PHP 8.2.30
Preview: ResolveReferencesToAliasesPass.php Size: 2.83 KB
/opt/cloudlinux/alt-php54/root/usr/share/pear/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
 * Replaces all references to aliases with references to the actual service.
 *
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
class ResolveReferencesToAliasesPass implements CompilerPassInterface
{
    private $container;

    /**
     * Processes the ContainerBuilder to replace references to aliases with actual service references.
     *
     * @param ContainerBuilder $container
     */
    public function process(ContainerBuilder $container)
    {
        $this->container = $container;

        foreach ($container->getDefinitions() as $definition) {
            if ($definition->isSynthetic() || $definition->isAbstract()) {
                continue;
            }

            $definition->setArguments($this->processArguments($definition->getArguments()));
            $definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
            $definition->setProperties($this->processArguments($definition->getProperties()));
        }

        foreach ($container->getAliases() as $id => $alias) {
            $aliasId = (string) $alias;
            if ($aliasId !== $defId = $this->getDefinitionId($aliasId)) {
                $container->setAlias($id, new Alias($defId, $alias->isPublic()));
            }
        }
    }

    /**
     * Processes the arguments to replace aliases.
     *
     * @param array $arguments An array of References
     *
     * @return array An array of References
     */
    private function processArguments(array $arguments)
    {
        foreach ($arguments as $k => $argument) {
            if (is_array($argument)) {
                $arguments[$k] = $this->processArguments($argument);
            } elseif ($argument instanceof Reference) {
                $defId = $this->getDefinitionId($id = (string) $argument);

                if ($defId !== $id) {
                    $arguments[$k] = new Reference($defId, $argument->getInvalidBehavior(), $argument->isStrict());
                }
            }
        }

        return $arguments;
    }

    /**
     * Resolves an alias into a definition id.
     *
     * @param string $id The definition or alias id to resolve
     *
     * @return string The definition id with aliases resolved
     */
    private function getDefinitionId($id)
    {
        while ($this->container->hasAlias($id)) {
            $id = (string) $this->container->getAlias($id);
        }

        return $id;
    }
}

Directory Contents

Dirs: 0 × Files: 24

Name Size Perms Modified Actions
4.41 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
2.36 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
3.60 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
2.05 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
5.50 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
2.55 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
746 B lrw-r--r-- 2019-12-18 11:22:56
Edit Download
4.48 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
1.43 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
1.84 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
5.90 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
1.04 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
1.24 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
2.71 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
691 B lrw-r--r-- 2019-12-18 11:22:56
Edit Download
2.03 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
4.07 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
5.42 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
3.42 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
2.11 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
2.83 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
2.79 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
1.48 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download
2.49 KB lrw-r--r-- 2019-12-18 11:22:56
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).