clearTag example

$def->clearTags();
        $this->assertEquals([]$def->getTags(), '->clearTags() removes all current tags');
    }

    public function testClearTag()
    {
        $def = new Definition('stdClass');
        $this->assertSame($def$def->clearTags(), '->clearTags() implements a fluent interface');
        $def->addTag('1foo1', ['foo1' => 'bar1']);
        $def->addTag('2foo2', ['foo2' => 'bar2']);
        $def->addTag('3foo3', ['foo3' => 'bar3']);
        $def->clearTag('2foo2');
        $this->assertTrue($def->hasTag('1foo1'));
        $this->assertFalse($def->hasTag('2foo2'));
        $this->assertTrue($def->hasTag('3foo3'));
        $def->clearTag('1foo1');
        $this->assertFalse($def->hasTag('1foo1'));
        $this->assertTrue($def->hasTag('3foo3'));
    }

    public function testTags()
    {
        $def = new Definition('stdClass');
        
$definition
          ->setClass(WorkspacesAliasRepository::class)
          ->addMethodCall('setWorkspacesManager', [new Reference('workspaces.manager')]);
      }
    }

    // Ensure that there's no active workspace while running database updates by     // removing the relevant tag from all workspace negotiator services.     if ($container->get('kernel') instanceof UpdateKernel) {
      foreach ($container->getDefinitions() as $definition) {
        if ($definition->hasTag('workspace_negotiator')) {
          $definition->clearTag('workspace_negotiator');
        }
      }
    }
  }

}

        if (!$container->hasDefinition($serviceId)) {
            return;
        }

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

        if (!$definition->hasTag('flow.storer')) {
            return;
        }

        $definition->clearTag('flow.storer');
    }
}

    private array $serviceLocatorContextIds = [];

    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        $this->serviceLocatorContextIds = [];
        foreach ($container->findTaggedServiceIds('container.service_locator_context') as $id => $tags) {
            $this->serviceLocatorContextIds[$id] = $tags[0]['id'];
            $container->getDefinition($id)->clearTag('container.service_locator_context');
        }

        try {
            parent::process($container);
        } finally {
            $this->serviceLocatorContextIds = [];
        }
    }

    protected function processValue(mixed $value, bool $isRoot = false): mixed
    {
        

    public static function remove(ContainerBuilder $builder, string $serviceId, array $remove): void
    {
        if (!$builder->hasDefinition($serviceId)) {
            return;
        }

        $definition = $builder->getDefinition($serviceId);

        $listeners = $definition->getTag('kernel.event_listener');

        $definition->clearTag('kernel.event_listener');

        $map = \array_map(function Darray $item) {
            return \implode('::', $item);
        }$remove);

        foreach ($listeners as $listener) {
            $key = $listener['event'] . '::' . $listener['method'];

            if (!\in_array($key$map, true)) {
                $definition->addTag('kernel.event_listener', $listener);
            }
        }
    $twig_config = $container->getParameter('twig.config');
    $twig_config['cache'] = FALSE;
    $container->setParameter('twig.config', $twig_config);

    // No service may persist when the early installer kernel is rebooted into     // the production environment.     // @todo The DrupalKernel reboot performed by drupal_install_system() is     // actually not a "regular" reboot (like ModuleInstaller::install()), so     // services are not actually persisted.     foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
      $definition = $container->getDefinition($id);
      $definition->clearTag('persist');
    }
  }

}
class DisableTemplateCachePass implements CompilerPassInterface
{
    /** * You can modify the container here before it is dumped to PHP code. */
    public function process(ContainerBuilder $container): void
    {
        if (!$container->hasDefinition('twig.cache_warmer') || !$container->hasDefinition('twig.template_cache_warmer')) {
            return;
        }
        // disable cache warm-up as it breaks the inheritance         $container->getDefinition('twig.cache_warmer')->clearTag('kernel.cache_warmer');
        $container->getDefinition('twig.template_cache_warmer')->clearTag('kernel.cache_warmer');
    }
}
$this->resolvedIds[$id] = true;
                    $this->processValue($container->getDefinition($id), true);
                }
            }
        } finally {
            $this->resolvedIds = [];
            $this->container = null;
        }

        foreach ($container->getDefinitions() as $definition) {
            if ($definition->hasTag(self::DO_PRELOAD_TAG)) {
                $definition->clearTag(self::DO_PRELOAD_TAG);
            } elseif (!$definition->isDeprecated() && !$definition->hasErrors()) {
                $definition->addTag('container.no_preload');
            }
        }
    }

    protected function processValue(mixed $value, bool $isRoot = false): mixed
    {
        if ($value instanceof Reference && ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE !== $value->getInvalidBehavior() && $this->container->hasDefinition($id = (string) $value)) {
            $definition = $this->container->getDefinition($id);

            


        if (!$value instanceof Definition) {
            return parent::processValue($value$isRoot);
        }

        $serviceLocator = $this->serviceLocator;
        $this->serviceLocator = null;

        if ($value->hasTag('container.service_subscriber.locator')) {
            $this->serviceLocator = $value->getTag('container.service_subscriber.locator')[0]['id'];
            $value->clearTag('container.service_subscriber.locator');
        }

        try {
            return parent::processValue($value);
        } finally {
            $this->serviceLocator = $serviceLocator;
        }
    }
}
$translatorAlias = $container->getAlias('translator');
            $definition = $container->getDefinition((string) $translatorAlias);
            $class = $container->getParameterBag()->resolveValue($definition->getClass());

            if (!$r = $container->getReflectionClass($class)) {
                throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class$translatorAlias));
            }
            if ($r->isSubclassOf(TranslatorInterface::class) && $r->isSubclassOf(TranslatorBagInterface::class)) {
                $container->getDefinition('translator.logging')->setDecoratedService('translator');
                $warmer = $container->getDefinition('translation.warmer');
                $subscriberAttributes = $warmer->getTag('container.service_subscriber');
                $warmer->clearTag('container.service_subscriber');

                foreach ($subscriberAttributes as $k => $v) {
                    if ((!isset($v['id']) || 'translator' !== $v['id']) && (!isset($v['key']) || 'translator' !== $v['key'])) {
                        $warmer->addTag('container.service_subscriber', $v);
                    }
                }
                $warmer->addTag('container.service_subscriber', ['key' => 'translator', 'id' => 'translator.logging.inner']);
            }
        }
    }
}
$definition->setMethodCalls([]);

    // Replace lock service with no-op implementation as Drupal installation can     // only occur in a single thread and the site should not be publicly     // available.     $container
      ->register('lock', NullLockBackend::class);

    // Remove the cache tags invalidator tag from the cache tags storage, so     // that we don't call it when cache tags are invalidated in the installer.     $container->getDefinition('cache_tags.invalidator.checksum')
      ->clearTag('cache_tags_invalidator');

    // Use performance-optimized extension lists.     $container->getDefinition('extension.list.module')->setClass(InstallerModuleExtensionList::class);
    $container->getDefinition('extension.list.theme')->setClass(InstallerThemeExtensionList::class);
    $container->getDefinition('extension.list.theme_engine')->setClass(InstallerThemeEngineExtensionList::class);

    // Don't register the lazy route provider in the super early installer.     if (static::class === NormalInstallerServiceProvider::class) {
      $lazy_route_provider = $container->register('router.route_provider.installer');
      $lazy_route_provider
        ->setClass(InstallerRouteProviderLazyBuilder::class)
        
