setAlias example

        $instance = self::getDefinedInstance($options$alias$arguments);
        if ($instance !== null) {
            return $instance;
        }

        // Try to locate the class         if ($class = self::locateClass($options$alias)) {
            return null;
        }

        self::createInstance($options['component']$class$arguments);
        self::setAlias($options['component']$alias$class);

        return self::$instances[$options['component']][$class];
    }

    /** * Gets the defined instance. If not exists, creates new one. * * @return object|null */
    private static function getDefinedInstance(array $options, string $alias, array $arguments)
    {
        
$this->process($container);

        $this->assertTrue($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
    }

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

        $container->register('parent', 'ParentClass');
        $container->setAlias('parent_alias', 'parent');
        $container->setDefinition('child', new ChildDefinition('parent_alias'));

        $this->process($container);

        $def = $container->getDefinition('child');
        $this->assertSame('ParentClass', $def->getClass());
    }

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

        

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

        $aDefinition = $container->register('a', '\stdClass')->setPublic(true);
        $aDefinition->setFactory([new Reference('b'), 'createA']);

        $bDefinition = new Definition('\stdClass');
        $container->setDefinition('b', $bDefinition);

        $container->setAlias('a_alias', 'a')->setPublic(true)->setDeprecated('foo/bar', '1.2', '%alias_id%');
        $container->setAlias('b_alias', 'b')->setPublic(true)->setDeprecated('foo/bar', '1.2', '%alias_id%');

        $container->setAlias('container', 'service_container');

        $this->process($container);

        $this->assertTrue($container->has('a'), '->process() does nothing to public definitions.');
        $this->assertTrue($container->hasAlias('a_alias'));
        $this->assertTrue($container->getAlias('a_alias')->isDeprecated());
        $this->assertFalse($container->has('b'), '->process() removes non-public definitions.');
        $this->assertTrue(
            


  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    // Trim the alias value of whitespace and slashes. Ensure to not trim the     // slash on the left side.     $alias = rtrim(trim($this->getAlias()), "\\/");
    $this->setAlias($alias);
  }

  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    $alias_manager = \Drupal::service('path_alias.manager');
    $alias_manager->cacheClear($this->getPath());
    if ($update) {
      
throw new LogicException(sprintf('Alias cannot be automatically determined for class "%s". If you have used the #[AsAlias] attribute with a class implementing multiple interfaces, add the interface you want to alias to the first parameter of #[AsAlias].', $class));
                    }
                    if (isset($this->aliases[$alias])) {
                        throw new LogicException(sprintf('The "%s" alias has already been defined with the #[AsAlias] attribute in "%s".', $alias$this->aliases[$alias]));
                    }
                    $this->aliases[$alias] = new Alias($class$public);
                }
            }
        }

        foreach ($this->aliases as $alias => $aliasDefinition) {
            $this->container->setAlias($alias$aliasDefinition);
        }

        if ($this->autoRegisterAliasesForSinglyImplementedInterfaces) {
            $this->registerAliasesForSinglyImplementedInterfaces();
        }
    }

    /** * @return void */
    public function registerAliasesForSinglyImplementedInterfaces()
    {


            if (Kernel::VERSION_ID >= 60400) {
                $config['handle_all_throwables'] = true;
            }

            $container
                ->loadFromExtension('framework', $config)
                ->loadFromExtension('twig', [
                    'default_path' => __DIR__.'/templates',
                ])
                ->setAlias('twig.alias', 'twig')->setPublic(true)
            ;
        });
    }

    public function getCacheDir(): string
    {
        return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/cache/'.$this->environment;
    }

    public function getLogDir(): string
    {
        

class LoggerPass implements CompilerPassInterface
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        $container->setAlias(LoggerInterface::class, 'logger')
            ->setPublic(false);

        if ($container->has('logger')) {
            return;
        }

        $container->register('logger', Logger::class)
            ->setArguments([null, null, null, new Reference(RequestStack::class)])
            ->setPublic(false);
    }
}
'http_method_override' => false,
    'handle_all_throwables' => true,
    'php_errors' => ['log' => true],
    'secret' => 's3cr3t',
    'validation' => [
        'enabled' => true,
        'enable_attributes' => true,
        'email_validation_mode' => 'html5',
    ],
]);

