Refactor per chillu, reverse linting

This commit is contained in:
Aaron Carlino 2018-05-30 16:07:31 +12:00 committed by Damian Mooyman
parent 5583565480
commit 265ad70011
2 changed files with 70 additions and 93 deletions

123
cache/CacheProxy.php vendored
View File

@ -2,141 +2,118 @@
require_once 'Zend/Cache.php';
/**
* A decorator for a Zend_Cache_Backend cache service that mutates cache keys
* dynamically depending on versioned state
*/
class CacheProxy extends Zend_Cache_Core {
/**
* @var Zend_Cache_Backend|Zend_Cache_Backend_ExtendedInterface
*/
protected $container;
protected $cache;
/**
* CacheProxy constructor.
* @param Zend_Cache_Core $container
* @param Zend_Cache_Core $cache
*/
public function __construct(Zend_Cache_Core $container) {
$this->container = $container;
public function __construct(Zend_Cache_Core $cache) {
$this->cache = $cache;
parent::__construct();
}
/**
* @param array $directives
*/
public function setDirectives($directives) {
$this->container->setDirectives($directives);
$this->cache->setDirectives($directives);
}
public function setConfig(Zend_Config $config)
{
return $this->container->setConfig($config);
public function setConfig(Zend_Config $config) {
return $this->cache->setConfig($config);
}
public function setBackend(Zend_Cache_Backend $backendObject)
{
return $this->container->setBackend($backendObject);
public function setBackend(Zend_Cache_Backend $backendObject) {
return $this->cache->setBackend($backendObject);
}
public function getBackend()
{
return $this->container->getBackend();
public function getBackend() {
return $this->cache->getBackend();
}
/**
* @param string $name
* @param mixed $value
*/
public function setOption($name, $value)
{
$this->container->setOption($name, $value);
public function setOption($name, $value) {
$this->cache->setOption($name, $value);
}
public function getOption($name)
{
return $this->container->getOption($name);
public function getOption($name) {
return $this->cache->getOption($name);
}
public function setLifetime($newLifetime)
{
return $this->container->setLifetime($newLifetime);
public function setLifetime($newLifetime) {
return $this->cache->setLifetime($newLifetime);
}
public function getIds()
{
return $this->container->getIds();
public function getIds() {
return $this->cache->getIds();
}
public function getTags()
{
return $this->container->getTags();
public function getTags() {
return $this->cache->getTags();
}
public function getIdsMatchingTags($tags = array())
{
return $this->container->getIdsMatchingTags($tags);
public function getIdsMatchingTags($tags = array()) {
return $this->cache->getIdsMatchingTags($tags);
}
public function getIdsNotMatchingTags($tags = array())
{
return $this->container->getIdsNotMatchingTags($tags);
public function getIdsNotMatchingTags($tags = array()) {
return $this->cache->getIdsNotMatchingTags($tags);
}
public function getIdsMatchingAnyTags($tags = array())
{
return $this->container->getIdsMatchingAnyTags($tags);
public function getIdsMatchingAnyTags($tags = array()) {
return $this->cache->getIdsMatchingAnyTags($tags);
}
public function getFillingPercentage()
{
return $this->container->getFillingPercentage();
public function getFillingPercentage() {
return $this->cache->getFillingPercentage();
}
public function getMetadatas($id)
{
return $this->container->getMetadatas($this->createKey($id));
public function getMetadatas($id) {
return $this->cache->getMetadatas($this->getKeyID($id));
}
public function touch($id, $extraLifetime)
{
return $this->container->touch($this->createKey($id), $extraLifetime);
public function touch($id, $extraLifetime) {
return $this->cache->touch($this->getKeyID($id), $extraLifetime);
}
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)
{
return $this->container->load($this->createKey($id), $doNotTestCacheValidity, $doNotUnserialize);
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false) {
return $this->cache->load($this->getKeyID($id), $doNotTestCacheValidity, $doNotUnserialize);
}
public function test($id)
{
return $this->container->test($this->createKey($id));
public function test($id) {
return $this->cache->test($this->getKeyID($id));
}
public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8)
{
return $this->container->save(
public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8) {
return $this->cache->save(
$data,
$this->createKey($id),
$this->getKeyID($id),
$tags,
$specificLifetime,
$priority
);
}
public function remove($id)
{
return $this->container->remove($this->createKey($id));
public function remove($id) {
return $this->cache->remove($this->getKeyID($id));
}
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
return $this->container->clean($mode, $tags);
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) {
return $this->cache->clean($mode, $tags);
}
/**
* Creates a dynamic key based on versioned state
* @param $key
* @param string $key
* @return string
*/
protected function createKey($key)
{
protected function getKeyID($key) {
$state = Versioned::get_reading_mode();
if ($state) {
return $key . '_' . md5($state);

View File

@ -74,19 +74,19 @@ class CacheTest extends SapphireTest {
$cacheInstance->clean();
Versioned::set_reading_mode('Stage.Live');
$result = $cacheInstance->load('test');
$result = $cacheInstance->load('shared_key');
$this->assertFalse($result);
$cacheInstance->save('uncle', 'test');
$this->assertEquals('uncle', $cacheInstance->load('test'));
$cacheInstance->save('uncle', 'shared_key');
$this->assertEquals('uncle', $cacheInstance->load('shared_key'), 'Shared key is cached on LIVE');
Versioned::set_reading_mode('Stage.Stage');
$this->assertFalse($cacheInstance->load('test'));
$cacheInstance->save('cheese', 'test');
$cacheInstance->save('bar', 'foo');
$this->assertEquals('cheese', $cacheInstance->load('test'));
$this->assertEquals('bar', $cacheInstance->load('foo'));
$this->assertFalse($cacheInstance->load('shared_key'), 'Shared key does not exist on STAGE');
$cacheInstance->save('cheese', 'shared_key');
$cacheInstance->save('bar', 'stage_key');
$this->assertEquals('cheese', $cacheInstance->load('shared_key'), 'Shared key has its own value on STAGE');
$this->assertEquals('bar', $cacheInstance->load('stage_key'), 'New key is cached on STAGE');
Versioned::set_reading_mode('Stage.Live');
$this->assertFalse($cacheInstance->load('foo'));
$this->assertEquals('uncle', $cacheInstance->load('test'));
$this->assertFalse($cacheInstance->load('stage_key'), 'New key does not exist on LIVE');
$this->assertEquals('uncle', $cacheInstance->load('shared_key'), 'Shared key retains its own value on LIVE');
$cacheInstance->clean();
@ -97,19 +97,19 @@ class CacheTest extends SapphireTest {
$cacheInstance->clean();
Versioned::set_reading_mode('Stage.Live');
$result = $cacheInstance->load('test');
$result = $cacheInstance->load('shared_key');
$this->assertFalse($result);
$cacheInstance->save('uncle', 'test');
$this->assertEquals('uncle', $cacheInstance->load('test'));
$cacheInstance->save('uncle', 'shared_key');
$this->assertEquals('uncle', $cacheInstance->load('shared_key'), 'Shared key is cached on LIVE');
Versioned::set_reading_mode('Stage.Stage');
$this->assertEquals('uncle', $cacheInstance->load('test'));
$cacheInstance->save('cheese', 'test');
$cacheInstance->save('bar', 'foo');
$this->assertEquals('cheese', $cacheInstance->load('test'));
$this->assertEquals('bar', $cacheInstance->load('foo'));
$this->assertEquals('uncle', $cacheInstance->load('shared_key'), 'Shared key is same on STAGE');
$cacheInstance->save('cheese', 'shared_key');
$cacheInstance->save('bar', 'stage_key');
$this->assertEquals('cheese', $cacheInstance->load('shared_key'), 'Shared key is overwritten on STAGE');
$this->assertEquals('bar', $cacheInstance->load('stage_key'), 'New key is written on STAGE');
Versioned::set_reading_mode('Stage.Live');
$this->assertEquals('bar', $cacheInstance->load('foo'));
$this->assertEquals('cheese', $cacheInstance->load('test'));
$this->assertEquals('bar', $cacheInstance->load('stage_key'), 'New key has same value on LIVE');
$this->assertEquals('cheese', $cacheInstance->load('shared_key'), 'New value for existing key is same on LIVE');
$cacheInstance->clean();
}