/** * Constructor * * Add a default initializer to ensure the plugin is valid after instance * creation. * * @param null|ConfigInterface $configuration */ public function __construct(ConfigInterface $configuration = null) { parent::__construct($configuration); $this->addInitializer(function ($instance) { if ($instance instanceof ServiceLocatorAwareInterface) { $instance->setServiceLocator($this); } }); }
/** * Constructor * * Add a default initializer to ensure the plugin is valid after instance * creation. * * @param null|ConfigurationInterface $configuration * @return void */ public function __construct(ConfigurationInterface $configuration = null) { parent::__construct($configuration); $self = $this; $this->addInitializer(function ($instance) use($self) { if ($instance instanceof ServiceManagerAwareInterface) { $instance->setServiceManager($self); } }); }
public function __construct(ConfigInterface $config = null) { parent::__construct($config); /* * @note Unfortunately we need this to allow 'response' key to be overridden. * Hopefully in a later version we can refactor and break Backwards * Compatibility and thus disable this feature. */ $this->setAllowOverride(true); }
/** * Constructor. * * Sets the provided $parentLocator as the creation context for all * factories; for $config, {@see \Zend\ServiceManager\ServiceManager::configure()} * for details on its accepted structure. * * @param null|ConfigInterface|ContainerInterface $configInstanceOrParentLocator * @param array $config */ public function __construct($configInstanceOrParentLocator = null, array $config = []) { if (null !== $configInstanceOrParentLocator && !$configInstanceOrParentLocator instanceof ConfigInterface && !$configInstanceOrParentLocator instanceof ContainerInterface) { throw new Exception\InvalidArgumentException(sprintf('%s expects a ConfigInterface or ContainerInterface instance as the first argument; received %s', __CLASS__, is_object($configInstanceOrParentLocator) ? get_class($configInstanceOrParentLocator) : gettype($configInstanceOrParentLocator))); } if ($configInstanceOrParentLocator instanceof ConfigInterface) { trigger_error(sprintf('Usage of %s as a constructor argument for %s is now deprecated', ConfigInterface::class, get_class($this)), E_USER_DEPRECATED); $config = $configInstanceOrParentLocator->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; }
/** * Constructor * * Add a default initializer to ensure the plugin is valid after instance * creation. * * Additionally, the constructor provides forwards compatibility with v3 by * overloading the initial argument. v2 usage expects either null or a * ConfigInterface instance, and will ignore any other arguments. v3 expects * a ContainerInterface instance, and will use an array of configuration to * seed the current instance with services. In most cases, you can ignore the * constructor unless you are writing a specialized factory for your plugin * manager or overriding it. * * @param null|ConfigInterface|ContainerInterface $configOrContainerInstance * @param array $v3config If $configOrContainerInstance is a container, this * value will be passed to the parent constructor. * @throws Exception\InvalidArgumentException if $configOrContainerInstance * is neither null, nor a ConfigInterface, nor a ContainerInterface. */ public function __construct($configOrContainerInstance = null, array $v3config = []) { if (null !== $configOrContainerInstance && !$configOrContainerInstance instanceof ConfigInterface && !$configOrContainerInstance instanceof ContainerInterface) { throw new Exception\InvalidArgumentException(sprintf('%s expects a ConfigInterface instance or ContainerInterface instance; received %s', get_class($this), is_object($configOrContainerInstance) ? get_class($configOrContainerInstance) : gettype($configOrContainerInstance))); } if ($configOrContainerInstance instanceof ContainerInterface) { if (property_exists($this, 'serviceLocator')) { if (!empty($v3config)) { parent::__construct(new Config($v3config)); } $this->serviceLocator = $configOrContainerInstance; } if (property_exists($this, 'creationContext')) { if (!empty($v3config)) { parent::__construct($v3config); } $this->creationContext = $configOrContainerInstance; } } if ($configOrContainerInstance instanceof ConfigInterface) { parent::__construct($configOrContainerInstance); } $this->addInitializer(function ($instance) { if ($instance instanceof ServiceLocatorAwareInterface) { $instance->setServiceLocator($this); } }); }
/** * Constructor * * Add a default initializer to ensure the plugin is valid after instance * creation. * * @param null|ConfigurationInterface $configuration * @return void */ public function __construct(ConfigurationInterface $configuration = null) { parent::__construct($configuration); $this->addInitializer(array($this, 'validatePlugin'), true); }
/** * Create new container * * @param array $settings Associative array of settings. User settings are in a 'settings' sub-array */ public function __construct($settings = []) { $userSettings = []; if (isset($settings['settings'])) { $userSettings = $settings['settings']; unset($settings['settings']); } // Add settings factory that also collects the default settings $defaultSettings = $this->defaultSettings; $settings['factories']['settings'] = function ($c) use($userSettings, $defaultSettings) { return array_merge($defaultSettings, $userSettings); }; // Add default services if they aren't added already if (!isset($settings['environment'])) { $settings['factories']['environment'] = function ($c) { return new Environment($_SERVER); }; } if (!isset($settings['request'])) { $settings['factories']['request'] = function ($c) { return Request::createFromEnvironment($c['environment']); }; } if (!isset($settings['response'])) { $settings['factories']['response'] = function ($c) { $headers = new Headers(['Content-Type' => 'text/html']); $response = new Response(200, $headers); return $response->withProtocolVersion($c['settings']['httpVersion']); }; } if (!isset($settings['router'])) { $settings['factories']['router'] = function ($c) { return new Router(); }; } if (!isset($settings['callableResolver'])) { $settings['factories']['callableResolver'] = function ($c) { return new CallableResolver($c); }; } if (!isset($settings['foundHandler'])) { $settings['invokables']['foundHandler'] = RequestResponse::class; } if (!isset($settings['errorHandler'])) { $settings['factories']['errorHandler'] = function ($c) { return new Error($c->get('settings')['displayErrorDetails']); }; } if (!isset($settings['notFoundHandler'])) { $settings['invokables']['notFoundHandler'] = NotFound::class; } if (!isset($settings['notAllowedHandler'])) { $settings['invokables']['notAllowedHandler'] = NotAllowed::class; } parent::__construct($settings); }
/** * constructor * @param \Zend\ServiceManager\ConfigInterface $config */ public function __construct(\Zend\ServiceManager\ConfigInterface $config = null) { parent::__construct($config); }
/** * Constructor * * @param null|ConfigInterface $configuration */ public function __construct(ConfigInterface $configuration = null) { parent::__construct($configuration); $this->addInitializer('BlockManager\\BlockInitializer'); }
/** * Create new container * * @param array $userSettings Associative array of application settings */ public function __construct(array $userSettings = []) { parent::__construct(); $defaultSettings = $this->defaultSettings; /** * This service MUST return an array or an * instance of \ArrayAccess. * * @param Container $c * * @return array|\ArrayAccess */ $this->setFactory('settings', function ($c) use($userSettings, $defaultSettings) { return array_merge($defaultSettings, $userSettings); }); /** * This service MUST return a shared instance * of \Slim\Interfaces\Http\EnvironmentInterface. * * @param Container $c * * @return EnvironmentInterface */ $this->setFactory('environment', function ($c) { return new Environment($_SERVER); }); /** * \Psr\Http\Message\ServerRequestInterface. */ $this->setFactory('request', function ($c) { return Request::createFromEnvironment($c['environment']); }); /** * \Psr\Http\Message\ResponseInterface. */ $this->setFactory('response', function ($c) { $headers = new Headers(['Content-Type' => 'text/html']); $response = new Response(200, $headers); return $response->withProtocolVersion($c['settings']['httpVersion']); }); /** * This service MUST return a SHARED instance * of \Slim\Interfaces\RouterInterface. * * @param Container $c * * @return RouterInterface */ $this->setFactory('router', function ($c) { return new Router(); }); /** * This service MUST return a SHARED instance * of \Slim\Interfaces\InvocationStrategyInterface. * * @param Container $c * * @return InvocationStrategyInterface */ $this->setFactory('foundHandler', function ($c) { return new RequestResponse(); }); /** * This service MUST return a callable * that accepts three arguments: * * 1. Instance of \Psr\Http\Message\ServerRequestInterface * 2. Instance of \Psr\Http\Message\ResponseInterface * 3. Instance of \Exception * * The callable MUST return an instance of * \Psr\Http\Message\ResponseInterface. * * @param Container $c * * @return callable */ $this->setFactory('errorHandler', function ($c) { return new Error(); }); /** * This service MUST return a callable * that accepts two arguments: * * 1. Instance of \Psr\Http\Message\ServerRequestInterface * 2. Instance of \Psr\Http\Message\ResponseInterface * * The callable MUST return an instance of * \Psr\Http\Message\ResponseInterface. * * @param Container $c * * @return callable */ $this->setFactory('notFoundHandler', function ($c) { return new NotFound(); }); /** * This service MUST return a callable * that accepts three arguments: * * 1. Instance of \Psr\Http\Message\ServerRequestInterface * 2. Instance of \Psr\Http\Message\ResponseInterface * 3. Array of allowed HTTP methods * * The callable MUST return an instance of * \Psr\Http\Message\ResponseInterface. * * @param Container $c * * @return callable */ $this->setFactory('notAllowedHandler', function ($c) { return new NotAllowed(); }); /** * \Slim\Interfaces\CallableResolverInterface */ $this->setFactory('callableResolver', function ($c) { return new CallableResolver($c); }); }
public function __construct(ConfigInterface $config = null) { parent::__construct($config); }
public function __construct(ConfigInterface $config, MonologLoggerFactory $loggerFactory, MonologHandlerFactory $handlerFactory) { parent::__construct($config); $this->loggerFactory = $loggerFactory; $this->handlerFactory = $handlerFactory; }