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 |
ResolveInvalidReferencesPass.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\Argument\ArgumentInterface;
015 use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
016 use Symfony\Component\DependencyInjection\ContainerBuilder;
017 use Symfony\Component\DependencyInjection\ContainerInterface;
018 use Symfony\Component\DependencyInjection\Definition;
019 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
020 use Symfony\Component\DependencyInjection\Reference;
021
022 /**
023 * Emulates the invalid behavior if the reference is not found within the
024 * container.
025 *
026 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
027 */
028 class ResolveInvalidReferencesPass implements CompilerPassInterface
029 {
030 private $container;
031 private $signalingException;
032
033 /**
034 * Process the ContainerBuilder to resolve invalid references.
035 */
036 public function process(ContainerBuilder $container)
037 {
038 $this->container = $container;
039 $this->signalingException = new RuntimeException('Invalid reference.');
040
041 try {
042 $this->processValue($container->getDefinitions(), 1);
043 } finally {
044 $this->container = $this->signalingException = null;
045 }
046 }
047
048 /**
049 * Processes arguments to determine invalid references.
050 *
051 * @throws RuntimeException When an invalid reference is found
052 */
053 private function processValue($value, $rootLevel = 0, $level = 0)
054 {
055 if ($value instanceof ServiceClosureArgument) {
056 $value->setValues($this->processValue($value->getValues(), 1, 1));
057 } elseif ($value instanceof ArgumentInterface) {
058 $value->setValues($this->processValue($value->getValues(), $rootLevel, 1 + $level));
059 } elseif ($value instanceof Definition) {
060 if ($value->isSynthetic() || $value->isAbstract()) {
061 return $value;
062 }
063 $value->setArguments($this->processValue($value->getArguments(), 0));
064 $value->setProperties($this->processValue($value->getProperties(), 1));
065 $value->setMethodCalls($this->processValue($value->getMethodCalls(), 2));
066 } elseif (\is_array($value)) {
067 $i = 0;
068
069 foreach ($value as $k => $v) {
070 try {
071 if (false !== $i && $k !== $i++) {
072 $i = false;
073 }
074 if ($v !== $processedValue = $this->processValue($v, $rootLevel, 1 + $level)) {
075 $value[$k] = $processedValue;
076 }
077 } catch (RuntimeException $e) {
078 if ($rootLevel < $level || ($rootLevel && !$level)) {
079 unset($value[$k]);
080 } elseif ($rootLevel) {
081 throw $e;
082 } else {
083 $value[$k] = null;
084 }
085 }
086 }
087
088 // Ensure numerically indexed arguments have sequential numeric keys.
089 if (false !== $i) {
090 $value = array_values($value);
091 }
092 } elseif ($value instanceof Reference) {
093 if ($this->container->has($value)) {
094 return $value;
095 }
096 $invalidBehavior = $value->getInvalidBehavior();
097
098 // resolve invalid behavior
099 if (ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) {
100 $value = null;
101 } elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $invalidBehavior) {
102 if (0 < $level || $rootLevel) {
103 throw $this->signalingException;
104 }
105 $value = null;
106 }
107 }
108
109 return $value;
110 }
111 }
112