Пример #1
0
 /**
  * Create front controller service
  *
  * As a side-effect if a Layout service is present in the Service
  * Locator it will be retrieved.
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return Zend_Controller_Front
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->has('Config') ? $serviceLocator->get('Config') : array();
     $options = isset($config['front_controller']) ? $config['front_controller'] : array();
     $class = isset($options['class']) ? $options['class'] : 'Zend_Controller_Front';
     /** @var $frontController Zend_Controller_Front */
     $frontController = call_user_func(array($class, 'getInstance'));
     $frontController->setDispatcher($serviceLocator->get('Dispatcher'));
     $frontController->setRouter($serviceLocator->get('Router'));
     $frontController->setRequest($serviceLocator->get('Request'));
     $frontController->setResponse($serviceLocator->get('Response'));
     // Setup front controller options
     $this->init($frontController, $options);
     // Retrieve controller paths from loaded modules and add them to dispatcher:
     // - if a module provides getControllerDirectory() method, its return value
     //   is used as a controller path for this module
     // - otherwise a default controller path will be used (module/controllers)
     $moduleManager = $serviceLocator->get('ModuleManager');
     foreach ($moduleManager->getLoadedModules() as $module => $moduleObj) {
         if (method_exists($moduleObj, 'getControllerDirectory')) {
             $dir = $moduleObj->getControllerDirectory();
         } else {
             $ref = new \ReflectionClass($moduleObj);
             $dir = dirname($ref->getFileName()) . '/' . $frontController->getModuleControllerDirectoryName();
         }
         $frontController->addControllerDirectory($dir, $module);
     }
     // Zend_Layout requires eager initialization - otherwise a controller
     // plugin that drives it will not be registered
     if ($serviceLocator->has('Layout')) {
         $serviceLocator->get('Layout');
     }
     return $frontController;
 }
 /**
  * @see \Zend\ServiceManager\FactoryInterface::createService()
  * @param \Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator
  * @return \BoilerAppMessenger\Media\Mail\MailMessageRenderer
  */
 public function createService(\Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator)
 {
     $oMailMessageRenderer = new \BoilerAppMessenger\Media\Mail\MailMessageRenderer();
     //Template map
     $aConfiguration = $oServiceLocator->get('Config');
     if (isset($aConfiguration['medias'][\BoilerAppMessenger\Media\Mail\MailMessageRenderer::MEDIA])) {
         $aConfiguration = $aConfiguration['medias'][\BoilerAppMessenger\Media\Mail\MailMessageRenderer::MEDIA];
         if (isset($aConfiguration['template_map'])) {
             $oMailMessageRenderer->setTemplateMap($aConfiguration['template_map']);
         }
         //Templating service
         if (class_exists('TreeLayoutStack\\TemplatingService')) {
             $oMailMessageRenderer->setTemplatingService(\TreeLayoutStack\TemplatingService::factory(isset($aConfiguration['tree_layout_stack']) ? $aConfiguration['tree_layout_stack'] : array()));
         }
     }
     //AssetsBundle service
     if ($oServiceLocator->has('AssetsBundleService')) {
         $oMailMessageRenderer->setAssetsBundleService($oServiceLocator->get('AssetsBundleService'));
     }
     //StyleInliner service
     if ($oServiceLocator->has('StyleInlinerService')) {
         $oMailMessageRenderer->setStyleInlinerService($oServiceLocator->get('StyleInlinerService'));
     }
     //Translator
     if ($oServiceLocator->has('translator')) {
         $oTranslateHelper = new \Zend\I18n\View\Helper\Translate();
         $oMailMessageRenderer->getHelperPluginManager()->setService('translate', $oTranslateHelper->setTranslator($oServiceLocator->get('translator'))->setTranslatorEnabled(true));
     }
     //Router
     if ($oServiceLocator->has('router')) {
         $oUrlHelper = new \Zend\View\Helper\Url();
         $oMailMessageRenderer->getHelperPluginManager()->setService('url', $oUrlHelper->setRouter($oServiceLocator->get('router')));
     }
     return $oMailMessageRenderer;
 }
