Example #1
0
File: Nav.php Project: hanif/stokq
 /**
  * @return ServiceManager
  */
 public function getServiceManager()
 {
     if (!$this->serviceManager) {
         $this->serviceManager = $this->serviceLocator->getServiceLocator();
     }
     return $this->serviceManager;
 }
Example #2
0
 /**
  * Given a Zend Framework Plugin Manager, initialize the instance.
  *
  * @param object                                     $instance Instance to
  * initialize
  * @param \Zend\ServiceManager\AbstractPluginManager $manager  Plugin manager
  *
  * @return object
  */
 public static function initZendPlugin($instance, \Zend\ServiceManager\AbstractPluginManager $manager)
 {
     $sm = $manager->getServiceLocator();
     if (null !== $sm) {
         static::initInstance($instance, $sm);
     }
     return $instance;
 }
 public function __construct(\Zend\ServiceManager\ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     $this->setInvokableClass(self::GENERATOR_HUMAN, self::GENERATOR_HUMAN);
     $this->setInvokableClass(self::GENERATOR_HYBRID, self::GENERATOR_HYBRID);
     $this->setInvokableClass(self::GENERATOR_COMPUTER, self::GENERATOR_COMPUTER);
     $this->addInitializer(function (PasswordGeneratorInterface $instance, PluginManager $pm) {
         /* @var $options \XelaxPasswordGeneratorModule\Options\GeneratorOptions */
         $generatorOptions = $pm->getServiceLocator()->get('XelaxPasswordGeneratorModule\\Options\\Generator');
         $options = array();
         if (isset($generatorOptions->getGeneratorOptions()[get_class($instance)])) {
             $options = $generatorOptions->getGeneratorOptions()[get_class($instance)];
         }
         if (!empty($options['options'])) {
             foreach ($options['options'] as $key => $value) {
                 $instance->setOptionValue($key, $value);
             }
         }
         if (!empty($options['parameters'])) {
             foreach ($options['parameters'] as $key => $value) {
                 $instance->setParameter($key, $value);
             }
         }
     });
 }
 public function __construct(ConfigInterface $config = null)
 {
     parent::__construct($config);
     foreach ($this->filters as $filterName => $filterClass) {
         $this->setInvokableClass($filterName, $filterClass);
     }
 }
Example #5
0
 /**
  * Override: do not use peering service managers
  *
  * @param  string $name
  * @param  array $options
  * @param  bool $usePeeringServiceManagers
  * @return mixed
  */
 public function get($name, $options = [], $usePeeringServiceManagers = false)
 {
     if (is_string($options)) {
         $options = ['class_name' => $options];
     }
     return parent::get($name, $options, $usePeeringServiceManagers);
 }
Example #6
0
 /**
  * {@inheritDoc}
  */
 public function __construct(ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     $this->addInitializer(function ($instance, $serviceLocator) {
         $instance->setServiceLocator($serviceLocator->getServiceLocator());
     }, false);
 }
 public function get($name, $options = array(), $usePeeringServiceManagers = true)
 {
     $plugin = parent::get($name, $options, $usePeeringServiceManagers);
     $plugin->setConfig($this->getConfig()->{$name});
     $plugin->setObjectManager($this->getObjectManager());
     return $plugin;
 }
