definitions(), $di->instanceManager()); $this->di = $di; if (in_array($useContainer, [self::USE_SL_BEFORE_DI, self::USE_SL_AFTER_DI, self::USE_SL_NONE], true)) { $this->useContainer = $useContainer; } } /** * {@inheritDoc} */ public function __invoke(ContainerInterface $container, $name, array $options = null) { $this->container = $container; return $this->get($name, $options ?: []); } /** * zend-servicemanager v2 compatibility. * * @param ServiceLocatorInterface $container * @param null|string $name * @param null|string $requestedName * @return object */ public function createService(ServiceLocatorInterface $container, $name = null, $requestedName = null) { return $this($container, $requestedName ?: $name, $this->creationOptions); } /** * zend-servicemanager v2 support for options passed to factory. * * @param array $options * @return void */ public function setCreationOptions(array $options) { $this->creationOptions = $options; } /** * Override, as we want it to use the functionality defined in the proxy. * * @param string $name * @param array $params * @return object * @throws Exception\ServiceNotFoundException */ public function get($name, array $params = []) { // Allow this di service to get dependencies from the service locator BEFORE trying DI. if ($this->useContainer === self::USE_SL_BEFORE_DI && $this->container->has($name)) { return $this->container->get($name); } try { return parent::get($name, $params); } catch (DiClassNotFoundException $e) { // allow this di service to get dependencies from the service locator AFTER trying di if ($this->useContainer !== self::USE_SL_AFTER_DI || $this->container->has($name)) { throw new Exception\ServiceNotFoundException( sprintf('Service %s was not found in this DI instance', $name), null, $e ); } } return $this->container->get($name); } }