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

Commit

Permalink
Merge branch 'cache_plugin_priority' of https://github.com/marc-mabe/zf2
Browse files Browse the repository at this point in the history
 into feature/cache-plugin-priority
  • Loading branch information
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 116 deletions.
5 changes: 3 additions & 2 deletions src/Storage/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,11 @@ public function hasPlugin(Plugin\PluginInterface $plugin)
* Register a plugin
*
* @param Plugin\PluginInterface $plugin
* @param int $priority
* @return AbstractAdapter Fluent interface
* @throws Exception\LogicException
*/
public function addPlugin(Plugin\PluginInterface $plugin)
public function addPlugin(Plugin\PluginInterface $plugin, $priority = 1)
{
$registry = $this->getPluginRegistry();
if ($registry->contains($plugin)) {
Expand All @@ -321,7 +322,7 @@ public function addPlugin(Plugin\PluginInterface $plugin)
));
}

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

return $this;
Expand Down
24 changes: 13 additions & 11 deletions src/Storage/Plugin/ClearByFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,45 +46,47 @@ class ClearByFactor extends AbstractPlugin
/**
* Attach
*
* @param EventManagerInterface $eventCollection
* @param EventManagerInterface $events
* @param int $priority
* @return ClearByFactor
* @throws Exception\LogicException
*/
public function attach(EventManagerInterface $eventCollection)
public function attach(EventManagerInterface $events, $priority = 1)
{
$index = spl_object_hash($eventCollection);
$index = spl_object_hash($events);
if (isset($this->handles[$index])) {
throw new Exception\LogicException('Plugin already attached');
}

$handles = array();
$this->handles[$index] = & $handles;

$handles[] = $eventCollection->attach('setItem.post', array($this, 'clearByFactor'));
$handles[] = $eventCollection->attach('setItems.post', array($this, 'clearByFactor'));
$handles[] = $eventCollection->attach('addItem.post', array($this, 'clearByFactor'));
$handles[] = $eventCollection->attach('addItems.post', array($this, 'clearByFactor'));
$callback = array($this, 'clearByFactor');
$handles[] = $events->attach('setItem.post', $callback, $priority);
$handles[] = $events->attach('setItems.post', $callback, $priority);
$handles[] = $events->attach('addItem.post', $callback, $priority);
$handles[] = $events->attach('addItems.post', $callback, $priority);

return $this;
}

