Skip to content

Commit

Permalink
Merge branch 'hotfix/104'
Browse files Browse the repository at this point in the history
Close #104
  • Loading branch information
weierophinney committed May 26, 2016
2 parents b29aa8f + 3b068e0 commit 64d46ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ All notable changes to this project will be documented in this file, in reverse
- [#97](https://github.com/phly/PhlyRestfully/pull/97) fixes the identifier
comparison in `ResourceController::getIdentifier()` to use a strict comparison
to boolean false, and thus allow identifiers of `0`.
- [#104](https://github.com/phly/PhlyRestfully/pull/104) corrects the logic in
`ResourceParametersListener::detachShared` to pass the identifier.
16 changes: 11 additions & 5 deletions src/Listener/ResourceParametersListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\EventManager\SharedEventManagerInterface;
use Zend\EventManager\SharedListenerAggregateInterface;
use Zend\Mvc\MvcEvent;

class ResourceParametersListener implements
ListenerAggregateInterface,
SharedListenerAggregateInterface
class ResourceParametersListener implements ListenerAggregateInterface
{
/**
* @var \Zend\Stdlib\CallbackHandler[]
Expand Down Expand Up @@ -62,8 +59,17 @@ public function attachShared(SharedEventManagerInterface $events)
*/
public function detachShared(SharedEventManagerInterface $events)
{
// Vary detachment based on zend-eventmanager version.
$detach = method_exists($events, 'attachAggregate')
? function ($listener) use ($events) {
return $events->detach(ResourceController::class, $listener);
}
: function ($listener) use ($events) {
return $events->detach($listener, ResourceController::class);
};

foreach ($this->sharedListeners as $index => $listener) {
if ($events->detach($listener)) {
if ($detach($listener)) {
unset($this->sharedListeners[$index]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function onBootstrap($e)
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach($services->get(ApiProblemListener::class));
}, 300);
$sharedEvents->attachAggregate($services->get('PhlyRestfully\ResourceParametersListener'));
$services->get('PhlyRestfully\ResourceParametersListener')->attachShared($sharedEvents);
}

/**
Expand Down

0 comments on commit 64d46ce

Please sign in to comment.