hasDefinition example

public static function register(ContainerBuilder $container, array $map, string $callerId = null): Reference
    {
        foreach ($map as $k => $v) {
            $map[$k] = new ServiceClosureArgument($v);
        }

        $locator = (new Definition(ServiceLocator::class))
            ->addArgument($map)
            ->addTag('container.service_locator');

        if (null !== $callerId && $container->hasDefinition($callerId)) {
            $locator->setBindings($container->getDefinition($callerId)->getBindings());
        }

        if (!$container->hasDefinition($id = '.service_locator.'.ContainerBuilder::hash($locator))) {
            $container->setDefinition($id$locator);
        }

        if (null !== $callerId) {
            $locatorId = $id;
            // Locators are shared when they hold the exact same list of factories;             // to have them specialized per consumer service, we use a cloning factory
foreach ($container->getDefinitions() as $id => $definition) {
                if ($definition->isPublic()) {
                    $connectedIds[$id] = true;
                    $this->processValue($definition);
                }
            }

            while ($this->connectedIds) {
                $ids = $this->connectedIds;
                $this->connectedIds = [];
                foreach ($ids as $id) {
                    if (!isset($connectedIds[$id]) && $container->hasDefinition($id)) {
                        $connectedIds[$id] = true;
                        $this->processValue($container->getDefinition($id));
                    }
                }
            }

            foreach ($container->getDefinitions() as $id => $definition) {
                if (!isset($connectedIds[$id])) {
                    $container->removeDefinition($id);
                    $container->resolveEnvPlaceholders(!$definition->hasErrors() ? serialize($definition) : $definition);
                    $container->log($thissprintf('Removed service "%s"; reason: unused.', $id));
                }
/** * @author Johannes M. Schmitt <schmittjoh@gmail.com> * @author Robin Chalas <robin.chalas@gmail.com> */
class AddConstraintValidatorsPass implements CompilerPassInterface
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('validator.validator_factory')) {
            return;
        }

        $validators = [];
        foreach ($container->findTaggedServiceIds('validator.constraint_validator', true) as $id => $attributes) {
            $definition = $container->getDefinition($id);

            if (isset($attributes[0]['alias'])) {
                $validators[$attributes[0]['alias']] = new Reference($id);
            }

            

  public function setSearchManager(PluginManagerInterface $search_manager = NULL) {
    $this->searchManager = $search_manager;
  }

  /** * {@inheritdoc} */
  public function clearCachedDefinitions() {
    parent::clearCachedDefinitions();
    if ($this->searchManager && $this->searchManager->hasDefinition('help_search') && $this->moduleHandler->moduleExists('help_topics')) {
      // Rebuild the index on cache clear so that new help topics are indexed       // and any changes due to help topics edits or translation changes are       // picked up.       $help_search = $this->searchManager->createInstance('help_search');
      $help_search->markForReindex();
    }
  }

}
$container->register('shopware.increment.gateway.array', ArrayIncrementer::class)
            ->addArgument('');

        $container->register('shopware.increment.gateway.mysql', MySQLIncrementer::class)
            ->addArgument('')
            ->addArgument($this->getContainer()->get(Connection::class));

        $entityCompilerPass = new IncrementerGatewayCompilerPass();
        $entityCompilerPass->process($container);

        // user_activity pool is registered         static::assertNotNull($container->hasDefinition('shopware.increment.user_activity.gateway.mysql'));
        $definition = $container->getDefinition('shopware.increment.user_activity.gateway.mysql');
        static::assertEquals(MySQLIncrementer::class$definition->getClass());
        static::assertTrue($definition->hasTag('shopware.increment.gateway'));

        // message_queue pool is registered         static::assertNotNull($container->hasDefinition('shopware.increment.message_queue.redis_adapter'));
        static::assertNotNull($container->hasDefinition('shopware.increment.message_queue.gateway.redis'));
        $definition = $container->getDefinition('shopware.increment.message_queue.gateway.redis');
        static::assertEquals(RedisIncrementer::class$definition->getClass());
        static::assertTrue($definition->hasTag('shopware.increment.gateway'));

        

        $this->noPreloadEvents = array_flip($noPreloadEvents);

        return $this;
    }

    /** * @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');

        
$container
            ->register('bar')
        ;
        $container
            ->register('moo')
            ->setPublic(true)
            ->setArguments([new Reference('bar')])
        ;

        $this->process($container);

        $this->assertFalse($container->hasDefinition('foo'));
        $this->assertTrue($container->hasDefinition('bar'));
        $this->assertTrue($container->hasDefinition('moo'));
    }

    public function testProcessRemovesUnusedDefinitionsRecursively()
    {
        $container = new ContainerBuilder();
        $container
            ->register('foo')
        ;
        $container
            


        $managerLocator = $container->getDefinition('security.authenticator.managers_locator');
        $managerLocator->replaceArgument(0, array_merge($managerLocator->getArgument(0)[$id => new ServiceClosureArgument(new Reference($managerId))]));

        // authenticator manager listener         $container
            ->setDefinition('security.firewall.authenticator.'.$idnew ChildDefinition('security.firewall.authenticator'))
            ->replaceArgument(0, new Reference($managerId))
        ;

        if ($container->hasDefinition('debug.security.firewall')) {
            $container
                ->register('debug.security.firewall.authenticator.'.$id, TraceableAuthenticatorManagerListener::class)
                ->setDecoratedService('security.firewall.authenticator.'.$id)
                ->setArguments([new Reference('debug.security.firewall.authenticator.'.$id.'.inner')])
            ;
        }

        // user checker listener         $container
            ->setDefinition('security.listener.user_checker.'.$idnew ChildDefinition('security.listener.user_checker'))
            ->replaceArgument(0, new Reference('security.user_checker.'.$id))
            
$this->assertSame([]$migrations,
      "No node translation migrations without content_translation");
  }

  /** * Tests node translation migrations with translation enabled. */
  public function testTranslations() {
    // With content_translation, there should be translation migrations for     // each content type.     $this->enableModules(['language', 'content_translation']);
    $this->assertTrue($this->container->get('plugin.manager.migration')->hasDefinition('d6_node_translation:story'), "Node translation migrations exist after content_translation installed");
  }

}
public function process(ContainerBuilder $container)
    {
        $busIds = [];
        foreach ($container->findTaggedServiceIds('messenger.bus') as $busId => $tags) {
            $busIds[] = $busId;
            if ($container->hasParameter($busMiddlewareParameter = $busId.'.middleware')) {
                $this->registerBusMiddleware($container$busId$container->getParameter($busMiddlewareParameter));

                $container->getParameterBag()->remove($busMiddlewareParameter);
            }

            if ($container->hasDefinition('data_collector.messenger')) {
                $this->registerBusToCollector($container$busId);
            }
        }

        if ($container->hasDefinition('messenger.receiver_locator')) {
            $this->registerReceivers($container$busIds);
        }
        $this->registerHandlers($container$busIds);
    }

    private function registerHandlers(ContainerBuilder $container, array $busIds): void
    {
$this->assertEqualsCanonicalizing([
            'log_level' => null,
            'status_code' => 500,
        ]$configuration[\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class]);
    }

    public function testRateLimiter()
    {
        $container = $this->createContainerFromFile('rate_limiter');

        $this->assertTrue($container->hasDefinition('limiter.sliding_window'));
    }

    public function testAssetMapper()
    {
        $container = $this->createContainerFromFile('asset_mapper');

        $definition = $container->getDefinition('asset_mapper.public_assets_path_resolver');
        $this->assertSame('/assets_path/', $definition->getArgument(1));

        $definition = $container->getDefinition('asset_mapper.dev_server_subscriber');
        $this->assertSame(['zip' => 'application/zip']$definition->getArgument(2));

        
$twigFilesystemLoaderDefinition->addMethodCall('addPath', [$path]);
            } else {
                $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$path$namespace]);
            }
        }

        // paths are modified in ExtensionPass if forms are enabled         $container->getDefinition('twig.template_iterator')->replaceArgument(1, $config['paths']);

        $container->getDefinition('twig.template_iterator')->replaceArgument(3, $config['file_name_pattern']);

        if ($container->hasDefinition('twig.command.lint')) {
            $container->getDefinition('twig.command.lint')->replaceArgument(1, $config['file_name_pattern'] ?: ['*.twig']);
        }

        foreach ($this->getBundleTemplatePaths($container$config) as $name => $paths) {
            $namespace = $this->normalizeBundleName($name);
            foreach ($paths as $path) {
                $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$path$namespace]);
            }

            if ($paths) {
                // the last path must be the bundle views directory
$extension2 = new DummyExtension('extension2');
        $extension3 = new DummyExtension('extension3');
        $extension4 = new CompilerPassExtension('extension4');

        $this->container->registerExtension($extension1);
        $this->container->registerExtension($extension2);
        $this->container->registerExtension($extension3);
        $this->container->registerExtension($extension4);

        $this->pass->process($this->container);

        $this->assertTrue($this->container->hasDefinition('extension1'));
        $this->assertFalse($this->container->hasDefinition('extension2'));
        $this->assertFalse($this->container->hasDefinition('extension3'));
        $this->assertTrue($this->container->hasDefinition('extension4'));
    }
}

class DummyExtension extends Extension
{
    public function __construct(private readonly string $alias)
    {
    }

    
public function testListenerUnregisteredWhenNoLocaleAwareServices()
    {
        $container = new ContainerBuilder();

        $container->register('locale_aware_listener', LocaleAwareListener::class)
                  ->setPublic(true)
                  ->setArguments([null, null]);

        $container->addCompilerPass(new RegisterLocaleAwareServicesPass());
        $container->compile();

        $this->assertFalse($container->hasDefinition('locale_aware_listener'));
    }
}
$def = new Definition(DataCollector::class);
        $def->setPublic(true);

        $container->setDefinition(DataCollector::class$def);

        $container->setParameter('kernel.debug', false);

        $compilerPass = new ElasticsearchProfileCompilerPass();
        $compilerPass->process($container);

        static::assertFalse($container->hasDefinition(DataCollector::class));
    }

    public function testCompilerPassDecoratesClient(): void
    {
        $container = new ContainerBuilder();

        $def = new Definition(DataCollector::class);
        $def->setPublic(true);
        $container->setDefinition(DataCollector::class$def);

        $def = new Definition(Client::class);
        
Home | Imprint | This part of the site doesn't use cookies.