toArray(); } parent::__construct($config); if (! $configInstanceOrParentLocator instanceof ContainerInterface) { trigger_error(sprintf( '%s now expects a %s instance representing the parent container; please update your code', __METHOD__, ContainerInterface::class ), E_USER_DEPRECATED); } $this->creationContext = $configInstanceOrParentLocator instanceof ContainerInterface ? $configInstanceOrParentLocator : $this; } /** * Override configure() to validate service instances. * * If an instance passed in the `services` configuration is invalid for the * plugin manager, this method will raise an InvalidServiceException. * * {@inheritDoc} * @throws InvalidServiceException */ public function configure(array $config) { if (isset($config['services'])) { foreach ($config['services'] as $service) { $this->validate($service); } } parent::configure($config); return $this; } /** * {@inheritDoc} * * @param string $name Service name of plugin to retrieve. * @param null|array $options Options to use when creating the instance. * @return mixed * @throws Exception\ServiceNotFoundException if the manager does not have * a service definition for the instance, and the service is not * auto-invokable. * @throws InvalidServiceException if the plugin created is invalid for the * plugin context. */ public function get($name, array $options = null) { if (! $this->has($name)) { if (! $this->autoAddInvokableClass || ! class_exists($name)) { throw new Exception\ServiceNotFoundException(sprintf( 'A plugin by the name "%s" was not found in the plugin manager %s', $name, get_class($this) )); } $this->setFactory($name, Factory\InvokableFactory::class); } $instance = empty($options) ? parent::get($name) : $this->build($name, $options); $this->validate($instance); return $instance; } /** * {@inheritDoc} */ public function validate($instance) { if (method_exists($this, 'validatePlugin')) { trigger_error(sprintf( '%s::validatePlugin() has been deprecated as of 3.0; please define validate() instead', get_class($this) ), E_USER_DEPRECATED); $this->validatePlugin($instance); return; } if (empty($this->instanceOf) || $instance instanceof $this->instanceOf) { return; } throw new InvalidServiceException(sprintf( 'Plugin manager "%s" expected an instance of type "%s", but "%s" was received', __CLASS__, $this->instanceOf, is_object($instance) ? get_class($instance) : gettype($instance) )); } /** * Implemented for backwards compatibility only. * * Returns the creation context. * * @deprecated since 3.0.0. The creation context should be passed during * instantiation instead. * @param ContainerInterface $container * @return void */ public function setServiceLocator(ContainerInterface $container) { trigger_error(sprintf( 'Usage of %s is deprecated since v3.0.0; please pass the container to the constructor instead', __METHOD__ ), E_USER_DEPRECATED); $this->creationContext = $container; } }