addDefinitions example

array $listeners,
        array $remove,
        array $expected
    ): void {
        $builder = new ContainerBuilder();

        $definition = new Definition('class-string');
        foreach ($listeners as $listener) {
            $definition->addTag('kernel.event_listener', $listener);
        }

        $builder->addDefinitions(['class-string' => $definition]);

        RemoveEventListener::remove($builder, 'class-string', [$remove]);

        if ($expected === []) {
            static::assertFalse($definition->hasTag('kernel.event_listener'));

            return;
        }

        static::assertTrue($definition->hasTag('kernel.event_listener'));

        
foreach ($handlersByBusAndMessage as $bus => $handlersByMessage) {
            foreach ($handlersByMessage as $message => $handlers) {
                $handlerDescriptors = [];
                foreach ($handlers as $handler) {
                    $definitions[$definitionId = '.messenger.handler_descriptor.'.ContainerBuilder::hash($bus.':'.$message.':'.$handler[0])] = (new Definition(HandlerDescriptor::class))->setArguments([new Reference($handler[0])$handler[1]]);
                    $handlerDescriptors[] = new Reference($definitionId);
                }

                $handlersLocatorMappingByBus[$bus][$message] = new IteratorArgument($handlerDescriptors);
            }
        }
        $container->addDefinitions($definitions);

        foreach ($busIds as $bus) {
            $container->register($locatorId = $bus.'.messenger.handlers_locator', HandlersLocator::class)
                ->setArgument(0, $handlersLocatorMappingByBus[$bus] ?? [])
            ;
            if ($container->has($handleMessageId = $bus.'.middleware.handle_message')) {
                $container->getDefinition($handleMessageId)
                    ->replaceArgument(0, new Reference($locatorId))
                ;
            }
        }

        


            if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
                // don't keep track of env vars that are *overridden* when configs are merged                 $resolvingBag->freezeAfterProcessing($extension$tmpContainer);
            }

            $container->merge($tmpContainer);
            $container->getParameterBag()->add($parameters);
        }

        $container->addDefinitions($definitions);
        $container->addAliases($aliases);
    }
}

/** * @internal */
class MergeExtensionConfigurationParameterBag extends EnvPlaceholderParameterBag
{
    private array $processedEnvPlaceholders;

    
/** * Sets the service definitions. * * @param array<string, Definition> $definitions * * @return void */
    public function setDefinitions(array $definitions)
    {
        $this->definitions = [];
        $this->addDefinitions($definitions);
    }

    /** * Gets all service definitions. * * @return array<string, Definition> */
    public function getDefinitions(): array
    {
        return $this->definitions;
    }

    
'bar' => new Definition('BarClass'),
        ];
        $builder->setDefinitions($definitions);
        $this->assertEquals($definitions$builder->getDefinitions(), '->setDefinitions() sets the service definitions');
        $this->assertTrue($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
        $this->assertFalse($builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');

        $builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
        $this->assertEquals($foo$builder->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
        $this->assertSame($builder->setDefinition('foobar', $foo = new Definition('FooBarClass'))$foo, '->setDefinition() implements a fluid interface by returning the service reference');

        $builder->addDefinitions($defs = ['foobar' => new Definition('FooBarClass')]);
        $this->assertEquals(array_merge($definitions$defs)$builder->getDefinitions(), '->addDefinitions() adds the service definitions');

        try {
            $builder->getDefinition('baz');
            $this->fail('->getDefinition() throws a ServiceNotFoundException if the service definition does not exist');
        } catch (ServiceNotFoundException $e) {
            $this->assertEquals('You have requested a non-existent service "baz".', $e->getMessage(), '->getDefinition() throws a ServiceNotFoundException if the service definition does not exist');
        }
    }

    /** * The test should be kept in the group as it always expects a deprecation. * * @group legacy */
/** * Sets the service definitions. * * @param array<string, Definition> $definitions * * @return void */
    public function setDefinitions(array $definitions)
    {
        $this->definitions = [];
        $this->addDefinitions($definitions);
    }

    /** * Gets all service definitions. * * @return array<string, Definition> */
    public function getDefinitions(): array
    {
        return $this->definitions;
    }

    


            if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
                // don't keep track of env vars that are *overridden* when configs are merged                 $resolvingBag->freezeAfterProcessing($extension$tmpContainer);
            }

            $container->merge($tmpContainer);
            $container->getParameterBag()->add($parameters);
        }

        $container->addDefinitions($definitions);
        $container->addAliases($aliases);
    }
}

/** * @internal */
class MergeExtensionConfigurationParameterBag extends EnvPlaceholderParameterBag
{
    private array $processedEnvPlaceholders;

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