Example #8
0
 /**
  * Creates an instance.
  *
  * Adds two default initializers:
  * - Inject the translator to mails implementing TranslatorAwareInterface
  * - Call init() method on Mails if such method exists.
  *
  * @param ConfigInterface $configuration
  */
 public function __construct(ServiceLocatorInterface $serviceLocator, ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     $this->serviceLocator = $serviceLocator;
     $self = $this;
     $this->addInitializer(function ($instance) use($self) {
         if ($instance instanceof TranslatorAwareInterface) {
             $translator = $self->getServiceLocator()->get('translator');
             $instance->setTranslator($translator);
             if (null === $instance->getTranslatorTextDomain()) {
                 $instance->setTranslatorTextDomain();
             }
             $instance->setTranslatorEnabled(true);
         }
     }, false);
     $this->addInitializer(function ($instance) {
         if (method_exists($instance, 'setServiceLocator')) {
             $instance->setServiceLocator($this);
         }
     }, false);
     $this->addInitializer(function ($instance) {
         if (method_exists($instance, 'init')) {
             $instance->init();
         }
     }, false);
 }
    /**
     * Retrieve a registered instance
     *
     * After the plugin is retrieved from the service locator, inject the
     * controller in the plugin every time it is requested. This is required
     * because a controller can use a plugin and another controller can be
     * dispatched afterwards. If this second controller uses the same plugin
     * as the first controller, the reference to the controller inside the
     * plugin is lost.
     *
     * @param  string $name
     * @param  mixed  $options
     * @param  bool   $usePeeringServiceManagers
     * @return mixed
     */
    public function get($name, $options = array(), $usePeeringServiceManagers = true)
    {
        $plugin = parent::get($name, $options, $usePeeringServiceManagers);
        $this->injectController($plugin);

        return $plugin;
    }
 /**
  * Constructor
  *
  * Merges provided configuration with default configuration.
  *
  * Adds initializers to inject the attached renderer and translator, if
  * any, to the currently requested helper.
  *
  * @param null|ConfigInterface|ContainerInterface $configOrContainerInstance
  * @param array $v3config If $configOrContainerInstance is a container, this
  *     value will be passed to the parent constructor.
  */
 public function __construct($configOrContainerInstance = null, array $v3config = [])
 {
     $this->initializers[] = [$this, 'injectRenderer'];
     $this->initializers[] = [$this, 'injectTranslator'];
     $this->initializers[] = [$this, 'injectEventManager'];
     parent::__construct($configOrContainerInstance, $v3config);
 }
Example #11
0
 /**
  * Creates an instance.
  *
  * {@inheritDoc}
  *
  * Adds an additional initializer to inject an event manager to assertions
  * implementing {@link EventManagerAwareInterface}.
  *
  */
 public function __construct(ServiceLocatorInterface $serviceLocator, ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     $this->serviceLocator = $serviceLocator;
     // Pushing to bottom of stack to ensure this is done last
     $this->addInitializer(array($this, 'injectEventManager'), false);
 }
 /**
  * @param null $configOrContainerInstance
  * @param array $v3config
  */
 public function __construct($configOrContainerInstance = null, array $v3config = [])
 {
     parent::__construct($configOrContainerInstance, $v3config);
     $this->addInitializer([$this, 'injectDbAdapter']);
     $this->addInitializer([$this, 'injectHydrator']);
     $this->addInitializer([$this, 'injectModel']);
 }
 /**
  * Constructor
  *
  * After invoking parent constructor, add an initializer to inject the
  * attached renderer and translator, if any, to the currently requested helper.
  *
  * @param null $configuration
  */
 public function __construct($configuration = null)
 {
     parent::__construct(null);
     Config::has('jquery', $configuration);
     $this->config = new Config($configuration['jquery'], $this->invokableClasses);
     $this->addInitializer(array($this, 'injectConfig'));
 }
 /**
  * @inheritdoc
  *
  * @param string $name
  * @param array $options
  * @param bool $usePeeringServiceManagers
  * @return JobInterface
  */
 public function get($name, $options = [], $usePeeringServiceManagers = true)
 {
     // parent::get calls validatePlugin() so we're sure $instance is a JobInterface
     $instance = parent::get($name, $options, $usePeeringServiceManagers);
     $instance->setMetadata('__name__', $name);
     return $instance;
 }
 /**
  * Constructor
  *
  * Make sure table gateways are properly initialized.
  *
  * @param ConfigInterface $configuration Configuration settings (optional)
  */
 public function __construct(ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     //todo: do we need an Initializer
     //$this->addInitializer(
     //    ['VuFind\ServiceManager\Initializer', 'initPlugin'], false
     //);
 }
