diff --git a/src/AbstractPluginManager.php b/src/AbstractPluginManager.php index 9db3420a..2b91bc59 100644 --- a/src/AbstractPluginManager.php +++ b/src/AbstractPluginManager.php @@ -63,9 +63,9 @@ public function __construct(ConfigInterface $configuration = null) { parent::__construct($configuration); $self = $this; - $this->addInitializer(function ($instance) use ($self) { + $this->addInitializer(function ($instance) { if ($instance instanceof ServiceLocatorAwareInterface) { - $instance->setServiceLocator($self); + $instance->setServiceLocator($this); } }); } diff --git a/src/ServiceManager.php b/src/ServiceManager.php index d1bf35f4..90a23ee9 100644 --- a/src/ServiceManager.php +++ b/src/ServiceManager.php @@ -610,12 +610,10 @@ public function create($name) */ private function createDelegatorCallback($delegatorFactory, $rName, $cName, $creationCallback) { - $serviceManager = $this; - - return function () use ($serviceManager, $delegatorFactory, $rName, $cName, $creationCallback) { + return function () use ($delegatorFactory, $rName, $cName, $creationCallback) { return $delegatorFactory instanceof DelegatorFactoryInterface - ? $delegatorFactory->createDelegatorWithName($serviceManager, $cName, $rName, $creationCallback) - : $delegatorFactory($serviceManager, $cName, $rName, $creationCallback); + ? $delegatorFactory->createDelegatorWithName($this, $cName, $rName, $creationCallback) + : $delegatorFactory($this, $cName, $rName, $creationCallback); }; } @@ -628,9 +626,8 @@ private function createDelegatorCallback($delegatorFactory, $rName, $cName, $cre * @return bool|mixed|null|object * @throws Exception\ServiceNotFoundException * - * @internal this method is internal because of PHP 5.3 compatibility - do not explicitly use it */ - public function doCreate($rName, $cName) + protected function doCreate($rName, $cName) { $instance = null; @@ -1188,10 +1185,9 @@ protected function checkNestedContextStop($force = false) */ protected function createDelegatorFromFactory($canonicalName, $requestedName) { - $serviceManager = $this; $delegatorsCount = count($this->delegators[$canonicalName]); - $creationCallback = function () use ($serviceManager, $requestedName, $canonicalName) { - return $serviceManager->doCreate($requestedName, $canonicalName); + $creationCallback = function () use ($requestedName, $canonicalName) { + return $this->doCreate($requestedName, $canonicalName); }; for ($i = 0; $i < $delegatorsCount; $i += 1) { @@ -1220,7 +1216,7 @@ protected function createDelegatorFromFactory($canonicalName, $requestedName) ); } - return $creationCallback($serviceManager, $canonicalName, $requestedName, $creationCallback); + return $creationCallback($this, $canonicalName, $requestedName, $creationCallback); } /**