Refactor Appbox

This commit is contained in:
Romain Neutron
2012-02-21 16:06:01 +01:00
parent 375fd3d493
commit e576989c7f
15 changed files with 90 additions and 114 deletions

View File

@@ -20,7 +20,7 @@ class registry implements registryInterface
/**
*
* @var cache_opcode_adapter
* @var \Alchemy\Phrasea\Cache\Cache
*/
protected $cache;
@@ -42,21 +42,22 @@ class registry implements registryInterface
*/
public static function get_instance()
{
$prefix = crc32(__DIR__);
if (!self::$_instance instanceof self)
self::$_instance = new self(new cache_opcode_adapter($prefix));
{
self::$_instance = new self();
}
return self::$_instance;
}
/**
*
* @param cache_opcode_interface $cache
* @param \Alchemy\Phrasea\Cache\Cache $cache
* @return registry
*/
protected function __construct(cache_opcode_interface $cache)
protected function __construct()
{
$this->cache = $cache;
$this->cache = new Alchemy\Phrasea\Cache\ArrayCache();
$handler = new \Alchemy\Phrasea\Core\Configuration\Handler(
new \Alchemy\Phrasea\Core\Configuration\Application(),
@@ -64,12 +65,12 @@ class registry implements registryInterface
);
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$this->cache->set('GV_RootPath', dirname(dirname(__DIR__)) . '/');
$this->cache->save('GV_RootPath', dirname(dirname(__DIR__)) . '/');
if ($configuration->isInstalled())
{
$this->cache->set('GV_ServerName', $configuration->getPhraseanet()->get('servername'));
$this->cache->set('GV_debug', $configuration->isDebug());
$this->cache->set('GV_maintenance', $configuration->isMaintained());
$this->cache->save('GV_ServerName', $configuration->getPhraseanet()->get('servername'));
$this->cache->save('GV_debug', $configuration->isDebug());
$this->cache->save('GV_maintenance', $configuration->isMaintained());
}
return $this;
@@ -81,7 +82,7 @@ class registry implements registryInterface
*/
protected function load()
{
if ($this->cache->get('registry_loaded') !== true)
if ($this->cache->fetch('registry_loaded') !== true)
{
$rs = array();
$loaded = false;
@@ -119,10 +120,10 @@ class registry implements registryInterface
break;
}
$this->cache->set($row['key'], $value);
$this->cache->save($row['key'], $value);
}
if ($loaded === true)
$this->cache->set('registry_loaded', true);
$this->cache->save('registry_loaded', true);
}
@@ -136,15 +137,15 @@ class registry implements registryInterface
*/
public function get($key, $defaultvalue = null)
{
if (!$this->cache->is_set($key))
if (!$this->cache->contains($key))
$this->load();
if (!$this->cache->is_set($key) && !is_null($defaultvalue))
if (!$this->cache->contains($key) && !is_null($defaultvalue))
return $defaultvalue;
else
return $this->cache->get($key);
return $this->cache->fetch($key);
}
/**
@@ -156,14 +157,6 @@ class registry implements registryInterface
public function set($key, $value, $type)
{
$this->load();
$delete_cache = false;
if ($key === 'GV_cache_server_type')
{
$current_cache = $this->get('GV_cache_server_type');
if ($current_cache !== $value)
$delete_cache = true;
}
switch ($type)
{
@@ -195,13 +188,7 @@ class registry implements registryInterface
$stmt->execute(array(':key' => $key, ':value' => $sql_value, ':type' => $type));
$stmt->closeCursor();
$this->cache->set($key, $value);
if ($delete_cache === true)
{
$cache = cache_adapter::get_instance($this);
$cache->flush();
}
$this->cache->save($key, $value);
return $this;
}
@@ -215,7 +202,7 @@ class registry implements registryInterface
{
$this->load();
return $this->cache->is_set($key);
return $this->cache->contains($key);
}
/**
@@ -233,7 +220,7 @@ class registry implements registryInterface
$stmt->execute(array(':key' => $key));
$stmt->closeCursor();
$this->cache->un_set($key);
$this->cache->delete($key);
return $this;
}