Example #16
0
 /**
  * Override setInvokableClass().
  *
  * Performs normal operation, but also auto-aliases the class name to the
  * service name. This ensures that providing the FQCN does not trigger an
  * abstract factory later.
  *
  * @param  string       $name
  * @param  string       $invokableClass
  * @param  null|bool    $shared
  * @return RoutePluginManager
  */
 public function setInvokableClass($name, $invokableClass, $shared = null)
 {
     parent::setInvokableClass($name, $invokableClass, $shared);
     if ($name != $invokableClass) {
         $this->setAlias($invokableClass, $name);
     }
     return $this;
 }
 public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = true)
 {
     if (is_string($name)) {
         // internally called with an array [normalizedName, requestedName].
         $this->incrementCallCount('has', $name);
     }
     return parent::has($name, $checkAbstractFactories, $usePeeringServiceManagers);
 }
Example #18
0
 /**
  * Converts the given value so that it can be hydrated by the hydrator.
  *
  * @param mixed $value The original value.
  * @param array $data (optional) The original data for context.
  * @return mixed Returns the value that should be hydrated.
  */
 public function hydrate($value)
 {
     if ($value instanceof StateInterface) {
         return $value;
     }
     if (is_string($value)) {
         if ($this->checkPlugin() && $this->plugins->has($value)) {
             return $this->plugins->get($value);
         }
         throw new \RuntimeException(sprintf('No service registered in %s with name %s', is_object($this->plugins) ? get_class($this->plugins) : gettype($this->plugins), $value));
     }
     if (empty($value) && $this->checkPlugin() && $this->plugins->has($this->firstStateName)) {
         return $this->plugins->has($this->firstStateName);
     }
     // FIXME is correct? or exception
     return $value;
 }
Example #19
0
 /**
  * Constructor
  *
  * After invoking parent constructor, add an initializer to inject the
  * attached renderer and translator, if any, to the currently requested helper.
  *
  * @param  null|ConfigInterface $configuration
  */
 public function __construct(ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     $this->addInitializer(array($this, 'injectView'));
     if ($this->has('Navigation')) {
         $this->setInvokableClass('navigation', 'HumusMvc\\View\\Helper\\Navigation');
     }
 }
 /**
  * @param string $sName
  * @param mixed $oAssetFileFilter
  * @param boolean $bShared
  * @return \AssetsBundle\AssetFile\AssetFileFiltersManager
  */
 public function setService($sName, $oAssetFileFilter, $bShared = true)
 {
     if ($oAssetFileFilter) {
         $this->validatePlugin($oAssetFileFilter);
         $oAssetFileFilter->setOptions($this->getOptions());
     }
     parent::setService($sName, $oAssetFileFilter, $bShared);
     return $this;
 }
Example #21
0
 /**
  * Ctor
  * @param ConfigInterface $configuration
  */
 public function __construct(ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     // FIXME: set its from config (not in the ctor)
     foreach ($this->invokableClasses as $key => $value) {
         $this->setInvokableClass($key, $value);
     }
     $this->addInitializer([$this, 'injectAdapter']);
 }
 /**
  * Override build to inject options as PatternOptions instance.
  *
  * {@inheritDoc}
  */
 public function build($plugin, array $options = null)
 {
     if (empty($options)) {
         return parent::build($plugin);
     }
     $plugin = parent::build($plugin);
     $plugin->setOptions(new Pattern\PatternOptions($options));
     return $plugin;
 }
 /**
  * Attempt to create an instance via a factory
  *
  * @param  string $canonicalName
  * @param  string $requestedName
  * @return mixed
  * @throws \Zend\ServiceManager\Exception\ServiceNotCreatedException If factory is not callable
  */
 protected function createFromFactory($canonicalName, $requestedName)
 {
     $factory = $this->factories[$canonicalName];
     if (is_string($factory) && class_exists($factory, true)) {
         $factory = new $factory($this->creationOptions);
         $this->factories[$canonicalName] = $factory;
     }
     return parent::createFromFactory($canonicalName, $requestedName);
 }
