Skip to content

Commit

Permalink
Adding a getter and setter for cache registry
Browse files Browse the repository at this point in the history
  • Loading branch information
burzum committed Apr 24, 2017
1 parent 5759d1e commit cefe650
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/Cache/Cache.php
Expand Up @@ -106,24 +106,47 @@ class Cache
*/
protected static $_registry;

/**
* Returns the Cache Registry instance used for creating and using cache adapters.
*
* @return \Cake\Core\ObjectRegistry
*/
public static function getRegistry()
{
if (!static::$_registry) {
static::$_registry = new CacheRegistry();
}

return static::$_registry;
}

/**
* Returns the Cache Registry instance used for creating and using cache adapters.
* Also allows for injecting of a new registry instance.
*
* @param \Cake\Core\ObjectRegistry|null $registry Injectable registry object.
* @return \Cake\Core\ObjectRegistry
*/
public static function setRegistry(ObjectRegistry $registry)
{
static::$_registry = $registry;
}

/**
* Returns the Cache Registry instance used for creating and using cache adapters.
* Also allows for injecting of a new registry instance.
*
* @deprecated Use getRegistry() and setRegistry() instead.
* @param \Cake\Core\ObjectRegistry|null $registry Injectable registry object.
* @return \Cake\Core\ObjectRegistry
*/
public static function registry(ObjectRegistry $registry = null)
{
if ($registry) {
static::$_registry = $registry;
static::setRegistry($registry);
}

if (!static::$_registry) {
static::$_registry = new CacheRegistry();
}

return static::$_registry;
return static::getRegistry();
}

/**
Expand All @@ -135,7 +158,7 @@ public static function registry(ObjectRegistry $registry = null)
*/
protected static function _buildEngine($name)
{
$registry = static::registry();
$registry = static::getRegistry();

if (empty(static::$_config[$name]['className'])) {
throw new InvalidArgumentException(
Expand Down Expand Up @@ -174,7 +197,7 @@ public static function engine($config)
return new NullEngine();
}

$registry = static::registry();
$registry = static::getRegistry();

if (isset($registry->{$config})) {
return $registry->{$config};
Expand Down

0 comments on commit cefe650

Please sign in to comment.