Пример #3
0
 /**
  * Creates and returns the module manager
  *
  * Instantiates the default module listeners, providing them configuration
  * from the "module_listener_options" key of the ApplicationConfig
  * service. Also sets the default config glob path.
  *
  * Module manager is instantiated and provided with an EventManager, to which
  * the default listener aggregate is attached. The ModuleEvent is also created
  * and attached to the module manager.
  *
  * @param  ServiceLocatorInterface $serviceLocator
  * @return ModuleManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     if (!$serviceLocator->has('ServiceListener')) {
         $serviceLocator->setFactory('ServiceListener', 'HumusMvc\\Service\\ServiceListenerFactory');
     }
     if (!$serviceLocator->has('Zf1MvcListener')) {
         $serviceLocator->setFactory('Zf1MvcListener', 'HumusMvc\\Service\\Zf1MvcListenerFactory');
     }
     $configuration = $serviceLocator->get('ApplicationConfig');
     $listenerOptions = new ListenerOptions($configuration['module_listener_options']);
     $defaultListeners = new DefaultListenerAggregate($listenerOptions);
     $serviceListener = $serviceLocator->get('ServiceListener');
     $serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig');
     $serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\\ModuleManager\\Feature\\ViewHelperProviderInterface', 'getViewHelperConfig');
     $serviceListener->addServiceManager('ActionHelperManager', 'action_helpers', 'HumusMvc\\ModuleManager\\Feature\\ActionHelperProviderInterface', 'getActionHelperConfig');
     $events = $serviceLocator->get('EventManager');
     $events->attach($defaultListeners);
     $events->attach($serviceListener);
     $sharedEvents = $events->getSharedManager();
     $sharedEvents->attach('HumusMvc\\Application', 'bootstrap', new LocaleListener());
     $moduleEvent = new ModuleEvent();
     $moduleEvent->setParam('ServiceManager', $serviceLocator);
     $moduleManager = new ModuleManager($configuration['modules'], $events);
     $moduleManager->setEvent($moduleEvent);
     return $moduleManager;
 }
 /**
  * Get shared instance
  *
  * @param $classOrAlias
  * @return mixed
  */
 public function getSharedInstance($classOrAlias)
 {
     if ($this->serviceLocator->has($classOrAlias)) {
         return $this->serviceLocator->get($classOrAlias);
     }
     return $this->diInstanceManager->getSharedInstance($classOrAlias);
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->has('ApplicationConfig') ? $serviceLocator->get('ApplicationConfig') : array();
     $config = isset($config['maintenance_mode']) ? $config['maintenance_mode'] : array();
     if (!isset($config['template'])) {
         $view_manager = $serviceLocator->has('Config') ? $serviceLocator->get('Config') : array();
         $view_manager = isset($view_manager['view_manager']) ? $view_manager['view_manager'] : array();
         // Check for a maintenance template
         if (isset($view_manager['maintenance_template'])) {
             $maintenance_template = $view_manager['maintenance_template'];
             if (isset($view_manager['template_map'][$maintenance_template])) {
                 $config['template'] = $view_manager['template_map'][$maintenance_template];
             } elseif ($serviceLocator->has('ViewManager')) {
                 $view_manager = $serviceLocator->get('ViewManager');
                 if ($view_manager instanceof HttpViewManager) {
                     $resolver = $view_manager->getResolver();
                     $template = $resolver->resolve($maintenance_template);
                     if ($template) {
                         $config['template'] = $template;
                     }
                 }
             }
         }
     }
     return new Config($config);
 }
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $config = $config['doctrine']['migrations'];
     if (isset($config['connection']) && $serviceLocator->has($config['connection'])) {
         $connection = $serviceLocator->get($config['connection']);
     } else {
         $connection = $serviceLocator->get('doctrine.connection.orm_default');
     }
     unset($config['connection']);
     if (isset($config['output_writer']) && $serviceLocator->has($config['output_writer'])) {
         $outputWriter = $serviceLocator->get($config['output_writer']);
     } else {
         $outputWriter = null;
     }
     unset($config['output_writer']);
     $configuration = new Configuration($connection, $outputWriter);
     foreach ($config as $key => $value) {
         $setter = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
         if (!method_exists($configuration, $setter)) {
             continue;
         }
         $configuration->{$setter}($value);
     }
     return $configuration;
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $adapter = null;
     $locale = null;
     $config = $serviceLocator->has('Config') ? $serviceLocator->get('Config') : [];
     $config = isset($config['locale_manager']) ? $config['locale_manager'] : [];
     if ($serviceLocator->has('LocaleManager\\Adapter\\AdapterInterface')) {
         $adapter = $serviceLocator->get('LocaleManager\\Adapter\\AdapterInterface');
         if (!$adapter instanceof AdapterInterface) {
             throw new ServiceNotCreatedException(sprintf('LocaleManager requires that the %s service implement %s; received "%s"', 'LocaleManager\\Adapter\\AdapterInterface', 'LocaleManager\\Adapter\\AdapterInterface', is_object($adapter) ? get_class($adapter) : gettype($adapter)));
         }
     }
     $manager = new LocaleManager($adapter);
     // Set the current locale
     if (isset($config['locale'])) {
         $locale = $config['locale'];
     } elseif ($serviceLocator->has('Translator')) {
         $translator = $serviceLocator->get('Translator');
         if ($translator instanceof \Zend\Mvc\I18n\Translator) {
             $translator = $translator->getTranslator();
         }
         if (method_exists($translator, 'getLocale')) {
             $locale = $translator->getLocale();
         }
     }
     if ($locale === null) {
         $locale = \Locale::getDefault();
     }
     $manager->setLocale($locale);
     // Return the manager
     return $manager;
 }
