addTag example

class CoreServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {

  /** * {@inheritdoc} */
  public function register(ContainerBuilder $container) {
    $this->registerTest($container);

    // Only register the private file stream wrapper if a file path has been set.     if (Settings::get('file_private_path')) {
      $container->register('stream_wrapper.private', 'Drupal\Core\StreamWrapper\PrivateStream')
        ->addTag('stream_wrapper', ['scheme' => 'private']);
    }

    // Add the compiler pass that lets service providers modify existing     // service definitions. This pass must come first so that later     // list-building passes are operating on the post-alter services list.     $container->addCompilerPass(new ModifyServiceDefinitionsPass());

    $container->addCompilerPass(new DevelopmentSettingsPass());

    $container->addCompilerPass(new ProxyServicesPass());

    
/** * @covers ::process */
  public function testEncoders() {
    $container = new ContainerBuilder();
    $definition = new Definition(Serializer::class[[][]]);
    $definition->setPublic(TRUE);
    $container->setDefinition('serializer', $definition);

    $definition = new Definition('TestClass');
    $definition->addTag('authentication_provider', ['provider_id' => 'bunny_auth']);
    $definition->addTag('_provider', ['provider' => 'test_provider_a']);
    $definition->setPublic(TRUE);
    $container->setDefinition('test_provider_a.authentication.bunny_auth', $definition);

    $definition = new Definition('TestClass');
    $definition->addTag('authentication_provider', ['provider_id' => 'llama_auth', 'priority' => 100]);
    $definition->addTag('_provider', ['provider' => 'test_provider_a']);
    $definition->setPublic(TRUE);
    $container->setDefinition('test_provider_a.authentication.llama_auth', $definition);

    $definition = new Definition('TestClass');
    

    public function testProcess(string $namespace, array $services, string $expectedRegexp)
    {
        $container = new ContainerBuilder();
        $container->setParameter('validator.auto_mapping', [
            'App\\' => ['services' => []],
            $namespace => ['services' => $services],
        ]);

        $container->register('validator.builder', ValidatorBuilder::class);
        foreach ($services as $service) {
            $container->register($service)->addTag('validator.auto_mapper');
        }

        (new AddAutoMappingConfigurationPass())->process($container);

        foreach ($services as $service) {
            $this->assertSame($expectedRegexp$container->getDefinition($service)->getArgument('$classValidatorRegexp'));
        }
        $this->assertCount(\count($services)$container->getDefinition('validator.builder')->getMethodCalls());
    }

    public static function mappingProvider(): array
    {

  protected function createMiddlewareServiceDefinition($tag = TRUE, $priority = 0) {
    $definition = new Definition('Symfony\Component\HttpKernel\HttpKernelInterface', ['test']);
    $definition->setPublic(TRUE);

    if ($tag) {
      $definition->addTag('http_middleware', ['priority' => $priority]);
    }

    return $definition;
  }

}
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;

class AddValidatorInitializersPassTest extends TestCase
{
    public function testProcess()
    {
        $container = new ContainerBuilder();
        $container
            ->register('initializer1')
            ->addTag('validator.initializer')
        ;
        $container
            ->register('initializer2')
            ->addTag('validator.initializer')
        ;
        $container
            ->register('validator.builder')
            ->addArgument([])
        ;

        (new AddValidatorInitializersPass())->process($container);

        
throw new \RuntimeException(sprintf(
                    'Can not find increment gateway for configured type %s of pool %s, expected service id %s can not be found',
                    $type,
                    $pool,
                    $active,
                ));
            }

            $definition = $container->getDefinition($active);

            if (!$definition->hasTag($tag)) {
                $definition->addTag($tag);
            }

            $class = $definition->getClass();

            if ($class === null || !is_subclass_of($class, AbstractIncrementer::class)) {
                throw new \RuntimeException(sprintf(
                    'Increment gateway with id %s, expected service instance of %s',
                    $active,
                    AbstractIncrementer::class
                D);
            }

            
class PropertyInfoPassTest extends TestCase
{
    /** * @dataProvider provideTags */
    public function testServicesAreOrderedAccordingToPriority($index$tag)
    {
        $container = new ContainerBuilder();

        $definition = $container->register('property_info')->setArguments([null, null, null, null, null]);
        $container->register('n2')->addTag($tag['priority' => 100]);
        $container->register('n1')->addTag($tag['priority' => 200]);
        $container->register('n3')->addTag($tag);

        $propertyInfoPass = new PropertyInfoPass();
        $propertyInfoPass->process($container);

        $expected = new IteratorArgument([
            new Reference('n1'),
            new Reference('n2'),
            new Reference('n3'),
        ]);
        

        $container = new ContainerBuilder();
        $container->setParameter('translator.logging', true);
        $container->setParameter('translator.class', Translator::class);
        $container->register('monolog.logger');
        $container->setAlias('logger', 'monolog.logger');
        $container->register('translator.default', '%translator.class%');
        $container->register('translator.logging', '%translator.class%');
        $container->setAlias('translator', 'translator.default');
        $translationWarmerDefinition = $container->register('translation.warmer')
            ->addArgument(new Reference('translator'))
            ->addTag('container.service_subscriber', ['id' => 'translator'])
            ->addTag('container.service_subscriber', ['id' => 'foo']);

        $pass = new LoggingTranslatorPass();
        $pass->process($container);

        $this->assertEquals(
            ['container.service_subscriber' => [
                ['id' => 'foo'],
                ['key' => 'translator', 'id' => 'translator.logging.inner'],
            ]],
            $translationWarmerDefinition->getTags()
        );
if (isset($service['shared'])) {
            $definition->setShared($service['shared']);
        }

        if (isset($service['synthetic'])) {
            $definition->setSynthetic($service['synthetic']);
        }

        if (isset($service['lazy'])) {
            $definition->setLazy((bool) $service['lazy']);
            if (\is_string($service['lazy'])) {
                $definition->addTag('proxy', ['interface' => $service['lazy']]);
            }
        }

        if (isset($service['public'])) {
            $definition->setPublic($service['public']);
        }

        if (isset($service['abstract'])) {
            $definition->setAbstract($service['abstract']);
        }

        
return;
        }

        static $attributes = [];

        if (null !== $source && !isset($attributes[$source])) {
            $attributes[$source] = ['source' => sprintf('in "%s/%s"', basename(\dirname($source))basename($source))];
        }

        $this->container->register($class$class)
            ->setAbstract(true)
            ->addTag('container.excluded', null !== $source ? $attributes[$source] : []);
    }
}
/** @var array<string, array> $types */
        $types = $container->getParameter('shopware.bundle.content_type.types');

        foreach ($types as $name => $type) {
            $backendController = new Definition(ContentType::class);
            $backendController->setArguments([
                new Reference(\Shopware\Bundle\ContentTypeBundle\Services\ExtjsBuilderInterface::class),
                new Expression('service("Shopware\\\\Bundle\\\\ContentTypeBundle\\\\Services\\\\TypeProvider").getType("' . $name . '")'),
                new Reference('shopware.bundle.content_type.' . $name),
            ]);

            $backendController->addTag(
                'shopware.controller',
                [
                    'controller' => 'Custom' . ucfirst($name),
                    'module' => 'backend',
                ]
            );
            $backendController->setPublic(true);

            $container->setDefinition('shopware_bundle.content_type.controllers.backend.' . $name$backendController);

            $apiController = new Definition(\Shopware\Bundle\ContentTypeBundle\Controller\Api\ContentType::class);
            

            if ($definition->isPublic()) {
                continue;
            }
            // Remove private definition and schedule for replacement             $definition->setPublic($target->isPublic());
            $container->setDefinition($definitionId$definition);
            $container->removeDefinition($targetId);
            $replacements[$targetId] = $definitionId;

            if ($target->isPublic() && $target->isDeprecated()) {
                $definition->addTag('container.private', $target->getDeprecation('%service_id%'));
            }
        }
        $this->replacements = $replacements;

        parent::process($container);
        $this->replacements = [];
    }

    protected function processValue(mixed $value, bool $isRoot = false): mixed
    {
        if ($value instanceof Reference && isset($this->replacements[$referenceId = (string) $value])) {
            
class RegisterControllerArgumentLocatorsPassTest extends TestCase
{
    public function testInvalidClass()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Class "Symfony\Component\HttpKernel\Tests\DependencyInjection\NotFound" used for service "foo" cannot be found.');
        $container = new ContainerBuilder();
        $container->register('argument_resolver.service')->addArgument([]);

        $container->register('foo', NotFound::class)
            ->addTag('controller.service_arguments')
        ;

        $pass = new RegisterControllerArgumentLocatorsPass();
        $pass->process($container);
    }

    public function testNoAction()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Missing "action" attribute on tag "controller.service_arguments" {"argument":"bar"} for service "foo".');
        $container = new ContainerBuilder();
        
use Symfony\Component\HttpKernel\Tests\Fixtures\ClearableService;
use Symfony\Component\HttpKernel\Tests\Fixtures\MultiResettableService;
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;

class ResettableServicePassTest extends TestCase
{
    public function testCompilerPass()
    {
        $container = new ContainerBuilder();
        $container->register('one', ResettableService::class)
            ->setPublic(true)
            ->addTag('kernel.reset', ['method' => 'reset']);
        $container->register('two', ClearableService::class)
            ->setPublic(true)
            ->addTag('kernel.reset', ['method' => 'clear']);
        $container->register('three', MultiResettableService::class)
            ->setPublic(true)
            ->addTag('kernel.reset', ['method' => 'resetFirst'])
            ->addTag('kernel.reset', ['method' => 'resetSecond']);

        $container->register('services_resetter', ServicesResetter::class)
            ->setPublic(true)
            ->setArguments([null, []]);
        
require_once __DIR__.'/../Fixtures/includes/classes.php';

class RegisterServiceSubscribersPassTest extends TestCase
{
    public function testInvalidClass()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Service "foo" must implement interface "Symfony\Contracts\Service\ServiceSubscriberInterface".');
        $container = new ContainerBuilder();

        $container->register('foo', CustomDefinition::class)
            ->addTag('container.service_subscriber')
        ;

        (new RegisterServiceSubscribersPass())->process($container);
        (new ResolveServiceSubscribersPass())->process($container);
    }

    public function testInvalidAttributes()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The "container.service_subscriber" tag accepts only the "key" and "id" attributes, "bar" given for service "foo".');
        $container = new ContainerBuilder();

        
Home | Imprint | This part of the site doesn't use cookies.