當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ServiceLocatorInterface::has方法代碼示例

本文整理匯總了PHP中Zend\ServiceManager\ServiceLocatorInterface::has方法的典型用法代碼示例。如果您正苦於以下問題:PHP ServiceLocatorInterface::has方法的具體用法?PHP ServiceLocatorInterface::has怎麽用?PHP ServiceLocatorInterface::has使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\ServiceManager\ServiceLocatorInterface的用法示例。


在下文中一共展示了ServiceLocatorInterface::has方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createService

 /**
  * 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;
 }
開發者ID:xemlock,項目名稱:HumusMvc,代碼行數:43,代碼來源:FrontControllerFactory.php

示例2: createService

 /**
  * @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;
 }
開發者ID:zf2-boiler-app,項目名稱:app-messenger,代碼行數:40,代碼來源:MailMessageRendererFactory.php

示例3: createService

 /**
  * 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;
 }
開發者ID:xemlock,項目名稱:HumusMvc,代碼行數:40,代碼來源:ModuleManagerFactory.php

示例4: getSharedInstance

 /**
  * 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);
 }
開發者ID:paulbriton,項目名稱:streaming_diffusion,代碼行數:13,代碼來源:DiInstanceManagerProxy.php

示例5: createService

 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);
 }
開發者ID:zend-modules,項目名稱:maintenance,代碼行數:26,代碼來源:MaintenanceConfigFactory.php

示例6: createService

 /**
  * 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;
 }
開發者ID:BrunoSpy,項目名稱:DoctrineMigrationsModule,代碼行數:32,代碼來源:ConfigurationFactory.php

示例7: createService

 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;
 }
開發者ID:zend-modules,項目名稱:localemanager_outdated,代碼行數:32,代碼來源:LocaleManagerFactory.php

示例8: createService

 /**
  * {@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;
 }
開發者ID:coolms,項目名稱:common,代碼行數:31,代碼來源:AnnotationBuilderFactory.php

示例9: getSocialConnector

 /**
  * @param $socialNetwork
  * @return SocialConnectorInterface
  * @throws InvalidSocialNetworkException
  */
 protected function getSocialConnector($socialNetwork)
 {
     if (!$this->socialPlugins->has($socialNetwork)) {
         throw new InvalidSocialNetworkException($socialNetwork);
     }
     return $this->socialPlugins->get($socialNetwork);
 }
開發者ID:nomaanp,項目名稱:di-with-plugin-manager,代碼行數:12,代碼來源:SocialUsers.php

示例10: createService

 /**
  * @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());
 }
開發者ID:JeoffScott,項目名稱:dyplom,代碼行數:32,代碼來源:TranslatorServiceFactory.php

示例11: createService

    /**
     * {@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);
    }
開發者ID:jbarentsen,項目名稱:drb,代碼行數:30,代碼來源:AcceptListenerFactory.php

示例12: build

 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;
 }
開發者ID:cross-solution,項目名稱:yawik,代碼行數:59,代碼來源:SettingsFieldset.php

示例13: getHandlerForCommand

 /**
  * 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);
 }
開發者ID:jeremygiberson,項目名稱:what-changed,代碼行數:17,代碼來源:AppendLocator.php

示例14: isValidConfig

 /**
  * 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);
 }
開發者ID:nuxwin,項目名稱:zf-apigility,代碼行數:21,代碼來源:DbConnectedResourceAbstractFactory.php

示例15: createService

 /**
  * 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);
 }
開發者ID:steenlibrary,項目名稱:vufind,代碼行數:17,代碼來源:EdsBackendFactory.php


注:本文中的Zend\ServiceManager\ServiceLocatorInterface::has方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。