/**
* Detach
*
* @param EventManagerInterface $eventCollection
* @param EventManagerInterface $events
* @return ClearByFactor
* @throws Exception\LogicException
*/
public function detach(EventManagerInterface $eventCollection)
public function detach(EventManagerInterface $events)
{
$index = spl_object_hash($eventCollection);
$index = spl_object_hash($events);
if (!isset($this->handles[$index])) {
throw new Exception\LogicException('Plugin not attached');
}

// detach all handles of this index
foreach ($this->handles[$index] as $handle) {
$eventCollection->detach($handle);
$events->detach($handle);
}

// remove all detached handles
Expand Down
73 changes: 37 additions & 36 deletions src/Storage/Plugin/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ class ExceptionHandler extends AbstractPlugin
/**
* Attach
*
* @param EventManagerInterface $eventCollection
* @param EventManagerInterface $events
* @param int $priority
* @return ExceptionHandler
* @throws Exception\LogicException
*/
public function attach(EventManagerInterface $eventCollection)
public function attach(EventManagerInterface $events, $priority = 1)
{
$index = spl_object_hash($eventCollection);
$index = spl_object_hash($events);
if (isset($this->handles[$index])) {
throw new Exception\LogicException('Plugin already attached');
}
Expand All @@ -60,75 +61,75 @@ public function attach(EventManagerInterface $eventCollection)
$this->handles[$index] = & $handles;

// read
$handles[] = $eventCollection->attach('getItem.exception', $callback);
$handles[] = $eventCollection->attach('getItems.exception', $callback);
$handles[] = $events->attach('getItem.exception', $callback, $priority);
$handles[] = $events->attach('getItems.exception', $callback, $priority);

$handles[] = $eventCollection->attach('hasItem.exception', $callback);
$handles[] = $eventCollection->attach('hasItems.exception', $callback);
$handles[] = $events->attach('hasItem.exception', $callback, $priority);
$handles[] = $events->attach('hasItems.exception', $callback, $priority);

$handles[] = $eventCollection->attach('getMetadata.exception', $callback);
$handles[] = $eventCollection->attach('getMetadatas.exception', $callback);
$handles[] = $events->attach('getMetadata.exception', $callback, $priority);
$handles[] = $events->attach('getMetadatas.exception', $callback, $priority);

// non-blocking
$handles[] = $eventCollection->attach('getDelayed.exception', $callback);
$handles[] = $eventCollection->attach('find.exception', $callback);
$handles[] = $events->attach('getDelayed.exception', $callback, $priority);
$handles[] = $events->attach('find.exception', $callback, $priority);

$handles[] = $eventCollection->attach('fetch.exception', $callback);
$handles[] = $eventCollection->attach('fetchAll.exception', $callback);
$handles[] = $events->attach('fetch.exception', $callback, $priority);
$handles[] = $events->attach('fetchAll.exception', $callback, $priority);

// write
$handles[] = $eventCollection->attach('setItem.exception', $callback);
$handles[] = $eventCollection->attach('setItems.exception', $callback);
$handles[] = $events->attach('setItem.exception', $callback, $priority);
$handles[] = $events->attach('setItems.exception', $callback, $priority);

$handles[] = $eventCollection->attach('addItem.exception', $callback);
$handles[] = $eventCollection->attach('addItems.exception', $callback);
$handles[] = $events->attach('addItem.exception', $callback, $priority);
$handles[] = $events->attach('addItems.exception', $callback, $priority);

$handles[] = $eventCollection->attach('replaceItem.exception', $callback);
$handles[] = $eventCollection->attach('replaceItems.exception', $callback);
$handles[] = $events->attach('replaceItem.exception', $callback, $priority);
$handles[] = $events->attach('replaceItems.exception', $callback, $priority);

$handles[] = $eventCollection->attach('touchItem.exception', $callback);
$handles[] = $eventCollection->attach('touchItems.exception', $callback);
$handles[] = $events->attach('touchItem.exception', $callback, $priority);
$handles[] = $events->attach('touchItems.exception', $callback, $priority);

$handles[] = $eventCollection->attach('removeItem.exception', $callback);
$handles[] = $eventCollection->attach('removeItems.exception', $callback);
$handles[] = $events->attach('removeItem.exception', $callback, $priority);
$handles[] = $events->attach('removeItems.exception', $callback, $priority);

$handles[] = $eventCollection->attach('checkAndSetItem.exception', $callback);
$handles[] = $events->attach('checkAndSetItem.exception', $callback, $priority);

// increment / decrement item(s)
$handles[] = $eventCollection->attach('incrementItem.exception', $callback);
$handles[] = $eventCollection->attach('incrementItems.exception', $callback);
$handles[] = $events->attach('incrementItem.exception', $callback, $priority);
$handles[] = $events->attach('incrementItems.exception', $callback, $priority);

$handles[] = $eventCollection->attach('decrementItem.exception', $callback);
$handles[] = $eventCollection->attach('decrementItems.exception', $callback);
$handles[] = $events->attach('decrementItem.exception', $callback, $priority);
$handles[] = $events->attach('decrementItems.exception', $callback, $priority);

// clear
$handles[] = $eventCollection->attach('clear.exception', $callback);
$handles[] = $eventCollection->attach('clearByNamespace.exception', $callback);
$handles[] = $events->attach('clear.exception', $callback, $priority);
$handles[] = $events->attach('clearByNamespace.exception', $callback, $priority);

// additional
$handles[] = $eventCollection->attach('optimize.exception', $callback);
$handles[] = $eventCollection->attach('getCapacity.exception', $callback);
$handles[] = $events->attach('optimize.exception', $callback, $priority);
$handles[] = $events->attach('getCapacity.exception', $callback, $priority);

return $this;
}

/**
* Detach
*
* @param EventManagerInterface $eventCollection
* @param EventManagerInterface $events
* @return ExceptionHandler
* @throws Exception\LogicException
*/
public function detach(EventManagerInterface $eventCollection)
public function detach(EventManagerInterface $events)
{
$index = spl_object_hash($eventCollection);
$index = spl_object_hash($events);
if (!isset($this->handles[$index])) {
throw new Exception\LogicException('Plugin not attached');
}

// detach all handles of this index
foreach ($this->handles[$index] as $handle) {
$eventCollection->detach($handle);
$events->detach($handle);
}

// remove all detached handles
Expand Down
71 changes: 36 additions & 35 deletions src/Storage/Plugin/IgnoreUserAbort.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ class IgnoreUserAbort extends AbstractPlugin
/**
* Attach
*
* @param EventManagerInterface $eventCollection
* @param EventManagerInterface $events
* @param int $priority
* @return Serializer
* @throws Exception\LogicException
*/
public function attach(EventManagerInterface $events)
public function attach(EventManagerInterface $events, $priority = 1)
{
$index = spl_object_hash($events);
if (isset($this->handles[$index])) {
Expand All @@ -68,50 +69,50 @@ public function attach(EventManagerInterface $events)
$cbOnBefore = array($this, 'onBefore');
$cbOnAfter = array($this, 'onAfter');

$handles[] = $events->attach('setItem.pre', $cbOnBefore);
$handles[] = $events->attach('setItem.post', $cbOnAfter);
$handles[] = $events->attach('setItem.exception', $cbOnAfter);
$handles[] = $events->attach('setItem.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('setItem.post', $cbOnAfter, $priority);
$handles[] = $events->attach('setItem.exception', $cbOnAfter, $priority);

$handles[] = $events->attach('setItems.pre', $cbOnBefore);
$handles[] = $events->attach('setItems.post', $cbOnAfter);
$handles[] = $events->attach('setItems.exception', $cbOnAfter);
$handles[] = $events->attach('setItems.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('setItems.post', $cbOnAfter, $priority);
$handles[] = $events->attach('setItems.exception', $cbOnAfter, $priority);

$handles[] = $events->attach('addItem.pre', $cbOnBefore);
$handles[] = $events->attach('addItem.post', $cbOnAfter);
$handles[] = $events->attach('addItem.exception', $cbOnAfter);
$handles[] = $events->attach('addItem.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('addItem.post', $cbOnAfter, $priority);
$handles[] = $events->attach('addItem.exception', $cbOnAfter, $priority);

$handles[] = $events->attach('addItems.pre', $cbOnBefore);
$handles[] = $events->attach('addItems.post', $cbOnAfter);
$handles[] = $events->attach('addItems.exception', $cbOnAfter);
$handles[] = $events->attach('addItems.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('addItems.post', $cbOnAfter, $priority);
$handles[] = $events->attach('addItems.exception', $cbOnAfter, $priority);

$handles[] = $events->attach('replaceItem.pre', $cbOnBefore);
$handles[] = $events->attach('replaceItem.post', $cbOnAfter);
$handles[] = $events->attach('replaceItem.exception', $cbOnAfter);
$handles[] = $events->attach('replaceItem.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('replaceItem.post', $cbOnAfter, $priority);
$handles[] = $events->attach('replaceItem.exception', $cbOnAfter, $priority);

$handles[] = $events->attach('replaceItems.pre', $cbOnBefore);
$handles[] = $events->attach('replaceItems.post', $cbOnAfter);
$handles[] = $events->attach('replaceItems.exception', $cbOnAfter);
$handles[] = $events->attach('replaceItems.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('replaceItems.post', $cbOnAfter, $priority);
$handles[] = $events->attach('replaceItems.exception', $cbOnAfter, $priority);

$handles[] = $events->attach('checkAndSetItem.pre', $cbOnBefore);
$handles[] = $events->attach('checkAndSetItem.post', $cbOnAfter);
$handles[] = $events->attach('checkAndSetItem.exception', $cbOnAfter);
$handles[] = $events->attach('checkAndSetItem.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('checkAndSetItem.post', $cbOnAfter, $priority);
$handles[] = $events->attach('checkAndSetItem.exception', $cbOnAfter, $priority);

// increment / decrement item(s)
$handles[] = $events->attach('incrementItem.pre', $cbOnBefore);
$handles[] = $events->attach('incrementItem.post', $cbOnAfter);
$handles[] = $events->attach('incrementItem.exception', $cbOnAfter);
$handles[] = $events->attach('incrementItem.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('incrementItem.post', $cbOnAfter, $priority);
$handles[] = $events->attach('incrementItem.exception', $cbOnAfter, $priority);

$handles[] = $events->attach('incrementItems.pre', $cbOnBefore);
$handles[] = $events->attach('incrementItems.post', $cbOnAfter);
$handles[] = $events->attach('incrementItems.exception', $cbOnAfter);
$handles[] = $events->attach('incrementItems.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('incrementItems.post', $cbOnAfter, $priority);
$handles[] = $events->attach('incrementItems.exception', $cbOnAfter, $priority);

$handles[] = $events->attach('decrementItem.pre', $cbOnBefore);
$handles[] = $events->attach('decrementItem.post', $cbOnAfter);
$handles[] = $events->attach('decrementItem.exception', $cbOnAfter);
$handles[] = $events->attach('decrementItem.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('decrementItem.post', $cbOnAfter, $priority);
$handles[] = $events->attach('decrementItem.exception', $cbOnAfter, $priority);

$handles[] = $events->attach('decrementItems.pre', $cbOnBefore);
$handles[] = $events->attach('decrementItems.post', $cbOnAfter);
$handles[] = $events->attach('decrementItems.exception', $cbOnAfter);
$handles[] = $events->attach('decrementItems.pre', $cbOnBefore, $priority);
$handles[] = $events->attach('decrementItems.post', $cbOnAfter, $priority);
$handles[] = $events->attach('decrementItems.exception', $cbOnAfter, $priority);

return $this;
}
Expand Down
24 changes: 13 additions & 11 deletions src/Storage/Plugin/OptimizeByFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,47 @@ class OptimizeByFactor extends AbstractPlugin
/**
* Attach
*
* @param EventManagerInterface $eventCollection
* @param EventManagerInterface $events
* @param int $priority
* @return OptimizeByFactor
* @throws Exception\LogicException
*/
public function attach(EventManagerInterface $eventCollection)
public function attach(EventManagerInterface $events, $priority = 1)
{
$index = spl_object_hash($eventCollection);
$index = spl_object_hash($events);
if (isset($this->handles[$index])) {
throw new Exception\LogicException('Plugin already attached');
}

$handles = array();
$this->handles[$index] = & $handles;

$handles[] = $eventCollection->attach('removeItem.post', array($this, 'optimizeByFactor'));
$handles[] = $eventCollection->attach('removeItems.post', array($this, 'optimizeByFactor'));
$handles[] = $eventCollection->attach('clear.post', array($this, 'optimizeByFactor'));
$handles[] = $eventCollection->attach('clearByNamespace.post', array($this, 'optimizeByFactor'));
$callback = array($this, 'optimizeByFactor');
$handles[] = $events->attach('removeItem.post', $callback, $priority);
$handles[] = $events->attach('removeItems.post', $callback, $priority);
$handles[] = $events->attach('clear.post', $callback, $priority);
$handles[] = $events->attach('clearByNamespace.post', $callback, $priority);

return $this;
}

/**
* Detach
*
* @param EventManagerInterface $eventCollection
* @param EventManagerInterface $events
* @return OptimizeByFactor
* @throws Exception\LogicException
*/
public function detach(EventManagerInterface $eventCollection)
public function detach(EventManagerInterface $events)
{
$index = spl_object_hash($eventCollection);
$index = spl_object_hash($events);
if (!isset($this->handles[$index])) {
throw new Exception\LogicException('Plugin not attached');
}

// detach all handles of this index
foreach ($this->handles[$index] as $handle) {
$eventCollection->detach($handle);
$events->detach($handle);
}

// remove all detached handles
Expand Down
Loading

0 comments on commit c2ac9c0

Please sign in to comment.