Пример #8
0
 /**
  * {@inheritDoc}
  *
  * @throws RuntimeException
  * @return AnnotationBuilder
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $options FormAnnotationBuilder */
     $options = $serviceLocator->get(FormAnnotationBuilder::class);
     $cache = $serviceLocator->has($options->getCache()) ? $serviceLocator->get($options->getCache()) : null;
     $builder = new AnnotationBuilder($cache);
     if ($serviceLocator->has('FormElementManager')) {
         $serviceLocator->get('FormElementManager')->injectFactory($builder);
     }
     foreach ($options->getAnnotations() as $annotation) {
         $builder->getAnnotationParser()->registerAnnotation($annotation);
     }
     $events = $builder->getEventManager();
     foreach ($options->getListeners() as $listener) {
         $listener = $serviceLocator->has($listener) ? $serviceLocator->get($listener) : new $listener();
         if (!$listener instanceof ListenerAggregateInterface) {
             throw new RuntimeException(sprintf('Invalid event listener (%s) provided', get_class($listener)));
         }
         $events->attach($listener);
     }
     if (null !== $options->getPreserveDefinedOrder()) {
         $builder->setPreserveDefinedOrder($options->getPreserveDefinedOrder());
     }
     return $builder;
 }
 /**
  * @param $socialNetwork
  * @return SocialConnectorInterface
  * @throws InvalidSocialNetworkException
  */
 protected function getSocialConnector($socialNetwork)
 {
     if (!$this->socialPlugins->has($socialNetwork)) {
         throw new InvalidSocialNetworkException($socialNetwork);
     }
     return $this->socialPlugins->get($socialNetwork);
 }
