|
11 | 11 |
|
12 | 12 | use Interop\Container\ContainerInterface; |
13 | 13 | use RecursiveIteratorIterator; |
| 14 | +use ReflectionProperty; |
14 | 15 | use Zend\EventManager\EventManager; |
15 | 16 | use Zend\EventManager\EventManagerAwareInterface; |
16 | 17 | use Zend\EventManager\EventManagerInterface; |
|
19 | 20 | use Zend\Navigation; |
20 | 21 | use Zend\Navigation\Page\AbstractPage; |
21 | 22 | use Zend\Permissions\Acl; |
| 23 | +use Zend\ServiceManager\AbstractPluginManager; |
22 | 24 | use Zend\View; |
23 | 25 | use Zend\View\Exception; |
24 | 26 |
|
@@ -753,6 +755,26 @@ public function hasRole() |
753 | 755 | */ |
754 | 756 | public function setServiceLocator(ContainerInterface $serviceLocator) |
755 | 757 | { |
| 758 | + // If we are provided a plugin manager, we should pull the parent |
| 759 | + // context from it. |
| 760 | + // @todo We should update tests and code to ensure that this situation |
| 761 | + // doesn't happen in the future. |
| 762 | + if ($serviceLocator instanceof AbstractPluginManager |
| 763 | + && ! method_exists($serviceLocator, 'configure') |
| 764 | + && $serviceLocator->getServiceLocator() |
| 765 | + ) { |
| 766 | + $serviceLocator = $serviceLocator->getServiceLocator(); |
| 767 | + } |
| 768 | + |
| 769 | + // v3 variant; likely won't be needed. |
| 770 | + if ($serviceLocator instanceof AbstractPluginManager |
| 771 | + && method_exists($serviceLocator, 'configure') |
| 772 | + ) { |
| 773 | + $r = new ReflectionProperty($serviceLocator, 'creationContext'); |
| 774 | + $r->setAccessible(true); |
| 775 | + $serviceLocator = $r->getValue($serviceLocator); |
| 776 | + } |
| 777 | + |
756 | 778 | $this->serviceLocator = $serviceLocator; |
757 | 779 | return $this; |
758 | 780 | } |
|
0 commit comments