* * 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\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; /** * @author Guilhem N. * * @deprecated since version 3.3, to be removed in 4.0. */ class FactoryReturnTypePass implements CompilerPassInterface { private $resolveClassPass; public function __construct(ResolveClassPass $resolveClassPass = null) { if (null === $resolveClassPass) { @trigger_error('The '.__CLASS__.' class is deprecated since Symfony 3.3 and will be removed in 4.0.', E_USER_DEPRECATED); } $this->resolveClassPass = $resolveClassPass; } /** * {@inheritdoc} */ public function process(ContainerBuilder $container) { // works only since php 7.0 and hhvm 3.11 if (!method_exists(\ReflectionMethod::class, 'getReturnType')) { return; } $resolveClassPassChanges = null !== $this->resolveClassPass ? $this->resolveClassPass->getChanges() : array(); foreach ($container->getDefinitions() as $id => $definition) { $this->updateDefinition($container, $id, $definition, $resolveClassPassChanges); } } private function updateDefinition(ContainerBuilder $container, $id, Definition $definition, array $resolveClassPassChanges, array $previous = array()) { // circular reference if (isset($previous[$id])) { return; } $factory = $definition->getFactory(); if (null === $factory || (!isset($resolveClassPassChanges[$id]) && null !== $definition->getClass())) { return; } $class = null; if (is_string($factory)) { try { $m = new \ReflectionFunction($factory); if (false !== $m->getFileName() && file_exists($m->getFileName())) { $container->fileExists($m->getFileName()); } } catch (\ReflectionException $e) { return; } } else { if ($factory[0] instanceof Reference) { $previous[$id] = true; $factoryId = $container->normalizeId($factory[0]); $factoryDefinition = $container->findDefinition($factoryId); $this->updateDefinition($container, $factoryId, $factoryDefinition, $resolveClassPassChanges, $previous); $class = $factoryDefinition->getClass(); } else { $class = $factory[0]; } if (!$m = $container->getReflectionClass($class, false)) { return; } try { $m = $m->getMethod($factory[1]); } catch (\ReflectionException $e) { return; } } $returnType = $m->getReturnType(); if (null !== $returnType && !$returnType->isBuiltin()) { $returnType = $returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType->__toString(); if (null !== $class) { $declaringClass = $m->getDeclaringClass()->getName(); if ('self' === strtolower($returnType)) { $returnType = $declaringClass; } elseif ('parent' === strtolower($returnType)) { $returnType = get_parent_class($declaringClass) ?: null; } } if (null !== $returnType && (!isset($resolveClassPassChanges[$id]) || $returnType !== $resolveClassPassChanges[$id])) { @trigger_error(sprintf('Relying on its factory\'s return-type to define the class of service "%s" is deprecated since Symfony 3.3 and won\'t work in 4.0. Set the "class" attribute to "%s" on the service definition instead.', $id, $returnType), E_USER_DEPRECATED); } $definition->setClass($returnType); } } } __halt_compiler();----SIGNATURE:----EbE05T4V2bmLDOTfFT8ARxqL/saA0xit7Q8AN2pwwn3MZ0MGzP29Qvmd6H82Yl1yrdqn/Yr6Hh06EVq+Eu+kOAjzh+ElXNYV+pCuDbQX7IPefapgF9T39EV66pecxO3dkxmI6H339tesfjFH24OdTtFFRJZZN32S3WLDo4QfOqy0qZ85gevpVddEcB1i/L0eQNv5UPnkRRxUC4zDE1FzmjDUybDjcB4tGON+lZj+zf+V/qOkpnyWYCwxOf4eWvWRoB91xKLjtBazA098jFEyy9LD4JsAlOMuY3PO9JrAg7jw3mqEJSehiZjMWurnT6rlTuDY+sZTcwckqkkeUbWnasCDTjdjUTst91NK0CaAf6oBIUpHi3CHAxa4Fvma6NcpoU79vQ3zJNzXr45KaWX59ypW0Mg92ATGQ2kiM2LZqL+oBA0DEAbnDL+Gs+iGEg2/UiFBA6Y1zpSSsUDW+09+f6X3EVIcnt4DJKrPdiIsfOBb/tCOqGtG4zGvG32GmBJX1dmoObrpoXlqMagcqzgS7sb7Gci/7N8KefQ5BWAT5ooBk0cJMaeVzMAXHyVAVQyfEZ5vZNEfNRHUGClopUza6/FQnAzJUoJOJSCfyGxtGTf9JwzKKFF/IlBWzheOCEe7MA2XqjGNKDTtpAnFSCvWo5iNMLqnxoZ0HKNktXkCOAc=----ATTACHMENT:----NDg1ODY5OTIwOTE2MTc5NiA5NjE0ODY3MjQ0NzM2ODUgNzI0ODg2MjE5NzY3NzAwNA==