hasParameter example


        $this->connectionsParameter = $connectionsParameter;
        $this->managerTemplate = $managerTemplate;
        $this->tagPrefix = $tagPrefix;
    }

    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasParameter($this->connectionsParameter)) {
            return;
        }

        $this->connections = $container->getParameter($this->connectionsParameter);
        $listenerRefs = $this->addTaggedServices($container);

        // replace service container argument of event managers with smaller service locator         // so services can even remain private         foreach ($listenerRefs as $connection => $refs) {
            $this->getEventManagerDef($container$connection)
                ->replaceArgument(0, ServiceLocatorTagPass::register($container$refs));
        }

        }
    }

    /** * Register tagged commands in Symfony style * * @see AddConsoleCommandPass */
    protected function registerTaggedServiceIds()
    {
        if ($this->kernel->getContainer()->hasParameter('console.command.ids')) {
            foreach ($this->kernel->getContainer()->getParameter('console.command.ids') as $id) {
                $this->add($this->kernel->getContainer()->get($id));
            }
        }
    }
}

class AddAutoMappingConfigurationPass implements CompilerPassInterface
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasParameter('validator.auto_mapping') || !$container->hasDefinition('validator.builder')) {
            return;
        }

        $config = $container->getParameter('validator.auto_mapping');

        $globalNamespaces = [];
        $servicesToNamespaces = [];
        foreach ($config as $namespace => $value) {
            if ([] === $value['services']) {
                $globalNamespaces[] = $namespace;

                

    protected static function getMethodCall1Service($container)
    {
        include_once '%path%foo.php';

        $container->services['method_call1'] = $instance = new \Bar\FooClass();

        $instance->setBar(($container->services['foo'] ?? self::getFooService($container)));
        $instance->setBar(NULL);
        $instance->setBar((($container->services['foo'] ?? self::getFooService($container))->foo() . (($container->hasParameter("foo")) ? ($container->getParameter("foo")) : ("default"))));

        return $instance;
    }

    /** * Gets the public 'new_factory_service' shared service. * * @return \FooBarBaz */
    protected static function getNewFactoryServiceService($container)
    {
        
$this->container = $container;
    }

    public function supports(ResourceInterface $metadata): bool
    {
        return $metadata instanceof ContainerParametersResource;
    }

    public function isFresh(ResourceInterface $resource, int $timestamp): bool
    {
        foreach ($resource->getParameters() as $key => $value) {
            if (!$this->container->hasParameter($key) || $this->container->getParameter($key) !== $value) {
                return false;
            }
        }

        return true;
    }
}
class AddEventAliasesPass implements CompilerPassInterface
{
    private array $eventAliases;

    public function __construct(array $eventAliases)
    {
        $this->eventAliases = $eventAliases;
    }

    public function process(ContainerBuilder $container): void
    {
        $eventAliases = $container->hasParameter('event_dispatcher.event_aliases') ? $container->getParameter('event_dispatcher.event_aliases') : [];

        $container->setParameter(
            'event_dispatcher.event_aliases',
            array_merge($eventAliases$this->eventAliases)
        );
    }
}
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Uid\AbstractUid;

final class RegisterUidTypePass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        if (!class_exists(AbstractUid::class)) {
            return;
        }

        if (!$container->hasParameter('doctrine.dbal.connection_factory.types')) {
            return;
        }

        $typeDefinition = $container->getParameter('doctrine.dbal.connection_factory.types');

        if (!isset($typeDefinition['uuid'])) {
            $typeDefinition['uuid'] = ['class' => UuidType::class];
        }

        if (!isset($typeDefinition['ulid'])) {
            $typeDefinition['ulid'] = ['class' => UlidType::class];
        }
return;
        }

        if (!$normalizers = $this->findAndSortTaggedServices('serializer.normalizer', $container)) {
            throw new RuntimeException('You must tag at least one service as "serializer.normalizer" to use the "serializer" service.');
        }

        if (!$encoders = $this->findAndSortTaggedServices('serializer.encoder', $container)) {
            throw new RuntimeException('You must tag at least one service as "serializer.encoder" to use the "serializer" service.');
        }

        if ($container->hasParameter('serializer.default_context')) {
            $defaultContext = $container->getParameter('serializer.default_context');
            foreach (array_merge($normalizers$encoders) as $service) {
                $definition = $container->getDefinition($service);
                $definition->setBindings(['array $defaultContext' => new BoundArgument($defaultContext, false)] + $definition->getBindings());
            }

            $container->getParameterBag()->remove('serializer.default_context');
        }

        if ($container->getParameter('kernel.debug') && $container->hasDefinition('serializer.data_collector')) {
            foreach ($normalizers as $i => $normalizer) {
                
'some_default'],
            $container->getDefinition($factoryWithDefaultChildMiddlewareId)->getArguments(),
            'parent default argument is used'
        );

        $this->assertEquals([
            new Reference(UselessMiddleware::class),
            new Reference($factoryChildMiddlewareArgs1Id),
            new Reference($factoryChildMiddlewareArgs2Id),
            new Reference($factoryWithDefaultChildMiddlewareId),
        ]$container->getDefinition($fooBusId)->getArgument(0)->getValues());
        $this->assertFalse($container->hasParameter($middlewareParameter));
    }

    public function testCannotRegistersAnUndefinedMiddleware()
    {
        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('Invalid middleware: service "not_defined_middleware" not found.');
        $container = $this->getContainerBuilder($fooBusId = 'messenger.bus.foo');
        $container->setParameter($middlewareParameter = $fooBusId.'.middleware', [
            ['id' => 'not_defined_middleware', 'arguments' => []],
        ]);

        (
continue;
                }
                // Resolve constraint validator FQCN even if defined as %foo.validator.class% parameter                 $className = $container->getParameterBag()->resolveValue($definition->getClass());
                // Extraction of the constraint class name from the Constraint Validator FQCN                 $constraintClassNames[] = str_replace('Validator', '', substr(strrchr($className, '\\'), 1));
            }

            $constraintVisitorDefinition->setArgument(0, $constraintClassNames);
        }

        if (!$container->hasParameter('twig.default_path')) {
            return;
        }

        $paths = array_keys($container->getDefinition('twig.template_iterator')->getArgument(1));
        if ($container->hasDefinition('console.command.translation_debug')) {
            $definition = $container->getDefinition('console.command.translation_debug');
            $definition->replaceArgument(4, $container->getParameter('twig.default_path'));

            if (\count($definition->getArguments()) > 6) {
                $definition->replaceArgument(6, $paths);
            }
        }

