Symfony\Component\DependencyInjection\ContainerBuilder::findTaggedServiceIds PHP Method

findTaggedServiceIds() public method

Example: $container->register('foo')->addTag('my.tag', array('hello' => 'world')); $serviceIds = $container->findTaggedServiceIds('my.tag'); foreach ($serviceIds as $serviceId => $tags) { foreach ($tags as $tag) { echo $tag['hello']; } }
public findTaggedServiceIds ( string $name ) : array
$name string The tag name
return array An array of tags with the tagged service as key, holding a list of attribute arrays
    public function findTaggedServiceIds($name)
    {
        $this->usedTags[] = $name;
        $tags = array();
        foreach ($this->getDefinitions() as $id => $definition) {
            if ($definition->hasTag($name)) {
                $tags[$id] = $definition->getTag($name);
            }
        }

        return $tags;
    }

Usage Example

Example #1
0
 /**
  * Register Drupal drivers.
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition('drupal.drupal')) {
         return;
     }
     $drupalDefinition = $container->getDefinition('drupal.drupal');
     foreach ($container->findTaggedServiceIds('drupal.driver') as $id => $attributes) {
         foreach ($attributes as $attribute) {
             if (isset($attribute['alias']) && ($name = $attribute['alias'])) {
                 $drupalDefinition->addMethodCall('registerDriver', array($name, new Reference($id)));
             }
         }
         // If this is Drupal Driver, then a core controller needs to be
         // instantiated as well.
         if ('drupal.driver.drupal' === $id) {
             $drupalDriverDefinition = $container->getDefinition($id);
             $availableCores = array();
             foreach ($container->findTaggedServiceIds('drupal.core') as $coreId => $coreAttributes) {
                 foreach ($coreAttributes as $attribute) {
                     if (isset($attribute['alias']) && ($name = $attribute['alias'])) {
                         $availableCores[$name] = $container->getDefinition($coreId);
                     }
                 }
             }
             $drupalDriverDefinition->addMethodCall('setCore', array($availableCores));
         }
     }
     $drupalDefinition->addMethodCall('setDefaultDriverName', array($container->getParameter('drupal.drupal.default_driver')));
 }
All Usage Examples Of Symfony\Component\DependencyInjection\ContainerBuilder::findTaggedServiceIds