Пример #10
0
 /**
  * @param ServiceLocatorInterface $serviceLocator
  * @return MvcTranslator
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     // Assume that if a user has registered a service for the
     // TranslatorInterface, it must be valid
     if ($serviceLocator->has('Zend\\I18n\\Translator\\TranslatorInterface')) {
         return new MvcTranslator($serviceLocator->get('Zend\\I18n\\Translator\\TranslatorInterface'));
     }
     // If ext/intl is not loaded, return a dummy translator
     if (!extension_loaded('intl')) {
         return new MvcTranslator(new DummyTranslator());
     }
     // Load a translator from configuration, if possible
     if ($serviceLocator->has('Config')) {
         $config = $serviceLocator->get('Config');
         // 'translator' => false
         if (array_key_exists('translator', $config) && $config['translator'] === false) {
             return new MvcTranslator(new DummyTranslator());
         }
         // 'translator' => array( ... translator options ... )
         if (array_key_exists('translator', $config) && (is_array($config['translator']) && !empty($config['translator']) || $config['translator'] instanceof Traversable)) {
             $i18nTranslator = Translator::factory($config['translator']);
             $serviceLocator->setService('Zend\\I18n\\Translator\\TranslatorInterface', $i18nTranslator);
             return new MvcTranslator($i18nTranslator);
         }
     }
     // For BC purposes (pre-2.3.0), use the I18n Translator
     return new MvcTranslator(new Translator());
 }
Пример #11
0
    /**
     * {@inheritDoc}
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = array();

        if ($serviceLocator->has('Config')) {
            $appConfig = $serviceLocator->get('Config');
            if (isset($appConfig['zf-content-negotiation'])
                && is_array($appConfig['zf-content-negotiation'])
            ) {
                $config = $appConfig['zf-content-negotiation'];
            }
        }

        $selector = null;
        if ($serviceLocator->has('ControllerPluginManager')) {
            $plugins = $serviceLocator->get('ControllerPluginManager');
            if ($plugins->has('AcceptableViewModelSelector')) {
                $selector = $plugins->get('AcceptableViewModelSelector');
            }
        }

        if (null === $selector) {
            $selector = new AcceptableViewModelSelector();
        }

        return new AcceptListener($selector, $config);
    }
Пример #12
0
 public function build()
 {
     if ($this->isBuild) {
         return;
     }
     $settings = $this->getObject();
     $reflection = new \ReflectionClass($settings);
     $properties = $reflection->getProperties();
     $skipProperties = array('_settings', 'isWritable');
     if ($settings instanceof ModuleSettingsContainerInterface) {
         $skipProperties[] = '_module';
     }
     $children = array();
     foreach ($properties as $property) {
         if (in_array($property->getName(), $skipProperties) || $this->has($property->getName())) {
             continue;
         }
         $property->setAccessible(true);
         $value = $property->getValue($settings);
         if ($value instanceof SettingsContainerInterface) {
             $children[$property->getName()] = $value;
             continue;
         }
         $inputName = $property->getName();
         $inputLabel = isset($this->labelMap[$inputName]) ? $this->labelMap[$inputName] : $inputName;
         if (is_array($inputLabel)) {
             $priority = isset($inputLabel[1]) ? $inputLabel[1] : 0;
             $inputLabel = $inputLabel[0];
         } else {
             $priority = 0;
         }
         $input = array('name' => $inputName, 'options' => array('label' => $inputLabel));
         if (is_bool($value)) {
             $input['type'] = 'Checkbox';
             $input['attributes']['checked'] = $value;
         } else {
             $input['attributes']['value'] = $value;
         }
         $this->add($input, ['priority' => $priority]);
     }
     foreach ($children as $name => $child) {
         $objectClass = ltrim(get_class($settings), '\\');
         $moduleName = substr($objectClass, 0, strpos($objectClass, '\\'));
         $fieldsetName = $moduleName . '/' . ucfirst($name) . 'SettingsFieldset';
         if ($this->formManager->has($fieldsetName)) {
             $fieldset = $this->formManager->get($fieldsetName);
             if (!$fieldset->getHydrator() instanceof SettingsEntityHydrator) {
                 $fieldset->setHydrator($this->getHydrator());
             }
         } else {
             $fieldset = new self();
             $label = preg_replace('~([A-Z])~', ' $1', $name);
             $fieldset->setLabel(ucfirst($label));
         }
         $fieldset->setName($name)->setObject($child);
         $this->add($fieldset);
     }
     $this->isBuild = true;
 }
Пример #13
0
 /**
  * Retrieves the handler for a specified command
  *
  * @param string $commandName
  *
  * @return object
  *
  * @throws MissingHandlerException
  */
 public function getHandlerForCommand($commandName)
 {
     $handlerName = $commandName . 'Handler';
     if (!$this->serviceLocator->has($handlerName)) {
         throw MissingHandlerException::forCommand($commandName);
     }
     return $this->serviceLocator->get($handlerName);
 }
 /**
  * Tests if the configuration is valid
  *
  * If the configuration has a "table_service" key, and that service exists,
  * then the configuration is valid.
  *
  * Otherwise, it checks if the service $requestedName\Table exists.
  *
  * @param  array $config
  * @param  string $requestedName
  * @param  ServiceLocatorInterface $services
  * @return bool
  */
 protected function isValidConfig(array $config, $requestedName, ServiceLocatorInterface $services)
 {
     if (isset($config['table_service'])) {
         return $services->has($config['table_service']);
     }
     $tableGatewayService = $requestedName . '\\Table';
     return $services->has($tableGatewayService);
 }
