Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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\ContainerInterface;
015 use Symfony\Component\DependencyInjection\Reference;
016 use Symfony\Component\DependencyInjection\ContainerBuilder;
017 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
018
019 /**
020 * Emulates the invalid behavior if the reference is not found within the
021 * container.
022 *
023 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
024 */
025 class ResolveInvalidReferencesPass implements CompilerPassInterface
026 {
027 private $container;
028
029 /**
030 * Process the ContainerBuilder to resolve invalid references.
031 *
032 * @param ContainerBuilder $container
033 */
034 public function process(ContainerBuilder $container)
035 {
036 $this->container = $container;
037 foreach ($container->getDefinitions() as $definition) {
038 if ($definition->isSynthetic() || $definition->isAbstract()) {
039 continue;
040 }
041
042 $definition->setArguments(
043 $this->processArguments($definition->getArguments())
044 );
045
046 $calls = array();
047 foreach ($definition->getMethodCalls() as $call) {
048 try {
049 $calls[] = array($call[0], $this->processArguments($call[1], true));
050 } catch (RuntimeException $e) {
051 // this call is simply removed
052 }
053 }
054 $definition->setMethodCalls($calls);
055
056 $properties = array();
057 foreach ($definition->getProperties() as $name => $value) {
058 try {
059 $value = $this->processArguments(array($value), true);
060 $properties[$name] = reset($value);
061 } catch (RuntimeException $e) {
062 // ignore property
063 }
064 }
065 $definition->setProperties($properties);
066 }
067 }
068
069 /**
070 * Processes arguments to determine invalid references.
071 *
072 * @param array $arguments An array of Reference objects
073 * @param bool $inMethodCall
074 *
075 * @return array
076 *
077 * @throws RuntimeException When the config is invalid
078 */
079 private function processArguments(array $arguments, $inMethodCall = false)
080 {
081 foreach ($arguments as $k => $argument) {
082 if (is_array($argument)) {
083 $arguments[$k] = $this->processArguments($argument, $inMethodCall);
084 } elseif ($argument instanceof Reference) {
085 $id = (string) $argument;
086
087 $invalidBehavior = $argument->getInvalidBehavior();
088 $exists = $this->container->has($id);
089
090 // resolve invalid behavior
091 if (!$exists && ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) {
092 $arguments[$k] = null;
093 } elseif (!$exists && ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $invalidBehavior) {
094 if ($inMethodCall) {
095 throw new RuntimeException('Method shouldn\'t be called.');
096 }
097
098 $arguments[$k] = null;
099 }
100 }
101 }
102
103 return $arguments;
104 }
105 }
106