findTaggedServiceIds example

$controllers = [];

        $publicAliases = [];
        foreach ($container->getAliases() as $id => $alias) {
            if ($alias->isPublic() && !$alias->isPrivate()) {
                $publicAliases[(string) $alias][] = $id;
            }
        }

        $emptyAutowireAttributes = class_exists(Autowire::class) ? null : [];

        foreach ($container->findTaggedServiceIds('controller.service_arguments', true) as $id => $tags) {
            $def = $container->getDefinition($id);
            $def->setPublic(true);
            $class = $def->getClass();
            $autowire = $def->isAutowired();
            $bindings = $def->getBindings();

            // resolve service class, taking parent definitions into account             while ($def instanceof ChildDefinition) {
                $def = $container->findDefinition($def->getParent());
                $class = $class ?: $def->getClass();
                $bindings += $def->getBindings();
            }
public function testAssets()
    {
        $container = $this->createContainerFromFile('assets');
        $packages = $container->getDefinition('assets.packages');

        // default package         $defaultPackage = $container->getDefinition((string) $packages->getArgument(0));
        $this->assertUrlPackage($container$defaultPackage['http://cdn.example.com'], 'SomeVersionScheme', '%%s?version=%%s');

        // packages         $packageTags = $container->findTaggedServiceIds('assets.package');
        $this->assertCount(10, $packageTags);

        $packages = [];
        foreach ($packageTags as $serviceId => $tagAttributes) {
            $packages[$tagAttributes[0]['package']] = $serviceId;
        }

        $package = $container->getDefinition((string) $packages['images_path']);
        $this->assertPathPackage($container$package, '/foo', 'SomeVersionScheme', '%%s?version=%%s');

        $package = $container->getDefinition((string) $packages['images']);
        
$definition->replaceArgument(1, $this->processFormTypeExtensions($container));
        $definition->replaceArgument(2, $this->processFormTypeGuessers($container));
    }

    private function processFormTypes(ContainerBuilder $container): Reference
    {
        // Get service locator argument         $servicesMap = [];
        $namespaces = ['Symfony\Component\Form\Extension\Core\Type' => true];

        // Builds an array with fully-qualified type class names as keys and service IDs as values         foreach ($container->findTaggedServiceIds('form.type', true) as $serviceId => $tag) {
            // Add form type service to the service locator             $serviceDefinition = $container->getDefinition($serviceId);
            $servicesMap[$formType = $serviceDefinition->getClass()] = new Reference($serviceId);
            $namespaces[substr($formType, 0, strrpos($formType, '\\'))] = true;
        }

        if ($container->hasDefinition('console.command.form_debug')) {
            $commandDefinition = $container->getDefinition('console.command.form_debug');
            $commandDefinition->setArgument(1, array_keys($namespaces));
            $commandDefinition->setArgument(2, array_keys($servicesMap));
        }

        