Пример #15
0
 /**
  * Create the backend.
  *
  * @param ServiceLocatorInterface $serviceLocator Superior service manager
  *
  * @return BackendInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $this->serviceLocator = $serviceLocator;
     $this->edsConfig = $this->serviceLocator->get('VuFind\\Config')->get('EDS');
     if ($this->serviceLocator->has('VuFind\\Logger')) {
         $this->logger = $this->serviceLocator->get('VuFind\\Logger');
     }
     $connector = $this->createConnector();
     return $this->createBackend($connector);
 }
Пример #16
0
 /**
  * {@inheritDoc}
  */
 public function collect(MvcEvent $mvcEvent)
 {
     if (!($application = $mvcEvent->getApplication())) {
         return;
     }
     $this->serviceLocator = $application->getServiceManager();
     if ($this->serviceLocator->has('Config')) {
         $this->collectedUser = $this->getUserDetails();
     }
 }
 /**
  * Return one of the plugin manager model instances
  *
  * @param ServiceLocatorInterface $services
  * @return object
  */
 public function createService(ServiceLocatorInterface $services)
 {
     if (!$services->has('ValidatorManager')) {
         throw new ServiceNotCreatedException(sprintf('%s requires that the ValidatorManager service be present; service not found', get_class($this)));
     }
     if (!$services->has('ZF\\Apigility\\Admin\\Model\\ValidatorMetadataModel')) {
         throw new ServiceNotCreatedException(sprintf('%s requires that the %s\\ValidatorMetadataModel service be present; service not found', get_class($this), __NAMESPACE__));
     }
     return new ValidatorsModel($services->get('ValidatorManager'), $services->get('ZF\\Apigility\\Admin\\Model\\ValidatorMetadataModel'));
 }
 /**
  * {@inheritdoc}
  */
 public function __invoke($action)
 {
     if (!$this->locator->has($action)) {
         throw new ActionNotFoundException();
     }
     $action = $this->locator->get($action);
     if (!is_callable($action)) {
         throw new ActionNotExecutableException();
     }
     return $action;
 }
 /**
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @param \Doctrine\Common\Persistence\ObjectManager $objectManager
  * @param \Zend\Stdlib\Hydrator\HydratorInterface $hydrator
  * @param \Phpro\Apigility\Doctrine\Bulk\Listener\CreateListener $listener
  */
 protected function mockServices($serviceLocator, $objectManager, $hydrator, $listener)
 {
     $serviceLocator->has('doctrine-object-manager')->willReturn(true);
     $serviceLocator->get('doctrine-object-manager')->willReturn($objectManager);
     $serviceLocator->has('HydratorManager')->willReturn(true);
     $serviceLocator->get('HydratorManager')->willReturn($serviceLocator);
     $serviceLocator->has('Zend\\Hydrator')->willReturn(true);
     $serviceLocator->get('Zend\\Hydrator')->willReturn($hydrator);
     $serviceLocator->has('ListenerAggregate')->willReturn(true);
     $serviceLocator->get('ListenerAggregate')->willReturn($listener);
 }
Пример #20
0
 /**
  * Create the backend.
  *
  * @param ServiceLocatorInterface $serviceLocator Superior service manager
  *
  * @return BackendInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $this->serviceLocator = $serviceLocator;
     $configReader = $this->serviceLocator->get('VuFind\\Config');
     $this->config = $configReader->get('MetaLib');
     if ($this->serviceLocator->has('VuFind\\Logger')) {
         $this->logger = $this->serviceLocator->get('VuFind\\Logger');
     }
     $connector = $this->createConnector();
     $backend = $this->createBackend($connector);
     return $backend;
 }
Пример #21
0
 /**
  *
  * @param string $blockId
  * @param array $specs
  * @return ModelInterface
  */
 public function createBlock($blockId, array $specs)
 {
     $this->getEventManager()->trigger(__METHOD__ . '.pre', $this, ['block_id' => $blockId, 'specs' => $specs]);
     /* @var $block ModelInterface */
     $class = $this->getOption('class', $specs);
     if (null !== $this->blockManager && $this->blockManager->has($class)) {
         $block = $this->blockManager->get($class);
     } elseif ($this->serviceLocator->has($class)) {
         $block = $this->serviceLocator->get($class);
     } else {
         $block = new $class();
     }
     $block->setVariable(LayoutInterface::BLOCK_ID_VAR, $blockId);
     foreach ($this->getOption('options', $specs) as $name => $option) {
         $block->setOption($name, $option);
     }
     foreach ($this->getOption('variables', $specs) as $name => $variable) {
         $block->setVariable($name, $variable);
     }
     foreach ($this->getOption('actions', $specs) as $method => $params) {
         $params = (array) $params;
         if (is_callable([$block, $method])) {
             call_user_func_array([$block, $method], $params);
         } else {
             $method = key($params);
             if (is_callable([$block, $method])) {
                 call_user_func_array([$block, $method], (array) current($params));
             }
         }
     }
     if ($template = $this->getOption('template', $specs)) {
         $block->setTemplate($template);
     }
     if (false !== ($wrapperOptions = $this->getOption('wrapper', $specs))) {
         $this->wrapBlock($block, $wrapperOptions);
     }
     $block->setCaptureTo($this->getOption('capture_to', $specs));
     $block->setAppend($this->getOption('append', $specs));
     if ($block instanceof BlockInterface) {
         $block->setRequest($this->serviceLocator->get('Request'));
         $block->setView($this->serviceLocator->get('ViewRenderer'));
     }
     if (method_exists($block, 'init')) {
         $block->init();
     }
     $results = $this->getEventManager()->trigger('createBlock.post', $this, ['block' => $block, 'specs' => $specs, 'block_id' => $blockId], function ($result) {
         return $result instanceof ModelInterface;
     });
     if ($results->stopped()) {
         $block = $results->last();
     }
     return $block;
 }
