forked from dgreda/cache-factory
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from kamil-iskierka-westwing-pl/WMS-1703
[WMS-1703] Create PHPArray adapter to cache-factory library
- Loading branch information
Showing
7 changed files
with
137 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Cache\Factory\Adapter; | ||
|
||
class PHPArray extends AbstractAdapter | ||
{ | ||
const ADAPTER_NAMESPACE_TEMPLATE = '\\Cache\\Adapter\\%s\\ArrayCachePool'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getConfiguredDriver(array $config) | ||
{ | ||
return new \Cache\Adapter\PHPArray\ArrayCachePool(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getAdapterClassName($adapterClassName) | ||
{ | ||
$adapterClassName = str_replace(__NAMESPACE__, '', $adapterClassName); | ||
$adapterClassName = str_replace('\\', '', $adapterClassName); | ||
$adapterClassName = sprintf(self::ADAPTER_NAMESPACE_TEMPLATE, $adapterClassName); | ||
|
||
return $adapterClassName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Cache\Factory\Config\Adapter; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
|
||
class PHPArray extends AbstractConfig | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getAdapterConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$node = $treeBuilder->root($this->getAdapterName()); | ||
|
||
return $node; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
use Cache\Factory\Config\Adapter\AdapterInterface as Config; | ||
use Cache\Factory\Config\Loader; | ||
|
||
abstract class BaseAdapterTests extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var string Name of the adapter in the configuration | ||
*/ | ||
protected $adapterName; | ||
|
||
/** | ||
* @var string Type of the cache pool adapter | ||
*/ | ||
protected $adapterType; | ||
|
||
/** | ||
* @var string Path to the config file | ||
*/ | ||
protected $configFile; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* Sets the config file | ||
*/ | ||
protected function setUp() | ||
{ | ||
if (!isset($this->adapterName)) { | ||
throw new Exception( | ||
sprintf('Provide $adapterName in %s', (new ReflectionClass($this))->getFileName()) | ||
); | ||
} elseif (!isset($this->adapterType)) { | ||
throw new Exception( | ||
sprintf('Provide $adapterType in %s', (new ReflectionClass($this))->getFileName()) | ||
); | ||
} | ||
|
||
$this->configFile = __DIR__ . '/../cache.yml'; | ||
|
||
$configLoader = new Loader(); | ||
$config = $configLoader->load($this->configFile); | ||
|
||
$configLoader->setAdapterName($this->adapterType); | ||
|
||
$processedConfiguration = $configLoader->process($this->adapterName, $config); | ||
$this->config = $processedConfiguration[Config::INDEX_ADAPTER][$this->adapterName]; | ||
} | ||
|
||
/** | ||
* Tests creation of the filesystem cache item pool | ||
*/ | ||
abstract public function testMake(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use Cache\Factory\Adapter\PHPArray; | ||
|
||
class PHPArrayAdapterTests extends BaseAdapterTests | ||
{ | ||
/** | ||
* @var string Name of the adapter in the configuration | ||
*/ | ||
protected $adapterName = 'memory'; | ||
|
||
/** | ||
* @var string Type of the cache pool adapter | ||
*/ | ||
protected $adapterType = 'PHPArray'; | ||
|
||
/** | ||
* Tests creation of the filesystem cache item pool | ||
*/ | ||
public function testMake() | ||
{ | ||
$filesystemAdapterFactory = new PHPArray(); | ||
$filesystemCacheItemPool = $filesystemAdapterFactory->make($this->config); | ||
|
||
$this->assertInstanceOf('Psr\\Cache\\CacheItemPoolInterface', $filesystemCacheItemPool); | ||
$this->assertInstanceOf('\\Cache\\Adapter\\PHPArray\\ArrayCachePool', $filesystemCacheItemPool); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ Cache: | |
local: | ||
type: Filesystem | ||
path: '/tmp' | ||
memory: | ||
type: PHPArray |