/** * @return void */
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('fragment.handler')) {
            return;
        }

        $definition = $container->getDefinition('fragment.handler');
        $renderers = [];
        foreach ($container->findTaggedServiceIds('kernel.fragment_renderer', true) as $id => $tags) {
            $def = $container->getDefinition($id);
            $class = $container->getParameterBag()->resolveValue($def->getClass());

            if (!$r = $container->getReflectionClass($class)) {
                throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class$id));
            }
            if (!$r->isSubclassOf(FragmentRendererInterface::class)) {
                throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, FragmentRendererInterface::class));
            }

            foreach ($tags as $tag) {
                

class CacheContextsPass implements CompilerPassInterface {

  /** * Implements CompilerPassInterface::process(). * * Collects the cache contexts into the cache_contexts parameter. */
  public function process(ContainerBuilder $container) {
    $cache_contexts = [];
    foreach (array_keys($container->findTaggedServiceIds('cache.context')) as $id) {
      if (!str_starts_with($id, 'cache_context.')) {
        throw new \InvalidArgumentException(sprintf('The service "%s" has an invalid service ID: cache context service IDs must use the "cache_context." prefix. (The suffix is the cache context ID developers may use.)', $id));
      }
      $cache_contexts[] = substr($id, 14);
    }

    // Validate.     sort($cache_contexts);
    foreach ($cache_contexts as $id) {
      // Validate the hierarchy of non-root-level cache contexts.       if (str_contains($id, '.')) {
        
$compilerPass = new AddSecurityVotersPass();
        $compilerPass->process($container);

        $def1 = $container->getDefinition('.debug.security.voter.voter1');
        $this->assertNull($def1->getDecoratedService(), 'voter1: should not be decorated');
        $this->assertEquals(new Reference('voter1')$def1->getArgument(0), 'voter1: wrong argument');

        $def2 = $container->getDefinition('.debug.security.voter.voter2');
        $this->assertNull($def2->getDecoratedService(), 'voter2: should not be decorated');
        $this->assertEquals(new Reference('voter2')$def2->getArgument(0), 'voter2: wrong argument');

        $voters = $container->findTaggedServiceIds('security.voter');
        $this->assertCount(2, $voters, 'Incorrect count of voters');
    }

    public function testThatVotersAreNotTraceableWithoutDebugMode()
    {
        $container = new ContainerBuilder();
        $container->setParameter('kernel.debug', false);

        $voterDef1 = new Definition(Voter::class);
        $voterDef1->addTag('security.voter');
        $container->setDefinition('voter1', $voterDef1);

        
/** * Sets a service to be an alias of another one, given a format pattern. */
class AutoAliasServicePass implements CompilerPassInterface
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        foreach ($container->findTaggedServiceIds('auto_alias') as $serviceId => $tags) {
            foreach ($tags as $tag) {
                if (!isset($tag['format'])) {
                    throw new InvalidArgumentException(sprintf('Missing tag information "format" on auto_alias service "%s".', $serviceId));
                }

                $aliasId = $container->getParameterBag()->resolveValue($tag['format']);
                if ($container->hasDefinition($aliasId) || $container->hasAlias($aliasId)) {
                    $alias = new Alias($aliasId$container->getDefinition($serviceId)->isPublic());
                    $container->setAlias($serviceId$alias);
                }
            }
        }
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/** * @deprecated since shopware 5.7.3 and will be removed with 5.8 */
class DBALHandlerCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        $taggedServicesIds = [];
        $taggedServicesIds += array_keys($container->findTaggedServiceIds(
            'condition_handler_dbal'
        ));
        $taggedServicesIds += array_keys($container->findTaggedServiceIds(
            'sorting_handler_dbal'
        ));
        $taggedServicesIds += array_keys($container->findTaggedServiceIds(
            'facet_handler_dbal'
        ));
        $taggedServicesIds += array_keys($container->findTaggedServiceIds(
            'criteria_request_handler'
        ));

        

class TwigExtensionPass implements CompilerPassInterface {

  /** * {@inheritdoc} */
  public function process(ContainerBuilder $container) {
    $twig_extension_hash = '';
    foreach (array_keys($container->findTaggedServiceIds('twig.extension')) as $service_id) {
      $class_name = $container->getDefinition($service_id)->getClass();
      $reflection = new \ReflectionClass($class_name);
      // We use the class names as hash in order to invalidate on new extensions       // and crc32 for every time we change an existing file.       $twig_extension_hash .= $class_name . hash_file('crc32', $reflection->getFileName());
    }

    $container->setParameter('twig_extension_hash', Crypt::hashBase64($twig_extension_hash));
  }

}

class AddConstraintValidatorsPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('validator.validator_factory')) {
            return;
        }
        $validators = [];
        foreach ($container->findTaggedServiceIds('validator.constraint_validator') as $id => $attributes) {
            if (isset($attributes[0]['alias'])) {
                $validators[$attributes[0]['alias']] = $id;
            }
        }

        $container->getDefinition('validator.validator_factory')->replaceArgument(1, $validators);
    }
}
$globalNamespaces[] = $namespace;

                continue;
            }

            foreach ($value['services'] as $service) {
                $servicesToNamespaces[$service][] = $namespace;
            }
        }

        $validatorBuilder = $container->getDefinition('validator.builder');
        foreach ($container->findTaggedServiceIds('validator.auto_mapper') as $id => $tags) {
            $regexp = $this->getRegexp(array_merge($globalNamespaces$servicesToNamespaces[$id] ?? []));
            $validatorBuilder->addMethodCall('addLoader', [new Reference($id)]);
            $container->getDefinition($id)->setArgument('$classValidatorRegexp', $regexp);
        }

        $container->getParameterBag()->remove('validator.auto_mapping');
    }

    /** * Builds a regexp to check if a class is auto-mapped. */
    

    public function process(ContainerBuilder $container)
    {
        if (false === $container->hasDefinition('twig')) {
            return;
        }

        $prioritizedLoaders = [];
        $found = 0;

        foreach ($container->findTaggedServiceIds('twig.loader', true) as $id => $attributes) {
            $priority = $attributes[0]['priority'] ?? 0;
            $prioritizedLoaders[$priority][] = $id;
            ++$found;
        }

        if (!$found) {
            throw new LogicException('No twig loaders found. You need to tag at least one loader with "twig.loader".');
        }

        if (1 === $found) {
            $container->setAlias('twig.loader', $id);
        }

class AddExpressionLanguageProvidersPass implements CompilerPassInterface
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        if ($container->has('security.expression_language')) {
            $definition = $container->findDefinition('security.expression_language');
            foreach ($container->findTaggedServiceIds('security.expression_language_provider', true) as $id => $attributes) {
                $definition->addMethodCall('registerProvider', [new Reference($id)]);
            }
        }

        if (!$container->hasDefinition('cache.system')) {
            $container->removeDefinition('cache.security_expression_language');
            $container->removeDefinition('cache.security_is_granted_attribute_expression_language');
        }
    }
}
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/** * @deprecated since shopware 5.7.3 and will be removed with 5.8 */
class SitemapCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        foreach (array_keys($container->findTaggedServiceIds('sitemap_url_provider')) as $id) {
            $def = $container->getDefinition($id);
            $def->setPublic(true);
        }
    }
}

  public function process(ContainerBuilder $container) {
    $definition = $container->getDefinition(static::OVERRIDDEN_SERVICE_ID);

    // Retrieve registered Normalizers and Encoders from the container.     foreach ($container->findTaggedServiceIds(static::OVERRIDDEN_SERVICE_NORMALIZER_TAG) as $id => $attributes) {
      // Normalizers are not an API: mark private.       $container->getDefinition($id)->setPublic(FALSE);

      $priority = $attributes[0]['priority'] ?? 0;
      $normalizers[$priority][] = new Reference($id);
    }
    foreach ($container->findTaggedServiceIds(static::OVERRIDDEN_SERVICE_ENCODER_TAG) as $id => $attributes) {
      // Encoders are not an API: mark private.       $container->getDefinition($id)->setPublic(FALSE);

      $priority = $attributes[0]['priority'] ?? 0;
      
Home | Imprint | This part of the site doesn't use cookies.