findByTag() public method

Gets the service names of the specified tag.
public findByTag ( $tag ) : array
return array of [service name => tag attributes]
 /**
  * Creates new presenter instance.
  *
  * @param  string presenter class name
  * @return Application\IPresenter
  */
 public function createPresenter($class)
 {
     $callInjects = $this->alwaysCallInjects;
     $services = array_keys($this->container->findByTag('nette.presenter'), $class);
     if (count($services) > 1) {
         throw new Application\InvalidPresenterException("Multiple services of type {$class} found: " . implode(', ', $services) . '.');
     } elseif (count($services)) {
         $presenter = $this->container->createService($services[0]);
         $callInjects = FALSE;
     } elseif (count($services = $this->container->findByType($class)) === 1) {
         $presenter = $this->container->createService($services[0]);
     } else {
         $presenter = $this->container->createInstance($class);
         $callInjects = TRUE;
     }
     if (!$presenter instanceof Application\IPresenter) {
         throw new UnexpectedValueException("Unable to create create presenter, returned value is not Nette\\Application\\IPresenter type.");
     }
     if ($callInjects) {
         $this->container->callInjects($presenter);
     }
     if ($presenter instanceof Application\UI\Presenter && $presenter->invalidLinkMode === NULL) {
         $presenter->invalidLinkMode = $this->invalidLinkMode;
     }
     return $presenter;
 }
Esempio n. 2
0
 public function __construct(Container $container)
 {
     $this->connections = array_keys($container->findByTag(OrmExtension::TAG_CONNECTION));
     $this->defaultConnection = $container->findByType('Doctrine\\DBAL\\Connection');
     $this->managers = array_keys($container->findByTag(OrmExtension::TAG_ENTITY_MANAGER));
     $this->defaultManager = $container->findByType('Doctrine\\ORM\\EntityManager');
     $this->container = $container;
 }
Esempio n. 3
0
 /**
  * @return MapperMatrix
  */
 public function create()
 {
     $matrix = new MapperMatrix();
     foreach ($this->container->findByTag('echo511.leanmapper.mapper') as $serviceName => $tagAttributes) {
         $matrix->addMapper($this->container->getService($serviceName));
     }
     return $matrix;
 }
Esempio n. 4
0
 public function create() : Registry
 {
     $tagToService = function (array $tags) {
         return array_map(function (string $serviceName) {
             return $this->container->getService($serviceName);
         }, array_keys($tags));
     };
     return new Registry($tagToService($this->container->findByTag(self::RULE_TAG)));
 }
Esempio n. 5
0
 public function create() : Broker
 {
     $tagToService = function (array $tags) {
         return array_map(function (string $serviceName) {
             return $this->container->getService($serviceName);
         }, array_keys($tags));
     };
     $phpClassReflectionExtension = $this->container->getByType(PhpClassReflectionExtension::class);
     return new Broker(array_merge([$phpClassReflectionExtension], $tagToService($this->container->findByTag(self::PROPERTIES_CLASS_REFLECTION_EXTENSION_TAG))), array_merge([$phpClassReflectionExtension], $tagToService($this->container->findByTag(self::METHODS_CLASS_REFLECTION_EXTENSION_TAG))), $tagToService($this->container->findByTag(self::DYNAMIC_METHOD_RETURN_TYPE_EXTENSION_TAG)), $this->container->getByType(FunctionReflectionFactory::class));
 }
 /**
  * @return TargetSection[]
  * @throws \Nette\InvalidStateException
  */
 public function getSections()
 {
     $sections = array();
     foreach ($this->container->findByTag("Brabijan.seo.targetSectionProvider") as $serviceName => $attributes) {
         $section = $this->container->getService($serviceName);
         if (!$section instanceof ITargetSectionProvider) {
             throw new InvalidStateException('Target provider must be instance of Brabijan\\SeoComponents\\DI\\ITargetSectionProvider');
         }
         $sections[] = $section->getTargetSection();
     }
     return $sections;
 }
Esempio n. 7
0
 public function create()
 {
     $serviceNames = $this->context->findByTag($this->tagName);
     $jobs = array();
     foreach ($serviceNames as $name => $attrs) {
         $job = $this->context->getService($name);
         if (!$job instanceof IJob) {
             throw new \InvalidArgumentException("Service {$name} must implements Cron\\IJob interface!");
         }
         $jobs[] = $job;
     }
     return new Cron($jobs);
 }
Esempio n. 8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (defined('AMQP_DEBUG') === false) {
         define('AMQP_DEBUG', (bool) $input->getOption('debug'));
     }
     $output->writeln('Setting up the Rabbit MQ fabric');
     foreach (array(RabbitMqExtension::TAG_PRODUCER, RabbitMqExtension::TAG_CONSUMER, RabbitMqExtension::TAG_RPC_CLIENT, RabbitMqExtension::TAG_RPC_SERVER) as $tag) {
         foreach ($this->container->findByTag($tag) as $serviceId => $meta) {
             /** @var AmqpMember $service */
             $service = $this->container->getService($serviceId);
             $service->setupFabric();
         }
     }
 }
 /**
  * @return Nette\Application\IPresenter
  */
 public function __invoke($class)
 {
     $services = array_keys($this->container->findByTag('nette.presenter'), $class);
     if (count($services) > 1) {
         throw new Nette\Application\InvalidPresenterException("Multiple services of type {$class} found: " . implode(', ', $services) . '.');
     } elseif (!$services) {
         if ($this->touchToRefresh) {
             touch($this->touchToRefresh);
         }
         $presenter = $this->container->createInstance($class);
         $this->container->callInjects($presenter);
         if ($presenter instanceof Nette\Application\UI\Presenter && $presenter->invalidLinkMode === NULL) {
             $presenter->invalidLinkMode = $this->invalidLinkMode;
         }
         return $presenter;
     }
     return $this->container->createService($services[0]);
 }
