本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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'));
}
示例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;
}
}
示例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'));
}
}