AttributeAutoconfigurationPass example

private array $removingPasses;

    public function __construct()
    {
        $this->mergePass = new MergeExtensionConfigurationPass();

        $this->beforeOptimizationPasses = [
            100 => [
                new ResolveClassPass(),
                new RegisterAutoconfigureAttributesPass(),
                new AutowireAsDecoratorPass(),
                new AttributeAutoconfigurationPass(),
                new ResolveInstanceofConditionalsPass(),
                new RegisterEnvVarProcessorsPass(),
            ],
            -1000 => [new ExtensionCompilerPass()],
        ];

        $this->optimizationPasses = [[
            new AutoAliasServicePass(),
            new ValidateEnvPlaceholdersPass(),
            new ResolveDecoratorStackPass(),
            new ResolveChildDefinitionsPass(),
            
class AttributeAutoconfigurationPassTest extends TestCase
{
    public function testProcessAddsNoEmptyInstanceofConditionals()
    {
        $container = new ContainerBuilder();
        $container->registerAttributeForAutoconfiguration(AsTaggedItem::classstatic function D) {});
        $container->register('foo', \stdClass::class)
            ->setAutoconfigured(true)
        ;

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

        $this->assertSame([]$container->getDefinition('foo')->getInstanceofConditionals());
    }

    public function testAttributeConfiguratorCallableMissingType()
    {
        $container = new ContainerBuilder();
        $container->registerAttributeForAutoconfiguration(AsTaggedItem::classstatic function DChildDefinition $definition, AsTaggedItem $attribute$reflector) {});
        $container->register('foo', \stdClass::class)
            ->setAutoconfigured(true)
        ;

        


    public function testTaggedInvokableEventListener()
    {
        $container = new ContainerBuilder();
        $container->registerAttributeForAutoconfiguration(AsEventListener::classstatic function DChildDefinition $definition, AsEventListener $attribute): void {
            $definition->addTag('kernel.event_listener', get_object_vars($attribute));
        });
        $container->register('foo', TaggedInvokableListener::class)->setAutoconfigured(true);
        $container->register('event_dispatcher', \stdClass::class);

        (new AttributeAutoconfigurationPass())->process($container);
        (new ResolveInstanceofConditionalsPass())->process($container);
        (new RegisterListenersPass())->process($container);

        $definition = $container->getDefinition('event_dispatcher');
        $expectedCalls = [
            [
                'addListener',
                [
                    CustomEvent::class,
                    [new ServiceClosureArgument(new Reference('foo')), '__invoke'],
                    0,
                ],
private array $removingPasses;

    public function __construct()
    {
        $this->mergePass = new MergeExtensionConfigurationPass();

        $this->beforeOptimizationPasses = [
            100 => [
                new ResolveClassPass(),
                new RegisterAutoconfigureAttributesPass(),
                new AutowireAsDecoratorPass(),
                new AttributeAutoconfigurationPass(),
                new ResolveInstanceofConditionalsPass(),
                new RegisterEnvVarProcessorsPass(),
            ],
            -1000 => [new ExtensionCompilerPass()],
        ];

        $this->optimizationPasses = [[
            new AutoAliasServicePass(),
            new ValidateEnvPlaceholdersPass(),
            new ResolveDecoratorStackPass(),
            new ResolveChildDefinitionsPass(),
            

                $tagAttributes['method'] = $reflector->getName();
            }

            $definition->addTag('messenger.message_handler', $tagAttributes);
        });
        $container
            ->register(TaggedDummyHandler::class, TaggedDummyHandler::class)
            ->setAutoconfigured(true)
        ;

        (new AttributeAutoconfigurationPass())->process($container);
        (new ResolveInstanceofConditionalsPass())->process($container);
        (new MessengerPass())->process($container);

        $handlersLocatorDefinition = $container->getDefinition($busId.'.messenger.handlers_locator');
        $this->assertSame(HandlersLocator::class$handlersLocatorDefinition->getClass());

        $handlerDescriptionMapping = $handlersLocatorDefinition->getArgument(0);
        $this->assertCount(2, $handlerDescriptionMapping);

        $this->assertHandlerDescriptor($container$handlerDescriptionMapping, DummyMessage::class[TaggedDummyHandler::class][[]]);
        $this->assertHandlerDescriptor(
            
Home | Imprint | This part of the site doesn't use cookies.