Esempio n. 10
0
 /**
  * @param Nette\DI\Container $di
  *
  * @return Nette\Application\IRouter
  */
 public static function createRouter(Nette\DI\Container $di)
 {
     $router = new Nette\Application\Routers\RouteList();
     foreach ($di->findByTag('router') as $name => $hasTag) {
         if ($hasTag) {
             $router[] = $di->getService($name);
         }
     }
     return $router;
 }
 /**
  * @param Container
  * @return Application
  */
 public static function createConsole(Container $container, $config)
 {
     $console = new Application($config['name'], $config['version']);
     $helperSet = new HelperSet();
     foreach (array_keys($container->findByTag(self::HELPER_TAG)) as $name) {
         $helperSet->set($container->getService($name), $name);
     }
     $console->setHelperSet($helperSet);
     $console->setCatchExceptions($config['catchExceptions']);
     $commands = [];
     foreach (array_keys($container->findByTag(self::COMMAND_TAG)) as $name) {
         $commands[] = $container->getService($name);
     }
     foreach (array_keys($container->findByTag(self::KDYBY_COMMAND_TAG)) as $name) {
         $commands[] = $container->getService($name);
     }
     $console->addCommands($commands);
     return $console;
 }
 /**
  * Creates new presenter instance.
  * @param  string  presenter name
  * @return IPresenter
  */
 public function createPresenter($name)
 {
     $class = $this->getPresenterClass($name);
     $services = array_keys($this->container->findByTag('nette.presenter'), $class);
     if (count($services) > 1) {
         throw new InvalidPresenterException("Multiple services of type {$class} found: " . implode(', ', $services) . '.');
     } elseif (!$services) {
         if ($this->autoRebuild) {
             $rc = new \ReflectionClass($this->container);
             @unlink($rc->getFileName());
             // @ file may not exists
         }
         $presenter = $this->container->createInstance($class);
         $this->container->callInjects($presenter);
         if ($presenter instanceof UI\Presenter && $presenter->invalidLinkMode === NULL) {
             $presenter->invalidLinkMode = $this->container->parameters['debugMode'] ? UI\Presenter::INVALID_LINK_WARNING : UI\Presenter::INVALID_LINK_SILENT;
         }
         return $presenter;
     }
     return $this->container->createService($services[0]);
 }
 /**
  * @param string $routingKey
  * @return Kdyby\RabbitMq\Consumer
  */
 private function findConsumer($routingKey)
 {
     foreach ($this->serviceLocator->findByTag(RabbitMqExtension::TAG_CONSUMER) as $consumerService => $_) {
         /** @var Kdyby\RabbitMq\Consumer $consumer */
         $consumer = $this->serviceLocator->getService($consumerService);
         if ($consumer instanceof Kdyby\RabbitMq\MultipleConsumer) {
             continue;
             // todo: not yet implemented
         }
         if ($consumer->exchangeOptions['name'] !== $this->exchangeOptions['name']) {
             continue;
             // nope
         }
         if (empty($routingKey)) {
             return $consumer;
         }
         continue;
         // todo: not yet implemented
     }
     return NULL;
 }
 /**
  * @param \Nette\DI\Container
  * @param \Symfony\Component\Console\Helper\HelperSet
  * @return \Symfony\Component\Console\Application
  */
 public static function createConsole(\Nette\DI\Container $container, \Symfony\Component\Console\Helper\HelperSet $helperSet = NULL)
 {
     $console = new \Symfony\Component\Console\Application(Framework::NAME . " Command Line Interface", Framework::VERSION);
     if (!$helperSet) {
         $helperSet = new \Symfony\Component\Console\Helper\HelperSet();
         $helperSet->set(new \Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper($container->documentManager), 'dm');
         $helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
     }
     $console->setHelperSet($helperSet);
     $console->setCatchExceptions(FALSE);
     $commands = array();
     foreach (array_keys($container->findByTag('consoleCommand')) as $name) {
         $commands[] = $container->getService($name);
     }
     $console->addCommands($commands);
     return $console;
 }
Esempio n. 15
0
 /**
  * @param \Doctrine\Common\EventManager
  * @param \Nette\DI\Container
  */
 public static function setupEventManager(EventManager $evm, Container $container)
 {
     foreach ($container->findByTag(static::EVENT_TAG_NAME) as $name => $value) {
         $evm->addEventSubscriber($container->getService($name));
     }
 }
Esempio n. 16
0
 /**
  * @param mixed $voterConsumer
  * @param Container $container
  */
 public static function setupVoters($voterConsumer, Container $container)
 {
     foreach ($container->findByTag(static::VOTER_TAG_NAME) as $name => $value) {
         $voterConsumer->addVoter($container->getService($name));
     }
 }
Esempio n. 17
0
 /**
  * @param string $tag
  * @return array
  */
 public function findByTag($tag)
 {
     return $this->container->findByTag($tag);
 }