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' into feature/db-story-35
Browse files Browse the repository at this point in the history
Conflicts:
	library/Zend/Db/Sql/Exception/RuntimeException.php
  • Loading branch information
Ralph Schindler committed May 8, 2012
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 143 deletions.
28 changes: 6 additions & 22 deletions src/Storage/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
Zend\Cache\Storage\ExceptionEvent,
Zend\Cache\Storage\PostEvent,
Zend\Cache\Storage\Plugin,
Zend\EventManager\EventCollection,
Zend\EventManager\EventManager,
Zend\EventManager\EventManagerAware;
Zend\EventManager\EventsCapableInterface;

/**
* @category Zend
Expand All @@ -42,12 +41,12 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class AbstractAdapter implements AdapterInterface, EventManagerAware
abstract class AbstractAdapter implements AdapterInterface, EventsCapableInterface
{
/**
* The used EventManager if any
*
* @var null|EventManager
* @var null|EventCollection
*/
protected $events = null;

Expand Down Expand Up @@ -221,30 +220,15 @@ public function getCaching()

/* Event/Plugin handling */

/**
* Set event manager instance
*
* @param EventCollection $events
* @return AbstractAdapter
*/
public function setEventManager(EventCollection $events)
{
$this->events = $events;
return $this;
}

/**
* Get the event manager
*
* @return EventManager
* @return EventCollection
*/
public function events()
{
if ($this->events === null) {
$this->setEventManager(new EventManager(array(
__CLASS__,
get_called_class(),
)));
$this->events = new EventManager(array(__CLASS__, get_called_class()));
}
return $this->events;
}
Expand Down Expand Up @@ -2431,7 +2415,7 @@ protected function internalGetCapabilities()
{
if ($this->capabilities === null) {
$this->capabilityMarker = new stdClass();
$this->capabilities = new Capabilities($this->capabilityMarker);
$this->capabilities = new Capabilities($this, $this->capabilityMarker);
}
return $this->capabilities;
}
Expand Down
1 change: 1 addition & 0 deletions src/Storage/Adapter/AbstractZendServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ protected function internalGetCapabilities()
if ($this->capabilities === null) {
$this->capabilityMarker = new stdClass();
$this->capabilities = new Capabilities(
$this,
$this->capabilityMarker,
array(
'supportedDatatypes' => array(
Expand Down
13 changes: 6 additions & 7 deletions src/Storage/Adapter/AdapterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use ArrayObject,
Zend\Cache\Exception,
Zend\Cache\Storage\Event,
Zend\EventManager\EventsCapableInterface,
Zend\Stdlib\Options;

/**
Expand Down Expand Up @@ -352,21 +353,19 @@ public function getWritable()
}

/**
* Triggers an option.change event
* if the this options instance has a connection too an adapter instance
* Triggers an option event if this options instance has a connection to
* an adapter implements EventsCapableInterface.
*
* @param string $optionName
* @param mixed $optionValue
* @return void
*/
protected function triggerOptionEvent($optionName, $optionValue)
{
if (!$this->adapter) {
return;
if ($this->adapter instanceof EventsCapableInterface) {
$event = new Event('option', $this->adapter, new ArrayObject(array($optionName => $optionValue)));
$this->adapter->events()->trigger($event);
}

$event = new Event('option', $this->adapter, new ArrayObject(array($optionName => $optionValue)));
$this->adapter->events()->trigger($event);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Storage/Adapter/Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ protected function internalGetCapabilities()
if ($this->capabilities === null) {
$marker = new stdClass();
$capabilities = new Capabilities(
$this,
$marker,
array(
'supportedDatatypes' => array(
Expand Down
1 change: 1 addition & 0 deletions src/Storage/Adapter/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@ protected function internalGetCapabilities()
}

$capabilities = new Capabilities(
$this,
$marker,
array(
'supportedDatatypes' => array(
Expand Down
1 change: 1 addition & 0 deletions src/Storage/Adapter/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ protected function internalGetCapabilities()
if ($this->capabilities === null) {
$this->capabilityMarker = new stdClass();
$this->capabilities = new Capabilities(
$this,
$this->capabilityMarker,
array(
'supportedDatatypes' => array(
Expand Down
1 change: 1 addition & 0 deletions src/Storage/Adapter/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ protected function internalGetCapabilities()
if ($this->capabilities === null) {
$this->capabilityMarker = new stdClass();
$this->capabilities = new Capabilities(
$this,
$this->capabilityMarker,
array(
'supportedDatatypes' => array(
Expand Down
1 change: 1 addition & 0 deletions src/Storage/Adapter/WinCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ protected function internalGetCapabilities()
if ($this->capabilities === null) {
$marker = new stdClass();
$capabilities = new Capabilities(
$this,
$marker,
array(
'supportedDatatypes' => array(
Expand Down
80 changes: 28 additions & 52 deletions src/Storage/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

namespace Zend\Cache\Storage;

use stdClass,
use ArrayObject,
stdClass,
Zend\Cache\Exception,
Zend\EventManager\EventManager;
Zend\EventManager\EventsCapableInterface;

/**
* @category Zend
Expand All @@ -35,11 +36,11 @@
class Capabilities
{
/**
* The event manager
* The storage adapter
*
* @var null|EventManager
* @var Adapter
*/
protected $eventManager;
protected $adapter;

/**
* A marker to set/change capabilities
Expand Down Expand Up @@ -116,8 +117,8 @@ class Capabilities
protected $_supportedMetadata;

/**
* Supports tagging?
*
* Supports tagging?
*
* @var bool
*/
protected $_tagging;
Expand All @@ -135,63 +136,34 @@ class Capabilities
/**
* Constructor
*
* @param stdClass $marker
* @param array $capabilities
* @param null|Zend\Cache\Storage\Capabilities $baseCapabilities
* @param Adapter $adapter
* @param stdClass $marker
* @param array $capabilities
* @param null|Capabilities $baseCapabilities
*/
public function __construct(
Adapter\AdapterInterface $adapter,
stdClass $marker,
array $capabilities = array(),
Capabilities $baseCapabilities = null
) {
$this->marker = $marker;
$this->adapter = $adapter;
$this->marker = $marker;
$this->baseCapabilities = $baseCapabilities;

foreach ($capabilities as $name => $value) {
$this->setCapability($marker, $name, $value);
}
}

/**
* Returns if the dependency of Zend\EventManager is available
*
* @return boolean
*/
public function hasEventManager()
{
return ($this->eventManager !== null || class_exists('Zend\EventManager\EventManager'));
}

/**
* Get the event manager
* Get the storage adapter
*
* @return EventManager
* @throws Exception\MissingDependencyException
* @return Adapter
*/
public function getEventManager()
public function getAdapter()
{
if ($this->eventManager instanceof EventManager) {
return $this->eventManager;
}

if (!class_exists('Zend\EventManager\EventManager')) {
throw new Exception\MissingDependencyException('Zend\EventManager\EventManager not found');
}

// create a new event manager object
$eventManager = new EventManager();

// trigger change event on change of a base capability
if ($this->baseCapabilities && $this->baseCapabilities->hasEventManager()) {
$onChange = function ($event) use ($eventManager) {
$eventManager->trigger('change', $event->getTarget(), $event->getParams());
};
$this->baseCapabilities->getEventManager()->attach('change', $onChange);
}

// register event manager
$this->eventManager = $eventManager;

return $this->eventManager;
return $this->adapter;
}

/**
Expand Down Expand Up @@ -550,7 +522,7 @@ public function setTagging(stdClass $marker, $tagging)
{
return $this->setCapability($marker, 'tagging', (bool) $tagging);
}

/**
* Get value for tagging
*
Expand Down Expand Up @@ -598,9 +570,13 @@ protected function setCapability(stdClass $marker, $name, $value)
$property = '_' . $name;
if ($this->$property !== $value) {
$this->$property = $value;
$this->getEventManager()->trigger('change', $this, array(
$name => $value
));

// trigger event
if ($this->adapter instanceof EventsCapableInterface) {
$this->adapter->events()->trigger('capability', $this->adapter, new ArrayObject(array(
$name => $value
)));
}
}

return $this;
Expand Down
10 changes: 5 additions & 5 deletions src/Storage/Plugin/ClearByFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace Zend\Cache\Storage\Plugin;

use Traversable,
Zend\EventManager\EventCollection,
Zend\EventManager\EventManagerInterface,
Zend\Cache\Exception,
Zend\Cache\Storage\Adapter\AdapterInterface as Adapter,
Zend\Cache\Storage\PostEvent;
Expand All @@ -46,11 +46,11 @@ class ClearByFactor extends AbstractPlugin
/**
* Attach
*
* @param EventCollection $eventCollection
* @param EventManagerInterface $eventCollection
* @return ClearByFactor
* @throws Exception\LogicException
*/
public function attach(EventCollection $eventCollection)
public function attach(EventManagerInterface $eventCollection)
{
$index = spl_object_hash($eventCollection);
if (isset($this->handles[$index])) {
Expand All @@ -71,11 +71,11 @@ public function attach(EventCollection $eventCollection)
/**
* Detach
*
* @param EventCollection $eventCollection
* @param EventManagerInterface $eventCollection
* @return ClearByFactor
* @throws Exception\LogicException
*/
public function detach(EventCollection $eventCollection)
public function detach(EventManagerInterface $eventCollection)
{
$index = spl_object_hash($eventCollection);
if (!isset($this->handles[$index])) {
Expand Down
10 changes: 5 additions & 5 deletions src/Storage/Plugin/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Traversable,
Zend\Cache\Exception,
Zend\Cache\Storage\ExceptionEvent,
Zend\EventManager\EventCollection;
Zend\EventManager\EventManagerInterface;

/**
* @category Zend
Expand All @@ -44,11 +44,11 @@ class ExceptionHandler extends AbstractPlugin
/**
* Attach
*
* @param EventCollection $eventCollection
* @param EventManagerInterface $eventCollection
* @return ExceptionHandler
* @throws Exception\LogicException
*/
public function attach(EventCollection $eventCollection)
public function attach(EventManagerInterface $eventCollection)
{
$index = spl_object_hash($eventCollection);
if (isset($this->handles[$index])) {
Expand Down Expand Up @@ -115,11 +115,11 @@ public function attach(EventCollection $eventCollection)
/**
* Detach
*
* @param EventCollection $eventCollection
* @param EventManagerInterface $eventCollection
* @return ExceptionHandler
* @throws Exception\LogicException
*/
public function detach(EventCollection $eventCollection)
public function detach(EventManagerInterface $eventCollection)
{
$index = spl_object_hash($eventCollection);
if (!isset($this->handles[$index])) {
Expand Down
Loading

0 comments on commit ef4289e

Please sign in to comment.