vendor/symfony/dependency-injection/Compiler/AutowirePass.php line 340

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\DependencyInjection\Compiler;
  11. use Symfony\Component\Config\Resource\ClassExistenceResource;
  12. use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
  13. use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
  14. use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
  15. use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
  16. use Symfony\Component\DependencyInjection\Attribute\Target;
  17. use Symfony\Component\DependencyInjection\ContainerBuilder;
  18. use Symfony\Component\DependencyInjection\Definition;
  19. use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
  20. use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  21. use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper;
  22. use Symfony\Component\DependencyInjection\TypedReference;
  23. /**
  24.  * Inspects existing service definitions and wires the autowired ones using the type hints of their classes.
  25.  *
  26.  * @author Kévin Dunglas <dunglas@gmail.com>
  27.  * @author Nicolas Grekas <p@tchwork.com>
  28.  */
  29. class AutowirePass extends AbstractRecursivePass
  30. {
  31.     private $types;
  32.     private $ambiguousServiceTypes;
  33.     private $autowiringAliases;
  34.     private $lastFailure;
  35.     private $throwOnAutowiringException;
  36.     private $decoratedClass;
  37.     private $decoratedId;
  38.     private $methodCalls;
  39.     private $defaultArgument;
  40.     private $getPreviousValue;
  41.     private $decoratedMethodIndex;
  42.     private $decoratedMethodArgumentIndex;
  43.     private $typesClone;
  44.     public function __construct(bool $throwOnAutowireException true)
  45.     {
  46.         $this->throwOnAutowiringException $throwOnAutowireException;
  47.         $this->defaultArgument = new class() {
  48.             public $value;
  49.             public $names;
  50.             public $bag;
  51.             public function withValue(\ReflectionParameter $parameter): self
  52.             {
  53.                 $clone = clone $this;
  54.                 $clone->value $this->bag->escapeValue($parameter->getDefaultValue());
  55.                 return $clone;
  56.             }
  57.         };
  58.     }
  59.     /**
  60.      * {@inheritdoc}
  61.      */
  62.     public function process(ContainerBuilder $container)
  63.     {
  64.         $this->defaultArgument->bag $container->getParameterBag();
  65.         try {
  66.             $this->typesClone = clone $this;
  67.             parent::process($container);
  68.         } finally {
  69.             $this->decoratedClass null;
  70.             $this->decoratedId null;
  71.             $this->methodCalls null;
  72.             $this->defaultArgument->bag null;
  73.             $this->defaultArgument->names null;
  74.             $this->getPreviousValue null;
  75.             $this->decoratedMethodIndex null;
  76.             $this->decoratedMethodArgumentIndex null;
  77.             $this->typesClone null;
  78.         }
  79.     }
  80.     /**
  81.      * {@inheritdoc}
  82.      */
  83.     protected function processValue($valuebool $isRoot false)
  84.     {
  85.         try {
  86.             return $this->doProcessValue($value$isRoot);
  87.         } catch (AutowiringFailedException $e) {
  88.             if ($this->throwOnAutowiringException) {
  89.                 throw $e;
  90.             }
  91.             $this->container->getDefinition($this->currentId)->addError($e->getMessageCallback() ?? $e->getMessage());
  92.             return parent::processValue($value$isRoot);
  93.         }
  94.     }
  95.     /**
  96.      * @return mixed
  97.      */
  98.     private function doProcessValue($valuebool $isRoot false)
  99.     {
  100.         if ($value instanceof TypedReference) {
  101.             if ($ref $this->getAutowiredReference($valuetrue)) {
  102.                 return $ref;
  103.             }
  104.             if (ContainerBuilder::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
  105.                 $message $this->createTypeNotFoundMessageCallback($value'it');
  106.                 // since the error message varies by referenced id and $this->currentId, so should the id of the dummy errored definition
  107.                 $this->container->register($id sprintf('.errored.%s.%s'$this->currentId, (string) $value), $value->getType())
  108.                     ->addError($message);
  109.                 return new TypedReference($id$value->getType(), $value->getInvalidBehavior(), $value->getName());
  110.             }
  111.         }
  112.         $value parent::processValue($value$isRoot);
  113.         if (!$value instanceof Definition || !$value->isAutowired() || $value->isAbstract() || !$value->getClass()) {
  114.             return $value;
  115.         }
  116.         if (!$reflectionClass $this->container->getReflectionClass($value->getClass(), false)) {
  117.             $this->container->log($thissprintf('Skipping service "%s": Class or interface "%s" cannot be loaded.'$this->currentId$value->getClass()));
  118.             return $value;
  119.         }
  120.         $this->methodCalls $value->getMethodCalls();
  121.         try {
  122.             $constructor $this->getConstructor($valuefalse);
  123.         } catch (RuntimeException $e) {
  124.             throw new AutowiringFailedException($this->currentId$e->getMessage(), 0$e);
  125.         }
  126.         if ($constructor) {
  127.             array_unshift($this->methodCalls, [$constructor$value->getArguments()]);
  128.         }
  129.         $checkAttributes 80000 <= \PHP_VERSION_ID && !$value->hasTag('container.ignore_attributes');
  130.         $this->methodCalls $this->autowireCalls($reflectionClass$isRoot$checkAttributes);
  131.         if ($constructor) {
  132.             [, $arguments] = array_shift($this->methodCalls);
  133.             if ($arguments !== $value->getArguments()) {
  134.                 $value->setArguments($arguments);
  135.             }
  136.         }
  137.         if ($this->methodCalls !== $value->getMethodCalls()) {
  138.             $value->setMethodCalls($this->methodCalls);
  139.         }
  140.         return $value;
  141.     }
  142.     private function autowireCalls(\ReflectionClass $reflectionClassbool $isRootbool $checkAttributes): array
  143.     {
  144.         $this->decoratedId null;
  145.         $this->decoratedClass null;
  146.         $this->getPreviousValue null;
  147.         if ($isRoot && ($definition $this->container->getDefinition($this->currentId)) && null !== ($this->decoratedId $definition->innerServiceId) && $this->container->has($this->decoratedId)) {
  148.             $this->decoratedClass $this->container->findDefinition($this->decoratedId)->getClass();
  149.         }
  150.         $patchedIndexes = [];
  151.         foreach ($this->methodCalls as $i => $call) {
  152.             [$method$arguments] = $call;
  153.             if ($method instanceof \ReflectionFunctionAbstract) {
  154.                 $reflectionMethod $method;
  155.             } else {
  156.                 $definition = new Definition($reflectionClass->name);
  157.                 try {
  158.                     $reflectionMethod $this->getReflectionMethod($definition$method);
  159.                 } catch (RuntimeException $e) {
  160.                     if ($definition->getFactory()) {
  161.                         continue;
  162.                     }
  163.                     throw $e;
  164.                 }
  165.             }
  166.             $arguments $this->autowireMethod($reflectionMethod$arguments$checkAttributes$i);
  167.             if ($arguments !== $call[1]) {
  168.                 $this->methodCalls[$i][1] = $arguments;
  169.                 $patchedIndexes[] = $i;
  170.             }
  171.         }
  172.         // use named arguments to skip complex default values
  173.         foreach ($patchedIndexes as $i) {
  174.             $namedArguments null;
  175.             $arguments $this->methodCalls[$i][1];
  176.             foreach ($arguments as $j => $value) {
  177.                 if ($namedArguments && !$value instanceof $this->defaultArgument) {
  178.                     unset($arguments[$j]);
  179.                     $arguments[$namedArguments[$j]] = $value;
  180.                 }
  181.                 if ($namedArguments || !$value instanceof $this->defaultArgument) {
  182.                     continue;
  183.                 }
  184.                 if (\PHP_VERSION_ID >= 80100 && (\is_array($value->value) ? $value->value : \is_object($value->value))) {
  185.                     unset($arguments[$j]);
  186.                     $namedArguments $value->names;
  187.                 } else {
  188.                     $arguments[$j] = $value->value;
  189.                 }
  190.             }
  191.             $this->methodCalls[$i][1] = $arguments;
  192.         }
  193.         return $this->methodCalls;
  194.     }
  195.     /**
  196.      * Autowires the constructor or a method.
  197.      *
  198.      * @throws AutowiringFailedException
  199.      */
  200.     private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, array $argumentsbool $checkAttributesint $methodIndex): array
  201.     {
  202.         $class $reflectionMethod instanceof \ReflectionMethod $reflectionMethod->class $this->currentId;
  203.         $method $reflectionMethod->name;
  204.         $parameters $reflectionMethod->getParameters();
  205.         if ($reflectionMethod->isVariadic()) {
  206.             array_pop($parameters);
  207.         }
  208.         $this->defaultArgument->names = new \ArrayObject();
  209.         foreach ($parameters as $index => $parameter) {
  210.             $this->defaultArgument->names[$index] = $parameter->name;
  211.             if (\array_key_exists($parameter->name$arguments)) {
  212.                 $arguments[$index] = $arguments[$parameter->name];
  213.                 unset($arguments[$parameter->name]);
  214.             }
  215.             if (\array_key_exists($index$arguments) && '' !== $arguments[$index]) {
  216.                 continue;
  217.             }
  218.             $type ProxyHelper::getTypeHint($reflectionMethod$parametertrue);
  219.             if ($checkAttributes) {
  220.                 foreach ($parameter->getAttributes() as $attribute) {
  221.                     if (TaggedIterator::class === $attribute->getName()) {
  222.                         $attribute $attribute->newInstance();
  223.                         $arguments[$index] = new TaggedIteratorArgument($attribute->tag$attribute->indexAttribute$attribute->defaultIndexMethodfalse$attribute->defaultPriorityMethod);
  224.                         break;
  225.                     }
  226.                     if (TaggedLocator::class === $attribute->getName()) {
  227.                         $attribute $attribute->newInstance();
  228.                         $arguments[$index] = new ServiceLocatorArgument(new TaggedIteratorArgument($attribute->tag$attribute->indexAttribute$attribute->defaultIndexMethodtrue$attribute->defaultPriorityMethod));
  229.                         break;
  230.                     }
  231.                 }
  232.                 if ('' !== ($arguments[$index] ?? '')) {
  233.                     continue;
  234.                 }
  235.             }
  236.             if (!$type) {
  237.                 if (isset($arguments[$index])) {
  238.                     continue;
  239.                 }
  240.                 // no default value? Then fail
  241.                 if (!$parameter->isDefaultValueAvailable()) {
  242.                     // For core classes, isDefaultValueAvailable() can
  243.                     // be false when isOptional() returns true. If the
  244.                     // argument *is* optional, allow it to be missing
  245.                     if ($parameter->isOptional()) {
  246.                         --$index;
  247.                         break;
  248.                     }
  249.                     $type ProxyHelper::getTypeHint($reflectionMethod$parameterfalse);
  250.                     $type $type sprintf('is type-hinted "%s"'ltrim($type'\\')) : 'has no type-hint';
  251.                     throw new AutowiringFailedException($this->currentIdsprintf('Cannot autowire service "%s": argument "$%s" of method "%s()" %s, you should configure its value explicitly.'$this->currentId$parameter->name$class !== $this->currentId $class.'::'.$method $method$type));
  252.                 }
  253.                 // specifically pass the default value
  254.                 $arguments[$index] = $this->defaultArgument->withValue($parameter);
  255.                 continue;
  256.             }
  257.             $getValue = function () use ($type$parameter$class$method) {
  258.                 if (!$value $this->getAutowiredReference($ref = new TypedReference($type$typeContainerBuilder::EXCEPTION_ON_INVALID_REFERENCETarget::parseName($parameter)), true)) {
  259.                     $failureMessage $this->createTypeNotFoundMessageCallback($refsprintf('argument "$%s" of method "%s()"'$parameter->name$class !== $this->currentId $class.'::'.$method $method));
  260.                     if ($parameter->isDefaultValueAvailable()) {
  261.                         $value $this->defaultArgument->withValue($parameter);
  262.                     } elseif (!$parameter->allowsNull()) {
  263.                         throw new AutowiringFailedException($this->currentId$failureMessage);
  264.                     }
  265.                 }
  266.                 return $value;
  267.             };
  268.             if ($this->decoratedClass && $isDecorated is_a($this->decoratedClass$typetrue)) {
  269.                 if ($this->getPreviousValue) {
  270.                     // The inner service is injected only if there is only 1 argument matching the type of the decorated class
  271.                     // across all arguments of all autowired methods.
  272.                     // If a second matching argument is found, the default behavior is restored.
  273.                     $getPreviousValue $this->getPreviousValue;
  274.                     $this->methodCalls[$this->decoratedMethodIndex][1][$this->decoratedMethodArgumentIndex] = $getPreviousValue();
  275.                     $this->decoratedClass null// Prevent further checks
  276.                 } else {
  277.                     $arguments[$index] = new TypedReference($this->decoratedId$this->decoratedClass);
  278.                     $this->getPreviousValue $getValue;
  279.                     $this->decoratedMethodIndex $methodIndex;
  280.                     $this->decoratedMethodArgumentIndex $index;
  281.                     continue;
  282.                 }
  283.             }
  284.             $arguments[$index] = $getValue();
  285.         }
  286.         if ($parameters && !isset($arguments[++$index])) {
  287.             while (<= --$index) {
  288.                 if (!$arguments[$index] instanceof $this->defaultArgument) {
  289.                     break;
  290.                 }
  291.                 unset($arguments[$index]);
  292.             }
  293.         }
  294.         // it's possible index 1 was set, then index 0, then 2, etc
  295.         // make sure that we re-order so they're injected as expected
  296.         ksort($arguments, \SORT_NATURAL);
  297.         return $arguments;
  298.     }
  299.     /**
  300.      * Returns a reference to the service matching the given type, if any.
  301.      */
  302.     private function getAutowiredReference(TypedReference $referencebool $filterType): ?TypedReference
  303.     {
  304.         $this->lastFailure null;
  305.         $type $reference->getType();
  306.         if ($type !== (string) $reference) {
  307.             return $reference;
  308.         }
  309.         if ($filterType && false !== $m strpbrk($type'&|')) {
  310.             $types array_diff(explode($m[0], $type), ['int''string''array''bool''float''iterable''object''callable''null']);
  311.             sort($types);
  312.             $type implode($m[0], $types);
  313.         }
  314.         if (null !== $name $reference->getName()) {
  315.             if ($this->container->has($alias $type.' $'.$name) && !$this->container->findDefinition($alias)->isAbstract()) {
  316.                 return new TypedReference($alias$type$reference->getInvalidBehavior());
  317.             }
  318.             if (null !== ($alias $this->getCombinedAlias($type$name) ?? null) && !$this->container->findDefinition($alias)->isAbstract()) {
  319.                 return new TypedReference($alias$type$reference->getInvalidBehavior());
  320.             }
  321.             if ($this->container->has($name) && !$this->container->findDefinition($name)->isAbstract()) {
  322.                 foreach ($this->container->getAliases() as $id => $alias) {
  323.                     if ($name === (string) $alias && str_starts_with($id$type.' $')) {
  324.                         return new TypedReference($name$type$reference->getInvalidBehavior());
  325.                     }
  326.                 }
  327.             }
  328.         }
  329.         if ($this->container->has($type) && !$this->container->findDefinition($type)->isAbstract()) {
  330.             return new TypedReference($type$type$reference->getInvalidBehavior());
  331.         }
  332.         if (null !== ($alias $this->getCombinedAlias($type) ?? null) && !$this->container->findDefinition($alias)->isAbstract()) {
  333.             return new TypedReference($alias$type$reference->getInvalidBehavior());
  334.         }
  335.         return null;
  336.     }
  337.     /**
  338.      * Populates the list of available types.
  339.      */
  340.     private function populateAvailableTypes(ContainerBuilder $container)
  341.     {
  342.         $this->types = [];
  343.         $this->ambiguousServiceTypes = [];
  344.         $this->autowiringAliases = [];
  345.         foreach ($container->getDefinitions() as $id => $definition) {
  346.             $this->populateAvailableType($container$id$definition);
  347.         }
  348.         foreach ($container->getAliases() as $id => $alias) {
  349.             $this->populateAutowiringAlias($id);
  350.         }
  351.     }
  352.     /**
  353.      * Populates the list of available types for a given definition.
  354.      */
  355.     private function populateAvailableType(ContainerBuilder $containerstring $idDefinition $definition)
  356.     {
  357.         // Never use abstract services
  358.         if ($definition->isAbstract()) {
  359.             return;
  360.         }
  361.         if ('' === $id || '.' === $id[0] || $definition->isDeprecated() || !$reflectionClass $container->getReflectionClass($definition->getClass(), false)) {
  362.             return;
  363.         }
  364.         foreach ($reflectionClass->getInterfaces() as $reflectionInterface) {
  365.             $this->set($reflectionInterface->name$id);
  366.         }
  367.         do {
  368.             $this->set($reflectionClass->name$id);
  369.         } while ($reflectionClass $reflectionClass->getParentClass());
  370.         $this->populateAutowiringAlias($id);
  371.     }
  372.     /**
  373.      * Associates a type and a service id if applicable.
  374.      */
  375.     private function set(string $typestring $id)
  376.     {
  377.         // is this already a type/class that is known to match multiple services?
  378.         if (isset($this->ambiguousServiceTypes[$type])) {
  379.             $this->ambiguousServiceTypes[$type][] = $id;
  380.             return;
  381.         }
  382.         // check to make sure the type doesn't match multiple services
  383.         if (!isset($this->types[$type]) || $this->types[$type] === $id) {
  384.             $this->types[$type] = $id;
  385.             return;
  386.         }
  387.         // keep an array of all services matching this type
  388.         if (!isset($this->ambiguousServiceTypes[$type])) {
  389.             $this->ambiguousServiceTypes[$type] = [$this->types[$type]];
  390.             unset($this->types[$type]);
  391.         }
  392.         $this->ambiguousServiceTypes[$type][] = $id;
  393.     }
  394.     private function createTypeNotFoundMessageCallback(TypedReference $referencestring $label): \Closure
  395.     {
  396.         if (null === $this->typesClone->container) {
  397.             $this->typesClone->container = new ContainerBuilder($this->container->getParameterBag());
  398.             $this->typesClone->container->setAliases($this->container->getAliases());
  399.             $this->typesClone->container->setDefinitions($this->container->getDefinitions());
  400.             $this->typesClone->container->setResourceTracking(false);
  401.         }
  402.         $currentId $this->currentId;
  403.         return (function () use ($reference$label$currentId) {
  404.             return $this->createTypeNotFoundMessage($reference$label$currentId);
  405.         })->bindTo($this->typesClone);
  406.     }
  407.     private function createTypeNotFoundMessage(TypedReference $referencestring $labelstring $currentId): string
  408.     {
  409.         if (!$r $this->container->getReflectionClass($type $reference->getType(), false)) {
  410.             // either $type does not exist or a parent class does not exist
  411.             try {
  412.                 $resource = new ClassExistenceResource($typefalse);
  413.                 // isFresh() will explode ONLY if a parent class/trait does not exist
  414.                 $resource->isFresh(0);
  415.                 $parentMsg false;
  416.             } catch (\ReflectionException $e) {
  417.                 $parentMsg $e->getMessage();
  418.             }
  419.             $message sprintf('has type "%s" but this class %s.'$type$parentMsg sprintf('is missing a parent class (%s)'$parentMsg) : 'was not found');
  420.         } else {
  421.             $alternatives $this->createTypeAlternatives($this->container$reference);
  422.             $message $this->container->has($type) ? 'this service is abstract' 'no such service exists';
  423.             $message sprintf('references %s "%s" but %s.%s'$r->isInterface() ? 'interface' 'class'$type$message$alternatives);
  424.             if ($r->isInterface() && !$alternatives) {
  425.                 $message .= ' Did you create a class that implements this interface?';
  426.             }
  427.         }
  428.         $message sprintf('Cannot autowire service "%s": %s %s'$currentId$label$message);
  429.         if (null !== $this->lastFailure) {
  430.             $message $this->lastFailure."\n".$message;
  431.             $this->lastFailure null;
  432.         }
  433.         return $message;
  434.     }
  435.     private function createTypeAlternatives(ContainerBuilder $containerTypedReference $reference): string
  436.     {
  437.         // try suggesting available aliases first
  438.         if ($message $this->getAliasesSuggestionForType($container$type $reference->getType())) {
  439.             return ' '.$message;
  440.         }
  441.         if (null === $this->ambiguousServiceTypes) {
  442.             $this->populateAvailableTypes($container);
  443.         }
  444.         $servicesAndAliases $container->getServiceIds();
  445.         if (null !== ($autowiringAliases $this->autowiringAliases[$type] ?? null) && !isset($autowiringAliases[''])) {
  446.             return sprintf(' Available autowiring aliases for this %s are: "$%s".'class_exists($typefalse) ? 'class' 'interface'implode('", "$'$autowiringAliases));
  447.         }
  448.         if (!$container->has($type) && false !== $key array_search(strtolower($type), array_map('strtolower'$servicesAndAliases))) {
  449.             return sprintf(' Did you mean "%s"?'$servicesAndAliases[$key]);
  450.         } elseif (isset($this->ambiguousServiceTypes[$type])) {
  451.             $message sprintf('one of these existing services: "%s"'implode('", "'$this->ambiguousServiceTypes[$type]));
  452.         } elseif (isset($this->types[$type])) {
  453.             $message sprintf('the existing "%s" service'$this->types[$type]);
  454.         } else {
  455.             return '';
  456.         }
  457.         return sprintf(' You should maybe alias this %s to %s.'class_exists($typefalse) ? 'class' 'interface'$message);
  458.     }
  459.     private function getAliasesSuggestionForType(ContainerBuilder $containerstring $type): ?string
  460.     {
  461.         $aliases = [];
  462.         foreach (class_parents($type) + class_implements($type) as $parent) {
  463.             if ($container->has($parent) && !$container->findDefinition($parent)->isAbstract()) {
  464.                 $aliases[] = $parent;
  465.             }
  466.         }
  467.         if ($len = \count($aliases)) {
  468.             $message 'Try changing the type-hint to one of its parents: ';
  469.             for ($i 0, --$len$i $len; ++$i) {
  470.                 $message .= sprintf('%s "%s", 'class_exists($aliases[$i], false) ? 'class' 'interface'$aliases[$i]);
  471.             }
  472.             $message .= sprintf('or %s "%s".'class_exists($aliases[$i], false) ? 'class' 'interface'$aliases[$i]);
  473.             return $message;
  474.         }
  475.         if ($aliases) {
  476.             return sprintf('Try changing the type-hint to "%s" instead.'$aliases[0]);
  477.         }
  478.         return null;
  479.     }
  480.     private function populateAutowiringAlias(string $id): void
  481.     {
  482.         if (!preg_match('/(?(DEFINE)(?<V>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+))^((?&V)(?:\\\\(?&V))*+)(?: \$((?&V)))?$/'$id$m)) {
  483.             return;
  484.         }
  485.         $type $m[2];
  486.         $name $m[3] ?? '';
  487.         if (class_exists($typefalse) || interface_exists($typefalse)) {
  488.             $this->autowiringAliases[$type][$name] = $name;
  489.         }
  490.     }
  491.     private function getCombinedAlias(string $typestring $name null): ?string
  492.     {
  493.         if (str_contains($type'&')) {
  494.             $types explode('&'$type);
  495.         } elseif (str_contains($type'|')) {
  496.             $types explode('|'$type);
  497.         } else {
  498.             return null;
  499.         }
  500.         $alias null;
  501.         $suffix $name ' $'.$name '';
  502.         foreach ($types as $type) {
  503.             if (!$this->container->hasAlias($type.$suffix)) {
  504.                 return null;
  505.             }
  506.             if (null === $alias) {
  507.                 $alias = (string) $this->container->getAlias($type.$suffix);
  508.             } elseif ((string) $this->container->getAlias($type.$suffix) !== $alias) {
  509.                 return null;
  510.             }
  511.         }
  512.         return $alias;
  513.     }
  514. }