本文整理匯總了PHP中Symfony\Component\DependencyInjection\DefinitionDecorator::addTag方法的典型用法代碼示例。如果您正苦於以下問題:PHP DefinitionDecorator::addTag方法的具體用法?PHP DefinitionDecorator::addTag怎麽用?PHP DefinitionDecorator::addTag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\DefinitionDecorator
的用法示例。
在下文中一共展示了DefinitionDecorator::addTag方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createCollector
private function createCollector($type, $config)
{
$definition = new DefinitionDecorator('beberlei_metrics.collector_proto.' . $config['type']);
// Theses listeners should be as late as possible
$definition->addTag('kernel.event_listener', array('method' => 'flush', 'priority' => -1024, 'event' => 'kernel.terminate'));
$definition->addTag('kernel.event_listener', array('method' => 'flush', 'priority' => -1024, 'event' => 'console.terminate'));
switch ($type) {
case 'doctrine_dbal':
$ref = $config['connection'] ? sprintf('doctrine.dbal.%s_connection', $config['connection']) : 'database_connection';
$definition->replaceArgument(0, new Reference($ref));
return $definition;
case 'graphite':
$definition->replaceArgument(0, $config['host'] ?: 'localhost');
$definition->replaceArgument(1, $config['port'] ?: 2003);
$definition->replaceArgument(2, $config['protocol'] ?: 'tcp');
return $definition;
case 'librato':
$definition->replaceArgument(1, $config['source']);
$definition->replaceArgument(2, $config['username']);
$definition->replaceArgument(3, $config['password']);
return $definition;
case 'logger':
case 'null':
return $definition;
case 'statsd':
$definition->replaceArgument(0, $config['host'] ?: 'localhost');
$definition->replaceArgument(1, $config['port'] ?: 8125);
$definition->replaceArgument(2, (string) $config['prefix']);
return $definition;
case 'zabbix':
$sender = new Definition('Net\\Zabbix\\Sender');
if ($config['file']) {
$senderConfig = new Definition('Net\\Zabbix\\Agent\\Config');
$senderConfig->addArgument($config['file']);
$sender->addMethodCall('importAgentConfig', array($senderConfig));
} else {
$sender->addArgument($config['host'] ?: 'localhost');
$sender->addArgument((int) $config['port'] ?: 10051);
}
$definition->replaceArgument(0, $sender);
$definition->replaceArgument(1, $config['prefix']);
return $definition;
case 'credis':
$credis_client = new Definition('Credis_Client');
$credis_client->addArgument($config['host'] ?: 'localhost');
$credis_client->addArgument($config['port'] ?: 6379);
$definition->replaceArgument(0, $credis_client);
return $definition;
default:
throw new \InvalidArgumentException(sprintf('The type "%s" is not supported', $type));
}
}
示例2: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if ($container->hasDefinition('doctrine')) {
$definition = new DefinitionDecorator('dag.form.type.object_to_identifier');
$definition->addArgument(new Reference('doctrine'));
$definition->addArgument('dag_entity_to_identifier');
$definition->addTag('form.type', array('alias' => 'dag_entity_to_identifier'));
$container->setDefinition('dag_entity_to_identifier', $definition);
}
if ($container->hasDefinition('doctrine_mongodb')) {
$definition = new DefinitionDecorator('dag.form.type.object_to_identifier');
$definition->addArgument(new Reference('doctrine_mongodb'));
$definition->addArgument('dag_document_to_identifier');
$definition->addTag('form.type', array('alias' => 'dag_document_to_identifier'));
$container->setDefinition('dag_document_to_identifier', $definition);
if (!$container->hasDefinition('dag_entity_to_identifier')) {
$container->setAlias('dag_entity_to_identifier', 'dag_document_to_identifier');
}
}
if ($container->hasDefinition('doctrine_phpcr')) {
$definition = new DefinitionDecorator('dag.form.type.object_to_identifier');
$definition->addArgument(new Reference('doctrine_phpcr'));
$definition->addArgument('dag_phpcr_document_to_identifier');
$definition->addTag('form.type', array('alias' => 'dag_phpcr_document_to_identifier'));
$container->setDefinition('dag_phpcr_document_to_identifier', $definition);
if (!$container->hasDefinition('dag_entity_to_identifier')) {
$container->setAlias('dag_entity_to_identifier', 'dag_phpcr_document_to_identifier');
}
}
}
示例3: createConverter
private function createConverter($name, array $config, ContainerBuilder $container)
{
$environment = new DefinitionDecorator($config['environment']);
$environment->setPublic(false);
$environment->setClass($container->getDefinition($config['environment'])->getClass());
$environment->addMethodCall('mergeConfig', [$config['config']]);
$environment->addTag('webuni_commonmark.environment.extensions', $config['extensions']);
// $environment->addTag('webuni_commonmark.environment', ['parent' => $config['environment'], 'extensions' => [$config['extensions']]);
$environmentName = 'webuni_commonmark.' . $name . '_environment' . $config['environment'];
$container->setDefinition($environmentName, $environment);
$parser = new DefinitionDecorator($config['parser']);
$parser->setPublic(false);
$parser->setClass($container->getDefinition($config['parser'])->getClass());
$parser->replaceArgument(0, new Reference($environmentName));
$renderer = new DefinitionDecorator($config['renderer']);
$renderer->setPublic(false);
$renderer->setClass($container->getDefinition($config['renderer'])->getClass());
$renderer->replaceArgument(0, new Reference($environmentName));
$converter = new DefinitionDecorator($config['converter']);
$converter->setPublic(true);
$converter->setClass($container->getDefinition($config['converter'])->getClass());
$converter->replaceArgument(0, $parser);
$converter->replaceArgument(1, $renderer);
$converterName = 'webuni_commonmark.' . $name . '_converter';
$container->setDefinition($converterName, $converter);
return $converterName;
}
示例4: process
/**
* @param ContainerBuilder $container
*
* @throws \InvalidArgumentException
*/
public function process(ContainerBuilder $container)
{
$config = $container->getExtensionConfig('elastica')[0];
$jsonLdFrameLoader = $container->get('nemrod.elastica.jsonld.frame.loader.filesystem');
$confManager = $container->getDefinition('nemrod.elastica.config_manager');
$filiationBuilder = $container->get('nemrod.filiation.builder');
$jsonLdFrameLoader->setFiliationBuilder($filiationBuilder);
foreach ($config['indexes'] as $name => $index) {
$indexName = isset($index['index_name']) ? $index['index_name'] : $name;
foreach ($index['types'] as $typeName => $settings) {
$jsonLdFrameLoader->setEsIndex($name);
$frame = $jsonLdFrameLoader->load($settings['frame'], null, true, true, true);
$type = !empty($frame['@type']) ? $frame['@type'] : $settings['type'];
if (empty($type)) {
throw \Exception("You must provide a RDF Type.");
}
//type
$typeId = 'nemrod.elastica.type.' . $name . '.' . $typeName;
$indexId = 'nemrod.elastica.index.' . $name;
$typeDef = new DefinitionDecorator('nemrod.elastica.type.abstract');
$typeDef->replaceArgument(0, $type);
$typeDef->setFactory(array(new Reference($indexId), 'getType'));
$typeDef->addTag('nemrod.elastica.type', array('index' => $name, 'name' => $typeName, 'type' => $type));
$container->setDefinition($typeId, $typeDef);
//registering config to configManager
$confManager->addMethodCall('setTypeConfigurationArray', array($name, $typeName, $type, $frame));
}
}
}
示例5: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
if (array_key_exists('servers', $config)) {
foreach ($config['servers'] as $id => $server) {
$container->setParameter('json_rpc.serializer.class', $server['serializer']);
$container->setParameter('json_rpc.reflection.class', $server['reflection']);
$definition = new DefinitionDecorator('json_rpc.server');
$definition->addTag('json_rpc.servers', array('resource' => $id));
foreach ($server['services'] as $service) {
$definition->addMethodCall('addService', array($service['namespace'], $service['class']));
}
$container->setDefinition(sprintf('json_rpc.server.%s', $id), $definition);
$definition = new DefinitionDecorator('json_rpc.transport.internal');
$definition->addTag('json_rpc.transports');
$definition->replaceArgument(0, new Reference(sprintf('json_rpc.server.%s', $id)));
$container->setDefinition(sprintf('json_rpc.transport.internal.%s', $id), $definition);
$definition = new DefinitionDecorator('json_rpc.client.internal');
$definition->addTag('json_rpc.clients.internal');
$definition->replaceArgument(0, new Reference(sprintf('json_rpc.transport.internal.%s', $id)));
$container->setDefinition(sprintf('json_rpc.client.internal.%s', $id), $definition);
}
}
}
示例6: process
/**
* @inheritdoc
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('qimnet.crud.configuration.repository')) {
return;
}
$repository = $container->getDefinition('qimnet.crud.configuration.repository');
$defaults = $container->getParameter('qimnet.crud.defaults');
foreach ($container->getParameter('qimnet.crud.services') as $name => $configuration) {
$options = $configuration['options'] + array('name' => $name) + $defaults['options'];
$configuration = $configuration + $defaults;
$serviceId = 'qimnet.crud.configuration.' . strtolower($name);
$definition = new DefinitionDecorator('qimnet.crud.configuration');
foreach (array('object_manager_factory', 'security_context_factory', 'path_generator_factory') as $index => $key) {
if ($configuration[$key]) {
$definition->replaceArgument($index, new Reference($configuration[$key]));
}
}
$definition->addArgument($options);
if ($configuration['class']) {
$definition->setClass($configuration['class']);
}
$definition->addTag('qimnet.crud.configuration', array('alias' => $name, 'object_class' => $options['object_class'], 'worker' => $configuration['worker'], 'redirection_manager' => $configuration['redirection_manager']));
$container->setDefinition($serviceId, $definition);
}
$taggedServices = $container->findTaggedServiceIds('qimnet.crud.configuration');
foreach ($taggedServices as $id => $attributes) {
$repository->addMethodCall('add', array($attributes[0]['alias'], $attributes[0]['object_class'], $id, $attributes[0]['worker'], $attributes[0]['redirection_manager']));
}
}
示例7: create
/**
* {@inheritDoc}
*/
public function create(ContainerBuilder $container, $loaderName, array $config)
{
$loaderDefinition = new DefinitionDecorator('liip_imagine.binary.loader.prototype.filesystem');
$loaderDefinition->replaceArgument(2, $config['data_root']);
$loaderDefinition->addTag('liip_imagine.binary.loader', array('loader' => $loaderName));
$loaderId = 'liip_imagine.binary.loader.' . $loaderName;
$container->setDefinition($loaderId, $loaderDefinition);
return $loaderId;
}
示例8: create
/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $resolverName, array $config)
{
$resolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.web_path');
$resolverDefinition->replaceArgument(2, $config['web_root']);
$resolverDefinition->replaceArgument(3, $config['cache_prefix']);
$resolverDefinition->addTag('liip_imagine.cache.resolver', array('resolver' => $resolverName));
$resolverId = 'liip_imagine.cache.resolver.' . $resolverName;
$container->setDefinition($resolverId, $resolverDefinition);
return $resolverId;
}
示例9: create
/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $resolverName, array $config)
{
$resolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.flysystem');
$resolverDefinition->replaceArgument(0, new Reference($config['filesystem_service']));
$resolverDefinition->replaceArgument(2, $config['root_url']);
$resolverDefinition->replaceArgument(3, $config['cache_prefix']);
$resolverDefinition->addTag('liip_imagine.cache.resolver', array('resolver' => $resolverName));
$resolverId = 'liip_imagine.cache.resolver.' . $resolverName;
$container->setDefinition($resolverId, $resolverDefinition);
return $resolverId;
}
示例10: testThrowsExceptionWhenCachePoolTagHasUnknownAttributes
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid "cache.pool" tag for service "app.cache_pool": accepted attributes are
*/
public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
{
$container = new ContainerBuilder();
$adapter = new Definition();
$adapter->setAbstract(true);
$adapter->addTag('cache.pool');
$container->setDefinition('app.cache_adapter', $adapter);
$cachePool = new DefinitionDecorator('app.cache_adapter');
$cachePool->addTag('cache.pool', array('foobar' => 123));
$container->setDefinition('app.cache_pool', $cachePool);
$this->cachePoolPass->process($container);
}
示例11: create
/**
* {@inheritDoc}
*/
public function create(ContainerBuilder $container, $loaderName, array $config)
{
$loaderDefinition = new DefinitionDecorator('liip_imagine.binary.loader.prototype.stream');
$loaderDefinition->replaceArgument(0, $config['wrapper']);
$loaderDefinition->replaceArgument(1, $config['context']);
$loaderDefinition->addTag('liip_imagine.binary.loader', array(
'loader' => $loaderName,
));
$loaderId = 'liip_imagine.binary.loader.'.$loaderName;
$container->setDefinition($loaderId, $loaderDefinition);
return $loaderId;
}
示例12: testThrowsExceptionWhenCachePoolTagHasUnknownAttributes
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid "cache.pool" tag for service "app.cache_pool": accepted attributes are
*/
public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.name', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.root_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
$adapter->addTag('cache.pool');
$container->setDefinition('app.cache_adapter', $adapter);
$cachePool = new DefinitionDecorator('app.cache_adapter');
$cachePool->addTag('cache.pool', array('foobar' => 123));
$container->setDefinition('app.cache_pool', $cachePool);
$this->cachePoolPass->process($container);
}
示例13: loadInternal
/**
* {@inheritdoc}
*/
protected function loadInternal(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('controller.xml');
foreach ($configs['filters'] as $name => $settings) {
if (!$settings['enabled']) {
continue;
}
$loader->load('filters/' . $name . '.xml');
foreach ($settings['apply_to'] as $i => $pattern) {
$worker = new DefinitionDecorator('assetic.worker.ensure_filter');
$worker->replaceArgument(0, '/' . $pattern . '/');
$worker->replaceArgument(1, new Reference('assetic.filter.' . $name));
$worker->addTag('assetic.factory_worker');
$container->setDefinition('assetic.filter.' . $name . '.worker' . $i, $worker);
}
}
}
示例14: configureConnectionClient
private function configureConnectionClient(ContainerBuilder $builder, $connectionName, array $connectionConfig, $profiling)
{
$connectionDef = new DefinitionDecorator('kassko_cassandra.connection.prototype');
$connectionDef->addTag('kassko_cassandra.connection');
//logger Cql creation.
$loggerCqlServiceName = $this->computeLoggerCqlServiceName($connectionName);
$loggerCqlServiceDef = new DefinitionDecorator('kassko_cassandra.logger_cql.prototype');
if (isset($connectionConfig['logger_service'])) {
$loggerCqlServiceDef->replaceArgument(0, new Reference($connectionConfig['logger_service']));
}
$builder->setDefinition($loggerCqlServiceName, $loggerCqlServiceDef);
//loggerChain creation.
$loggerChainServiceName = $this->computeLoggerChainServiceName($connectionName);
$loggerChainDef = new DefinitionDecorator('kassko_cassandra.logger_chain.prototype');
$builder->setDefinition($loggerChainServiceName, $loggerChainDef);
$loggerChainDef->addMethodCall('addLogger', [new Reference($loggerCqlServiceName)]);
if ($profiling) {
$loggerProfilerServiceName = $this->computeLoggerProfilerServiceName($connectionName);
$builder->setDefinition($loggerProfilerServiceName, new DefinitionDecorator('kassko_cassandra.logger_profiler.prototype'));
$loggerChainDef->addMethodCall('addLogger', [new Reference($loggerProfilerServiceName)]);
$queryStatsManagerDef = $builder->getDefinition('kassko_cassandra.query_stats.manager');
$queryStatsManagerDef->addMethodCall('addLogger', [$connectionName, new Reference($loggerProfilerServiceName)]);
}
if (isset($connectionConfig['event_dispatcher_service'])) {
$connectionDef->addMethodCall('setEventDispatcher', [new Reference($connectionConfig['event_dispatcher_service'])]);
}
$connectionDef->addMethodCall('setLogger', [new Reference($loggerChainServiceName)]);
$connectionDef->addMethodCall('useKeyspace', [$connectionConfig['keyspace']]);
list($dsn, $username, $password) = $this->resolveConnectionParam($connectionConfig);
if (null === $username xor null === $password) {
throw new \LogicException(sprintf('username and password should be provided both or neither for keyspace "%s".', $connectionConfig['keyspace']));
}
if (null !== $username) {
$connectionDef->setArguments([$dsn, $username, $password]);
} else {
$connectionDef->setArguments([$dsn]);
}
$serviceName = $this->computeServiceName($connectionName);
$builder->setDefinition($serviceName, $connectionDef);
if (isset($connectionConfig['alias'])) {
$builder->setAlias($connectionConfig['alias'], $serviceName);
}
}
示例15: load
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
foreach ($config as $key => $stateMachineConfig) {
$stateMachineConfig = $this->removeDisabledCallbacks($stateMachineConfig);
$definition = new DefinitionDecorator('bangpound_finite.container_loader');
$definition->replaceArgument(0, $stateMachineConfig);
$definition->addTag('bangpound_finite.loader');
// setLazy method wasn't available before 2.3, FiniteBundle requirement is ~2.1
if (method_exists($definition, 'setLazy')) {
$definition->setLazy(true);
}
$serviceId = 'bangpound_finite.loader.' . $key;
$container->setDefinition($serviceId, $definition);
}
}