$container->setAlias('validator.alias', 'validator')->setPublic(true);

    private function parseDefinition(string $id$service, string $file, array $defaults)
    {
        if (\is_string($service) && str_starts_with($service, '@')) {
            $this->container->setAlias($id$alias = new Alias(substr($service, 1)));
            if (isset($defaults['public'])) {
                $alias->setPublic($defaults['public']);
            }

            return;
        }

        if (null === $service) {
            $service = [];
        }

        
public function process(ContainerBuilder $container)
    {
        foreach ($container->findTaggedServiceIds('auto_alias') as $serviceId => $tags) {
            foreach ($tags as $tag) {
                if (!isset($tag['format'])) {
                    throw new InvalidArgumentException(sprintf('Missing tag information "format" on auto_alias service "%s".', $serviceId));
                }

                $aliasId = $container->getParameterBag()->resolveValue($tag['format']);
                if ($container->hasDefinition($aliasId) || $container->hasAlias($aliasId)) {
                    $alias = new Alias($aliasId$container->getDefinition($serviceId)->isPublic());
                    $container->setAlias($serviceId$alias);
                }
            }
        }
    }
}
        $seenAliasTargets = [];
        $replacements = [];

        foreach ($container->getAliases() as $definitionId => $target) {
            $targetId = (string) $target;
            // Special case: leave this target alone             if ('service_container' === $targetId) {
                continue;
            }
            // Check if target needs to be replaced             if (isset($replacements[$targetId])) {
                $container->setAlias($definitionId$replacements[$targetId])->setPublic($target->isPublic());

                if ($target->isDeprecated()) {
                    $container->getAlias($definitionId)->setDeprecated(...array_values($target->getDeprecation('%alias_id%')));
                }
            }
            // No need to process the same target twice             if (isset($seenAliasTargets[$targetId])) {
                continue;
            }
            // Process new target             $seenAliasTargets[$targetId] = true;
            
        $seenAliasTargets = [];
        $replacements = [];

        foreach ($container->getAliases() as $definitionId => $target) {
            $targetId = (string) $target;
            // Special case: leave this target alone             if ('service_container' === $targetId) {
                continue;
            }
            // Check if target needs to be replaced             if (isset($replacements[$targetId])) {
                $container->setAlias($definitionId$replacements[$targetId])->setPublic($target->isPublic());

                if ($target->isDeprecated()) {
                    $container->getAlias($definitionId)->setDeprecated(...array_values($target->getDeprecation('%alias_id%')));
                }
            }
            // No need to process the same target twice             if (isset($seenAliasTargets[$targetId])) {
                continue;
            }
            // Process new target             $seenAliasTargets[$targetId] = true;
            
// only register if the improved version from DebugBundle is *not* present             if (!$container->has('twig.extension.dump')) {
                $container->getDefinition('twig.extension.debug')->addTag('twig.extension');
            }
        }

        if ($container->has('web_link.add_link_header_listener')) {
            $container->getDefinition('twig.extension.weblink')->addTag('twig.extension');
        }

        $container->setAlias('twig.loader.filesystem', new Alias('twig.loader.native_filesystem', false));

        if ($container->has('assets.packages')) {
            $container->getDefinition('twig.extension.assets')->addTag('twig.extension');
        }

        if ($container->hasDefinition('twig.extension.yaml')) {
            $container->getDefinition('twig.extension.yaml')->addTag('twig.extension');
        }

        if (class_exists(\Symfony\Component\Stopwatch\Stopwatch::class)) {
            $container->getDefinition('twig.extension.debug.stopwatch')->addTag('twig.extension');
        }
$services[$k] = new ServiceClosureArgument($v);
        }
        ksort($services);

        $value->setArgument(0, $services);

        $id = '.service_locator.'.ContainerBuilder::hash($value);

        if ($isRoot) {
            if ($id !== $this->currentId) {
                $this->container->setAlias($idnew Alias($this->currentId, false));
            }

            return $value;
        }

        $this->container->setDefinition($id$value->setPublic(false));

        return new Reference($id);
    }

    public static function register(ContainerBuilder $container, array $map, string $callerId = null): Reference
    {

class LoggerPass implements CompilerPassInterface
{
    /** * @return void */
    public function process(ContainerBuilder $container)
    {
        $container->setAlias(LoggerInterface::class, 'logger');

        if ($container->has('logger')) {
            return;
        }

        if ($debug = $container->getParameter('kernel.debug')) {
            // Build an expression that will be equivalent to `!in_array(PHP_SAPI, ['cli', 'phpdbg'])`             $debug = (new Definition('bool'))
                ->setFactory('in_array')
                ->setArguments([
                    (new Definition('string'))->setFactory('constant')->setArguments(['PHP_SAPI']),
                    [
Home | Imprint | This part of the site doesn't use cookies.