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

Commit

Permalink
Ensure that we get the parent locator
Browse files Browse the repository at this point in the history
Some tests are injecting the plugin manager as the service locator, when, in
fact, the two instances should be discretely different. This patch ensures the
tests continue to pass by updating `setServiceLocator()` to test if the instance
is a plugin manager. If it is, it pulls the parent context and uses that
instead.
  • Loading branch information
weierophinney committed Feb 22, 2016
1 parent 9058a15 commit 2888591
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Helper/Navigation/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Interop\Container\ContainerInterface;
use RecursiveIteratorIterator;
use ReflectionProperty;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
Expand All @@ -19,6 +20,7 @@
use Zend\Navigation;
use Zend\Navigation\Page\AbstractPage;
use Zend\Permissions\Acl;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\View;
use Zend\View\Exception;

Expand Down Expand Up @@ -753,6 +755,26 @@ public function hasRole()
*/
public function setServiceLocator(ContainerInterface $serviceLocator)
{
// If we are provided a plugin manager, we should pull the parent
// context from it.
// @todo We should update tests and code to ensure that this situation
// doesn't happen in the future.
if ($serviceLocator instanceof AbstractPluginManager
&& ! method_exists($serviceLocator, 'configure')
&& $serviceLocator->getServiceLocator()
) {
$serviceLocator = $serviceLocator->getServiceLocator();
}

// v3 variant; likely won't be needed.
if ($serviceLocator instanceof AbstractPluginManager
&& method_exists($serviceLocator, 'configure')
) {
$r = new ReflectionProperty($serviceLocator, 'creationContext');
$r->setAccessible(true);
$serviceLocator = $r->getValue($serviceLocator);
}

$this->serviceLocator = $serviceLocator;
return $this;
}
Expand Down

0 comments on commit 2888591

Please sign in to comment.