当前位置: 首页>>代码示例>>PHP>>正文


PHP ContainerInterface::getServiceLocator方法代码示例

本文整理汇总了PHP中Interop\Container\ContainerInterface::getServiceLocator方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerInterface::getServiceLocator方法的具体用法?PHP ContainerInterface::getServiceLocator怎么用?PHP ContainerInterface::getServiceLocator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interop\Container\ContainerInterface的用法示例。


在下文中一共展示了ContainerInterface::getServiceLocator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 public function __invoke(ContainerInterface $container)
 {
     $filter = new OpenGraphFilter();
     $validator = new OpenGraphValidator();
     $hydrator = new OpenGraphHydrator();
     /** @var \Doctrine\ORM\EntityManagerInterface $entityManager */
     $entityManager = $container->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     /** @var \Zend\Cache\Storage\StorageInterface $cache */
     $cache = $container->getServiceLocator()->get('Rcm\\Service\\Cache');
     /** @var ServerUrl $serverUrl */
     $serverUrl = $container->getServiceLocator()->get('ViewHelperManager')->get('serverUrl');
     return new AdminController($filter, $validator, $hydrator, $entityManager, $cache, $serverUrl);
 }
开发者ID:wshafer,项目名称:opengraph,代码行数:13,代码来源:AdminControllerFactory.php

示例2: __invoke

 public function __invoke(ContainerInterface $container)
 {
     $serviceLocator = $container->getServiceLocator();
     /** @var \Doctrine\ORM\EntityManagerInterface $entityManager */
     $entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
     /** @var \Zend\Cache\Storage\StorageInterface $cache */
     $cache = $serviceLocator->get('Rcm\\Service\\Cache');
     $config = $serviceLocator->get('config');
     return new OpenGraph($entityManager, $cache, $config);
 }
开发者ID:wshafer,项目名称:opengraph,代码行数:10,代码来源:OpenGraphFactory.php

示例3: __invoke

 /**
  * {@inheritDoc}
  *
  * Allows creation of services only when in a whitelist
  */
 public function __invoke(ContainerInterface $container, $name, array $options = null)
 {
     if (!isset($this->allowedServiceNames[$name])) {
         throw new Exception\InvalidServiceException(sprintf('Service "%s" is not whitelisted', $name));
     }
     $this->container = $container instanceof AbstractPluginManager ? $container->getServiceLocator() : $container;
     return parent::get($name);
 }
开发者ID:zendframework,项目名称:zend-servicemanager-di,代码行数:13,代码来源:DiStrictAbstractServiceFactory.php

示例4: MigrationController

 /**
  * The __invoke method is called when a script tries to call an object as a function.
  *
  * @param ContainerInterface $container
  * @param string $name
  * @param array $options
  * @return mixed
  */
 function __invoke(ContainerInterface $container, $name, array $options = null)
 {
     $instance = new MigrationController();
     return $instance->setMigrationService($container->getServiceLocator()->get('MigrationService'));
 }
开发者ID:andrey-mokhov,项目名称:anelegan-db,代码行数:13,代码来源:MigrationControllerFactory.php

示例5: injectTranslator

 /**
  * Inject a helper instance with the registered translator
  *
  * @param ContainerInterface|Helper\HelperInterface $first helper instance
  *     under zend-servicemanager v2, ContainerInterface under v3.
  * @param ContainerInterface|Helper\HelperInterface $second
  *     ContainerInterface under zend-servicemanager v3, helper instance
  *     under v2. Ignored regardless.
  */
 public function injectTranslator($first, $second)
 {
     if ($first instanceof ContainerInterface) {
         // v3 usage
         $container = $first;
         $helper = $second;
     } else {
         // v2 usage; grab the parent container
         $container = $second->getServiceLocator();
         $helper = $first;
     }
     if (!$helper instanceof TranslatorAwareInterface) {
         return;
     }
     if (!$container) {
         // Under zend-navigation v2.5, the navigation PluginManager is
         // always lazy-loaded, which means it never has a parent
         // container.
         return;
     }
     if ($container->has('MvcTranslator')) {
         $helper->setTranslator($container->get('MvcTranslator'));
         return;
     }
     if ($container->has('Zend\\I18n\\Translator\\TranslatorInterface')) {
         $helper->setTranslator($container->get('Zend\\I18n\\Translator\\TranslatorInterface'));
         return;
     }
     if ($container->has('Translator')) {
         $helper->setTranslator($container->get('Translator'));
         return;
     }
 }
开发者ID:vbryan,项目名称:Zend,代码行数:42,代码来源:HelperPluginManager.php

示例6: injectEventManager

 /**
  * Inject a helper instance with the registered event manager
  *
  * @param ContainerInterface|Helper\HelperInterface $first helper instance
  *     under zend-servicemanager v2, ContainerInterface under v3.
  * @param ContainerInterface|Helper\HelperInterface $second
  *     ContainerInterface under zend-servicemanager v3, helper instance
  *     under v2. Ignored regardless.
  */
 public function injectEventManager($first, $second)
 {
     if ($first instanceof ContainerInterface) {
         // v3 usage
         $container = $first;
         $helper = $second;
     } else {
         // v2 usage; grab the parent container
         $container = $second->getServiceLocator();
         $helper = $first;
     }
     if (!$container) {
         // Under zend-navigation v2.5, the navigation PluginManager is
         // always lazy-loaded, which means it never has a parent
         // container.
         return;
     }
     if (!$helper instanceof EventManagerAwareInterface) {
         return;
     }
     if (!$container->has('EventManager')) {
         // If the container doesn't have an EM service, do nothing.
         return;
     }
     $events = $helper->getEventManager();
     if (!$events || !$events->getSharedManager() instanceof SharedEventManagerInterface) {
         $helper->setEventManager($container->get('EventManager'));
     }
 }
开发者ID:froschdesign,项目名称:zend-view,代码行数:38,代码来源:HelperPluginManager.php


注:本文中的Interop\Container\ContainerInterface::getServiceLocator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。