當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。