Example #24
0
 /**
  * {@inheritDoc}
  */
 public function get($name, $options = [], $usePeeringServiceManagers = true)
 {
     try {
         $instance = parent::get($name, $options, $usePeeringServiceManagers);
     } catch (ServiceNotFoundException $e) {
         $instance = new Fallback();
         $instance->setServiceLocator($this->getServiceLocator());
     }
     return $instance;
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     if (!$configuration) {
         return;
     }
     Assertion::isInstanceOf($configuration, DataMapperManagerConfig::class);
     /* @var $configuration DataMapperManagerConfig */
     $this->entityDataMapperMap = $configuration->getEntityDataMapperMap();
 }
Example #26
0
 /**
  * {@inheritDoc}
  */
 public function get($name, $options = array(), $usePeeringServiceManagers = true)
 {
     $formElementManager = $this->getServiceLocator()->get('FormElementManager');
     if ($formElementManager->has($name)) {
         $form = $formElementManager->get($name);
         if ($form instanceof FormInterface) {
             return $form;
         }
     }
     return parent::get($name, $options, $usePeeringServiceManagers);
 }
 /**
  * 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 (empty($v3config) && $configOrContainerInstance instanceof ContainerInterface) {
         $config = $configOrContainerInstance->get('Config');
         if (isset($config['migration_manager'])) {
             $v3config = $config['migration_manager'];
         }
     }
     parent::__construct($configOrContainerInstance, $v3config);
     $this->addInitializer([$this, 'dbAdapterInitializer'], false);
     $this->addInitializer([$this, 'consoleAdapterInitializer'], false);
 }
 /**
  * Retrieve a service from the manager by name
  *
  * Allows passing an array of options to use when creating the instance.
  * createFromInvokable() will use these and pass them to the instance
  * constructor if not null and a non-empty array.
  *
  * @param string $name
  * @param array $options
  * @param bool $usePeeringServiceManagers
  * @return object
  * @throws InvalidPluginException
  */
 public function get($name, $options = [], $usePeeringServiceManagers = true)
 {
     // If service not registered check the the Service Locator.
     if (!$this->has($name)) {
         return $this->getServiceLocator()->get($name);
     }
     if (isset($options['initialize'])) {
         $this->initialize = $options['initialize'];
         unset($options['initialize']);
     }
     $instance = parent::get($name, $options, $usePeeringServiceManagers);
     $this->validatePlugin($instance);
     return $instance;
 }
 /**
  * Constructor
  *
  * After invoking parent constructor, add an initializer to inject the
  * attached renderer and translator, if any, to the currently requested helper.
  *
  * @param null|ConfigInterface $configuration
  */
 public function __construct(ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     $this->setFactory('identity', function ($helpers) {
         $services = $helpers->getServiceLocator();
         $helper = new Helper\Identity();
         if (!$services->has('Zend\\Authentication\\AuthenticationService')) {
             return $helper;
         }
         $helper->setAuthenticationService($services->get('Zend\\Authentication\\AuthenticationService'));
         return $helper;
     });
     $this->addInitializer(array($this, 'injectRenderer'))->addInitializer(array($this, 'injectTranslator'));
 }
Example #30
0
 public function __construct(ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     $this->addInitializer(function ($instance) {
         if ($instance instanceof ServiceManagerAwareInterface) {
             $instance->setServiceManager($this->getServiceLocator());
         }
         if (method_exists($instance, 'setRequest')) {
             $instance->setRequest($this->getServiceLocator()->get('Request'));
         }
         if ($instance instanceof InitializableInterface) {
             $instance->init();
         }
     });
 }