class AddAutoMappingConfigurationPass implements CompilerPassInterface
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasParameter('validator.auto_mapping') || !$container->hasDefinition('validator.builder')) {
            return;
        }

        $config = $container->getParameter('validator.auto_mapping');

        $globalNamespaces = [];
        $servicesToNamespaces = [];
        foreach ($config as $namespace => $value) {
            if ([] === $value['services']) {
                $globalNamespaces[] = $namespace;

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

        $this->assertEquals([
            'container.service_subscriber' => [0 => []],
            'kernel.reset' => [
                [
                    'method' => 'reset',
                ],
            ],
        ]$container->getDefinition('decorator')->getTags());
        $this->assertFalse($container->hasParameter('container.behavior_describing_tags'));
    }
}

class DecoratorWithBehavior implements ResetInterface, ResourceCheckerInterface, ServiceSubscriberInterface
{
    public function reset(): void
    {
    }

    public function supports(ResourceInterface $metadata): bool
    {
    }
/** * Determine the manager name. * * The default implementation loops over the managerParameters and returns * the first non-empty parameter. * * @throws InvalidArgumentException if none of the managerParameters is found in the container */
    private function getManagerName(ContainerBuilder $container): string
    {
        foreach ($this->managerParameters as $param) {
            if ($container->hasParameter($param)) {
                $name = $container->getParameter($param);
                if ($name) {
                    return $name;
                }
            }
        }

        throw new InvalidArgumentException(sprintf('Could not find the manager name parameter in the container. Tried the following parameter names: "%s".', implode('", "', $this->managerParameters)));
    }

    /** * Determine whether this mapping should be activated or not. This allows * to take this decision with the container builder available. * * This default implementation checks if the class has the enabledParameter * configured and if so if that parameter is present in the container. */
$alias = 'console.command.public_alias.my-command';

        if ($public) {
            $this->assertFalse($container->hasAlias($alias));
        } else {
            // The alias is replaced by a Definition by the ReplaceAliasByActualDefinitionPass             // in case the original service is private             $this->assertFalse($container->hasDefinition($id));
            $this->assertTrue($container->hasDefinition($alias));
        }

        $this->assertTrue($container->hasParameter('console.command.ids'));
        $this->assertSame([$public ? $id : $alias]$container->getParameter('console.command.ids'));
    }

    public function testProcessRegistersLazyCommands()
    {
        $container = new ContainerBuilder();
        $command = $container
            ->register('my-command', MyCommand::class)
            ->addTag('console.command', ['command' => 'my:command'])
            ->addTag('console.command', ['command' => 'my:alias'])
        ;

        (
/** * @return void */
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('event_dispatcher') && !$container->hasAlias('event_dispatcher')) {
            return;
        }

        $aliases = [];

        if ($container->hasParameter('event_dispatcher.event_aliases')) {
            $aliases = $container->getParameter('event_dispatcher.event_aliases');
        }

        $globalDispatcherDefinition = $container->findDefinition('event_dispatcher');

        foreach ($container->findTaggedServiceIds('kernel.event_listener', true) as $id => $events) {
            $noPreload = 0;

            foreach ($events as $event) {
                $priority = $event['priority'] ?? 0;

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