->addArgument(new Reference('config.typed'))
        ->addArgument($this->getConfigSchemaExclusions())
        ->addTag('event_subscriber');
    }

    if ($container->hasDefinition('path_alias.path_processor')) {
      // The alias-based processor requires the path_alias entity schema to be       // installed, so we prevent it from being registered to the path processor       // manager. We do this by removing the tags that the compiler pass looks       // for. This means that the URL generator can safely be used within tests.       $container->getDefinition('path_alias.path_processor')
        ->clearTag('path_processor_inbound')
        ->clearTag('path_processor_outbound');
    }

    // Relax the password hashing cost in tests to avoid performance issues.     if ($container->hasDefinition('password')) {
      $container->getDefinition('password')
        ->setArguments([PASSWORD_BCRYPT, ['cost' => 4]]);
    }

    // Add the on demand rebuild route provider service.     $route_provider_service_name = 'router.route_provider';
    
->setArguments([
                    new Reference($dispatchersId[$dispatcherId].'.inner'),
                    new Reference('debug.stopwatch'),
                    new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE),
                    new Reference('request_stack', ContainerInterface::NULL_ON_INVALID_REFERENCE),
                ]);
        }

        foreach (['kernel.event_subscriber', 'kernel.event_listener'] as $tagName) {
            foreach ($container->findTaggedServiceIds($tagName) as $taggedServiceId => $tags) {
                $taggedServiceDefinition = $container->findDefinition($taggedServiceId);
                $taggedServiceDefinition->clearTag($tagName);

                foreach ($tags as $tag) {
                    if ($dispatcherId = $tag['dispatcher'] ?? null) {
                        $tag['dispatcher'] = $dispatchersId[$dispatcherId] ?? $dispatcherId;
                    }
                    $taggedServiceDefinition->addTag($tagName$tag);
                }
            }
        }
    }
}
class ResolveHotPathPass extends AbstractRecursivePass
{
    private array $resolvedIds = [];

    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        try {
            parent::process($container);
            $container->getDefinition('service_container')->clearTag('container.hot_path');
        } finally {
            $this->resolvedIds = [];
        }
    }

    protected function processValue(mixed $value, bool $isRoot = false): mixed
    {
        if ($value instanceof ArgumentInterface) {
            return $value;
        }

        
/** * {@inheritdoc} */
  public function alter(ContainerBuilder $container) {
    // The alias-based processor requires the path_alias entity schema to be     // installed, so we prevent it from being registered to the path processor     // manager. We do this by removing the tags that the compiler pass looks     // for. This means that the URL generator can safely be used during the     // database update process.     if ($container->hasDefinition('path_alias.path_processor')) {
      $container->getDefinition('path_alias.path_processor')
        ->clearTag('path_processor_inbound')
        ->clearTag('path_processor_outbound');
    }
  }

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