Пример #22
0
 public function getAuthenticationService()
 {
     if (!$this->authenticationService instanceof AuthenticationServiceInterface) {
         if (!$this->services->has($this->authenticationService)) {
             throw new \Exception('Authentication Service not found');
         }
         $this->authenticationService = $this->services->get($this->authenticationService);
         if (!$this->authenticationService instanceof AuthenticationServiceInterface) {
             throw new \Exception('Authentication Service must implement Zend\\Authentication\\AuthenticationServiceInterface');
         }
     }
     return $this->authenticationService;
 }
 /**
  * Return a filter plugin manager model instances
  *
  * @param ServiceLocatorInterface $services
  * @return FiltersModel
  */
 public function createService(ServiceLocatorInterface $services)
 {
     if (!$services->has('FilterManager')) {
         throw new ServiceNotCreatedException(sprintf('%s requires that the FilterManager service be present; service not found', get_class($this)));
     }
     $metadata = [];
     if ($services->has('Config')) {
         $config = $services->get('Config');
         if (isset($config['filter_metadata']) && is_array($config['filter_metadata'])) {
             $metadata = $config['filter_metadata'];
         }
     }
     return new FiltersModel($services->get('FilterManager'), $metadata);
 }
 protected function getSubscriber($name)
 {
     $subscriber = $name;
     if (is_string($subscriber) && $this->serviceLocator->has($subscriber)) {
         $subscriber = $this->serviceLocator->get($subscriber);
     } elseif (is_string($subscriber) && class_exists($subscriber)) {
         $subscriber = new $subscriber();
     }
     if ($subscriber instanceof EventSubscriber) {
         return $subscriber;
     }
     $subscriberType = is_object($name) ? get_class($name) : $name;
     throw new InvalidArgumentException(sprintf('Invalid event subscriber "%s" given, must be a service name, ' . 'class name or an instance implementing Doctrine\\Common\\EventSubscriber', $subscriberType));
 }
 /**
  * Create the DefaultAuthorizationListener
  *
  * @param ServiceLocatorInterface $services
  * @return DefaultAuthorizationListener
  */
 public function createService(ServiceLocatorInterface $services)
 {
     if (!$services->has('ZF\\MvcAuth\\Authorization\\AuthorizationInterface')) {
         throw new ServiceNotCreatedException('Cannot create DefaultAuthorizationListener service; ' . 'no ZF\\MvcAuth\\Authorization\\AuthorizationInterface service available!');
     }
     return new DefaultAuthorizationListener($services->get('ZF\\MvcAuth\\Authorization\\AuthorizationInterface'));
 }
