Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 43 changed files with 422 additions and 1,088 deletions.
14 changes: 0 additions & 14 deletions .travis/run-tests.sh

This file was deleted.

7 changes: 0 additions & 7 deletions .travis/skipped-components

This file was deleted.

61 changes: 0 additions & 61 deletions .travis/tested-components

This file was deleted.

4 changes: 2 additions & 2 deletions src/Pattern/PatternOptions.php
Expand Up @@ -24,7 +24,7 @@
use Zend\Cache\Exception,
Zend\Cache\StorageFactory,
Zend\Cache\Storage\StorageInterface as Storage,
Zend\Stdlib\Options;
Zend\Stdlib\AbstractOptions;

/**
* @category Zend
Expand All @@ -33,7 +33,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class PatternOptions extends Options
class PatternOptions extends AbstractOptions
{
/**
* Used by:
Expand Down
56 changes: 0 additions & 56 deletions src/PatternBroker.php

This file was deleted.

40 changes: 19 additions & 21 deletions src/PatternFactory.php
Expand Up @@ -20,9 +20,8 @@

namespace Zend\Cache;

use Traversable,
Zend\Loader\Broker,
Zend\Stdlib\ArrayUtils;
use Traversable;
use Zend\Stdlib\ArrayUtils;

/**
* @category Zend
Expand All @@ -33,11 +32,11 @@
class PatternFactory
{
/**
* The pattern broker
* The pattern manager
*
* @var null|Broker
* @var null|PatternPluginManager
*/
protected static $broker = null;
protected static $plugins = null;

/**
* Instantiate a cache pattern
Expand Down Expand Up @@ -68,44 +67,43 @@ public static function factory($patternName, $options = array())
return $patternName;
}

$pattern = static::getBroker()->load($patternName);
$pattern = static::getPluginManager()->get($patternName);
$pattern->setOptions($options);
return $pattern;
}

/**
* Get the pattern broker
* Get the pattern plugin manager
*
* @return Broker
* @return PatternPluginManager
*/
public static function getBroker()
public static function getPluginManager()
{
if (static::$broker === null) {
static::$broker = new PatternBroker();
static::$broker->setRegisterPluginsOnLoad(false);
if (static::$plugins === null) {
static::$plugins = new PatternPluginManager();
}

return static::$broker;
return static::$plugins;
}

/**
* Set the pattern broker
* Set the pattern plugin manager
*
* @param Broker $broker
* @param PatternPluginManager $plugins
* @return void
*/
public static function setBroker(Broker $broker)
public static function setPluginManager(PatternPluginManager $plugins)
{
static::$broker = $broker;
static::$plugins = $plugins;
}

/**
* Reset pattern broker to default
* Reset pattern plugin manager to default
*
* @return void
*/
public static function resetBroker()
public static function resetPluginManager()
{
static::$broker = null;
static::$plugins = null;
}
}
46 changes: 41 additions & 5 deletions src/PatternLoader.php → src/PatternPluginManager.php
Expand Up @@ -20,27 +20,63 @@

namespace Zend\Cache;

use Zend\Loader\PluginClassLoader;
use Zend\ServiceManager\AbstractPluginManager;

/**
* Plugin Class Loader implementation for cache patterns.
* Plugin manager implementation for cache pattern adapters
*
* Enforces that adatpers retrieved are instances of
* Pattern\PatternInterface. Additionally, it registers a number of default
* patterns available.
*
* @category Zend
* @package Zend_Cache
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class PatternLoader extends PluginClassLoader
class PatternPluginManager extends AbstractPluginManager
{
/**
* @var array Pre-aliased adapters
* Default set of adapters
*
* @var array
*/
protected $plugins = array(
protected $invokableClasses = array(
'callback' => 'Zend\Cache\Pattern\CallbackCache',
'capture' => 'Zend\Cache\Pattern\CaptureCache',
'class' => 'Zend\Cache\Pattern\ClassCache',
'object' => 'Zend\Cache\Pattern\ObjectCache',
'output' => 'Zend\Cache\Pattern\OutputCache',
'page' => 'Zend\Cache\Pattern\PageCache',
);

/**
* Don't share by default
*
* @var array
*/
protected $shareByDefault = false;

/**
* Validate the plugin
*
* Checks that the pattern adapter loaded is an instance of Pattern\PatternInterface.
*
* @param mixed $plugin
* @return void
* @throws Exception\RuntimeException if invalid
*/
public function validatePlugin($plugin)
{
if ($plugin instanceof Pattern\PatternInterface) {
// we're okay
return;
}

throw new Exception\RuntimeException(sprintf(
'Plugin of type %s is invalid; must implement %s\Pattern\PatternInterface',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__
));
}
}
16 changes: 8 additions & 8 deletions src/Storage/Adapter/AbstractAdapter.php
Expand Up @@ -115,7 +115,7 @@ public function __destruct()
}

if ($this->eventHandles) {
$events = $this->events();
$events = $this->getEventManager();
foreach ($this->eventHandles as $handle) {
$events->detach($handle);
}
Expand Down Expand Up @@ -145,7 +145,7 @@ public function setOptions($options)
$this->options = $options;

$event = new Event('option', $this, new ArrayObject($options->toArray()));
$this->events()->trigger($event);
$this->getEventManager()->trigger($event);
}
return $this;
}
Expand Down Expand Up @@ -205,7 +205,7 @@ public function getCaching()
*
* @return EventManagerInterface
*/
public function events()
public function getEventManager()
{
if ($this->events === null) {
$this->events = new EventManager(array(__CLASS__, get_called_class()));
Expand All @@ -222,7 +222,7 @@ public function events()
*/
protected function triggerPre($eventName, ArrayObject $args)
{
return $this->events()->trigger(new Event($eventName . '.pre', $this, $args));
return $this->getEventManager()->trigger(new Event($eventName . '.pre', $this, $args));
}

/**
Expand All @@ -236,7 +236,7 @@ protected function triggerPre($eventName, ArrayObject $args)
protected function triggerPost($eventName, ArrayObject $args, & $result)
{
$postEvent = new PostEvent($eventName . '.post', $this, $args, $result);
$eventRs = $this->events()->trigger($postEvent);
$eventRs = $this->getEventManager()->trigger($postEvent);
if ($eventRs->stopped()) {
return $eventRs->last();
}
Expand All @@ -260,7 +260,7 @@ protected function triggerPost($eventName, ArrayObject $args, & $result)
protected function triggerException($eventName, ArrayObject $args, & $result, \Exception $exception)
{
$exceptionEvent = new ExceptionEvent($eventName . '.exception', $this, $args, $result, $exception);
$eventRs = $this->events()->trigger($exceptionEvent);
$eventRs = $this->getEventManager()->trigger($exceptionEvent);

if ($exceptionEvent->getThrowException()) {
throw $exceptionEvent->getException();
Expand Down Expand Up @@ -303,7 +303,7 @@ public function addPlugin(Plugin\PluginInterface $plugin, $priority = 1)
));
}

$plugin->attach($this->events(), $priority);
$plugin->attach($this->getEventManager(), $priority);
$registry->attach($plugin);

return $this;
Expand All @@ -320,7 +320,7 @@ public function removePlugin(Plugin\PluginInterface $plugin)
{
$registry = $this->getPluginRegistry();
if ($registry->contains($plugin)) {
$plugin->detach($this->events());
$plugin->detach($this->getEventManager());
$registry->detach($plugin);
}
return $this;
Expand Down

0 comments on commit a876e82

Please sign in to comment.