本文整理汇总了PHP中Nette\DI\Container::findByTag方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::findByTag方法的具体用法?PHP Container::findByTag怎么用?PHP Container::findByTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DI\Container
的用法示例。
在下文中一共展示了Container::findByTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createPresenter
/**
* 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;
}
示例2: __construct
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;
}
示例3: create
/**
* @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;
}
示例4: create
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)));
}
示例5: create
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));
}
示例6: getSections
/**
* @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;
}
示例7: create
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);
}
示例8: execute
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();
}
}
}
示例9: __invoke
/**
* @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]);
}
示例10: createRouter
/**
* @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;
}
示例11: createConsole
/**
* @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;
}
示例12: createPresenter
/**
* 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]);
}
示例13: findConsumer
/**
* @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;
}
示例14: createConsole
/**
* @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;
}
示例15: setupEventManager
/**
* @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));
}
}