Пример #26
0
 /**
  * Create and return the router
  *
  * Retrieves the "router" key of the Config service, and uses it
  * to instantiate the router. Uses the TreeRouteStack implementation by
  * default.
  *
  * @param  ServiceLocatorInterface        $serviceLocator
  * @param  string|null                     $cName
  * @param  string|null                     $rName
  * @return \Zend\Mvc\Router\RouteStackInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator, $cName = null, $rName = null)
 {
     $config = $serviceLocator->has('Config') ? $serviceLocator->get('Config') : array();
     // Defaults
     $routerClass = 'Zend\\Mvc\\Router\\Http\\TreeRouteStack';
     $routerConfig = isset($config['router']) ? $config['router'] : array();
     // Console environment?
     if ($rName === 'ConsoleRouter' || $cName === 'router' && Console::isConsole()) {
         // We are in a console, use console router defaults.
         $routerClass = 'Zend\\Mvc\\Router\\Console\\SimpleRouteStack';
         $routerConfig = isset($config['console']['router']) ? $config['console']['router'] : array();
     }
     // Obtain the configured router class, if any
     if (isset($routerConfig['router_class']) && class_exists($routerConfig['router_class'])) {
         $routerClass = $routerConfig['router_class'];
     }
     // Inject the route plugins
     if (!isset($routerConfig['route_plugins'])) {
         $routePluginManager = $serviceLocator->get('RoutePluginManager');
         $routerConfig['route_plugins'] = $routePluginManager;
     }
     // Obtain an instance
     $factory = sprintf('%s::factory', $routerClass);
     return call_user_func($factory, $routerConfig);
 }
 protected function processConfig(&$config, ServiceLocatorInterface $services)
 {
     if (isset($config['writer_plugin_manager']) && is_string($config['writer_plugin_manager']) && $services->has($config['writer_plugin_manager'])) {
         $config['writer_plugin_manager'] = $services->get($config['writer_plugin_manager']);
     }
     if ((!isset($config['writer_plugin_manager']) || !$config['writer_plugin_manager'] instanceof AbstractPluginManager) && $services->has('LogWriterManager')) {
         $config['writer_plugin_manager'] = $services->get('LogWriterManager');
     }
     if (isset($config['processor_plugin_manager']) && is_string($config['processor_plugin_manager']) && $services->has($config['processor_plugin_manager'])) {
         $config['processor_plugin_manager'] = $services->get($config['processor_plugin_manager']);
     }
     if ((!isset($config['processor_plugin_manager']) || !$config['processor_plugin_manager'] instanceof AbstractPluginManager) && $services->has('LogProcessorManager')) {
         $config['processor_plugin_manager'] = $services->get('LogProcessorManager');
     }
     if (!isset($config['writers'])) {
         return;
     }
     foreach ($config['writers'] as $index => $writerConfig) {
         if (!isset($writerConfig['options']['db']) || !is_string($writerConfig['options']['db'])) {
             continue;
         }
         if (!$services->has($writerConfig['options']['db'])) {
             continue;
         }
         // Retrieve the DB service from the service locator, and
         // inject it into the configuration.
         $db = $services->get($writerConfig['options']['db']);
         $config['writers'][$index]['options']['db'] = $db;
     }
 }
Пример #28
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     // The parameters in Doctrine 2 and ZF2 are slightly different.
     // Below is an example how we can reuse the db settings
     $doctrineDbConfig = (array) $config['db'];
     $doctrineDbConfig['driver'] = strtolower($doctrineDbConfig['driver']);
     if (!isset($doctrineDbConfig['dbname'])) {
         $doctrineDbConfig['dbname'] = $doctrineDbConfig['database'];
     }
     if (!isset($doctrineDbConfig['host'])) {
         $doctrineDbConfig['host'] = $doctrineDbConfig['hostname'];
     }
     if (!isset($doctrineDbConfig['user'])) {
         $doctrineDbConfig['user'] = $doctrineDbConfig['username'];
     }
     $doctrineConfig = Setup::createAnnotationMetadataConfiguration($config['doctrine']['entity_path'], true);
     $entityManager = DoctrineEntityManager::create($doctrineDbConfig, $doctrineConfig);
     if (isset($config['doctrine']['initializers'])) {
         $eventManager = $entityManager->getEventManager();
         foreach ($config['doctrine']['initializers'] as $initializer) {
             $eventClass = new DoctrineEvent(new $initializer(), $serviceLocator);
             $eventManager->addEventListener(\Doctrine\ORM\Events::postLoad, $eventClass);
         }
     }
     if ($serviceLocator->has('doctrine-profiler')) {
         $profiler = $serviceLocator->get('doctrine-profiler');
         $entityManager->getConfiguration()->setSQLLogger($profiler);
     }
     return $entityManager;
 }
 /**
  * @param ServiceLocatorInterface $services
  * @throws ServiceNotCreatedException
  * @return false|HttpAuthAdapter
  */
 public function createService(ServiceLocatorInterface $services)
 {
     // If no configuration present, nothing to create
     if (!$services->has('config')) {
         return false;
     }
     $config = $services->get('config');
     // If no HTTP adapter configuration present, nothing to create
     if (!isset($config['zf-mvc-auth']['authentication']['http'])) {
         return false;
     }
     $httpConfig = $config['zf-mvc-auth']['authentication']['http'];
     if (!isset($httpConfig['accept_schemes']) || !is_array($httpConfig['accept_schemes'])) {
         throw new ServiceNotCreatedException('"accept_schemes" is required when configuring an HTTP authentication adapter');
     }
     if (!isset($httpConfig['realm'])) {
         throw new ServiceNotCreatedException('"realm" is required when configuring an HTTP authentication adapter');
     }
     if (in_array('digest', $httpConfig['accept_schemes'])) {
         if (!isset($httpConfig['digest_domains']) || !isset($httpConfig['nonce_timeout'])) {
             throw new ServiceNotCreatedException('Both "digest_domains" and "nonce_timeout" are required when configuring an HTTP digest authentication adapter');
         }
     }
     $httpAdapter = new HttpAuth(array_merge($httpConfig, array('accept_schemes' => implode(' ', $httpConfig['accept_schemes']))));
     if (in_array('basic', $httpConfig['accept_schemes']) && isset($httpConfig['htpasswd'])) {
         $httpAdapter->setBasicResolver(new HttpAuth\ApacheResolver($httpConfig['htpasswd']));
     }
     if (in_array('digest', $httpConfig['accept_schemes']) && isset($httpConfig['htdigest'])) {
         $httpAdapter->setDigestResolver(new HttpAuth\FileResolver($httpConfig['htdigest']));
     }
     return $httpAdapter;
 }
 /**
  * Create service with name
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @param $name
  * @param $requestedName
  * @return mixed
  */
 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
 {
     $name = substr($requestedName, strlen(self::MANAGER_PREFIX));
     $config = $serviceLocator->get('config');
     $workerConfig = $config['workers'][$name];
     if (!$serviceLocator->has($workerConfig['manager']['director'])) {
         throw new \RuntimeException("Could not load {$workerConfig['manager']['director']}");
     }
     $director = $serviceLocator->get($workerConfig['manager']['director']);
     if (!$director instanceof DirectorInterface) {
         throw new \RuntimeException("Could not load {$workerConfig['manager']['director']}");
     }
     $rabbitMqSettings = isset($workerConfig['rabbitmq_settings']) ? $workerConfig['rabbitmq_settings'] : $config['rabbitmq_settings'];
     $conn = new AMQPConnection($rabbitMqSettings['host'], $rabbitMqSettings['port'], $rabbitMqSettings['username'], $rabbitMqSettings['password']);
     // Bind to the generic exchange
     $eventChannel = $conn->channel();
     $exchange = $workerConfig['manager']['general']['exchange']['name'];
     $exchangeType = $workerConfig['manager']['general']['exchange']['type'];
     $eventQueueName = $workerConfig['manager']['general']['queue']['name'];
     $routingKey = isset($workerConfig['manager']['general']['queue']['routing_key']) ? $workerConfig['manager']['general']['queue']['routing_key'] : null;
     $eventChannel->queue_declare($eventQueueName, false, true, false, false);
     $eventChannel->exchange_declare($exchange, $exchangeType, false, false, true);
     $eventChannel->queue_bind($eventQueueName, $exchange, $routingKey);
     // Bind to the one specific for the workers
     $processorQueueName = $workerConfig['manager']['worker']['queue']['name'];
     $workerExchange = $workerConfig['manager']['worker']['exchange']['name'];
     $workerExchangeType = $workerConfig['manager']['worker']['exchange']['type'];
     $workerChannel = $conn->channel();
     $workerChannel->exchange_declare($workerExchange, $workerExchangeType, false, false, false);
     $workerChannel->queue_declare($processorQueueName, false, true, false, false);
     $workerChannel->queue_bind($processorQueueName, $workerExchange);
     return new DirectedManager($conn, $eventChannel, $eventQueueName, $workerChannel, $workerExchange, $processorQueueName, $director);
 }