Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
FactoryReturnTypePass.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\DependencyInjection\Compiler;
013
014 use Symfony\Component\DependencyInjection\ContainerBuilder;
015 use Symfony\Component\DependencyInjection\Definition;
016 use Symfony\Component\DependencyInjection\Reference;
017
018 /**
019 * @author Guilhem N. <egetick@gmail.com>
020 *
021 * @deprecated since version 3.3, to be removed in 4.0.
022 */
023 class FactoryReturnTypePass implements CompilerPassInterface
024 {
025 private $resolveClassPass;
026
027 public function __construct(ResolveClassPass $resolveClassPass = null)
028 {
029 if (null === $resolveClassPass) {
030 @trigger_error('The '.__CLASS__.' class is deprecated since Symfony 3.3 and will be removed in 4.0.', \E_USER_DEPRECATED);
031 }
032 $this->resolveClassPass = $resolveClassPass;
033 }
034
035 /**
036 * {@inheritdoc}
037 */
038 public function process(ContainerBuilder $container)
039 {
040 // works only since php 7.0 and hhvm 3.11
041 if (!method_exists(\ReflectionMethod::class, 'getReturnType')) {
042 return;
043 }
044 $resolveClassPassChanges = null !== $this->resolveClassPass ? $this->resolveClassPass->getChanges() : [];
045
046 foreach ($container->getDefinitions() as $id => $definition) {
047 $this->updateDefinition($container, $id, $definition, $resolveClassPassChanges);
048 }
049 }
050
051 private function updateDefinition(ContainerBuilder $container, $id, Definition $definition, array $resolveClassPassChanges, array $previous = [])
052 {
053 // circular reference
054 if (isset($previous[$id])) {
055 return;
056 }
057
058 $factory = $definition->getFactory();
059 if (null === $factory || (!isset($resolveClassPassChanges[$id]) && null !== $definition->getClass())) {
060 return;
061 }
062
063 $class = null;
064 if (\is_string($factory)) {
065 try {
066 $m = new \ReflectionFunction($factory);
067 if (false !== $m->getFileName() && file_exists($m->getFileName())) {
068 $container->fileExists($m->getFileName());
069 }
070 } catch (\ReflectionException $e) {
071 return;
072 }
073 } else {
074 if ($factory[0] instanceof Reference) {
075 $previous[$id] = true;
076 $factoryId = $container->normalizeId($factory[0]);
077 $factoryDefinition = $container->findDefinition($factoryId);
078 $this->updateDefinition($container, $factoryId, $factoryDefinition, $resolveClassPassChanges, $previous);
079 $class = $factoryDefinition->getClass();
080 } else {
081 $class = $factory[0];
082 }
083
084 if (!$m = $container->getReflectionClass($class, false)) {
085 return;
086 }
087 try {
088 $m = $m->getMethod($factory[1]);
089 } catch (\ReflectionException $e) {
090 return;
091 }
092 }
093
094 $returnType = $m->getReturnType();
095 if (null !== $returnType && !$returnType->isBuiltin()) {
096 $returnType = $returnType instanceof \ReflectionNamedType ? $returnType->getName() : (string) $returnType;
097 if (null !== $class) {
098 $declaringClass = $m->getDeclaringClass()->getName();
099 if ('self' === strtolower($returnType)) {
100 $returnType = $declaringClass;
101 } elseif ('parent' === strtolower($returnType)) {
102 $returnType = get_parent_class($declaringClass) ?: null;
103 }
104 }
105
106 if (null !== $returnType && (!isset($resolveClassPassChanges[$id]) || $returnType !== $resolveClassPassChanges[$id])) {
107 @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);
108 }
109 $definition->setClass($returnType);
110 }
111 }
112 }
113