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); }
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); }
/** * {@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); }
/** * 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')); }
/** * 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; } }
/** * 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')); } }