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 |
ArgumentMetadataFactory.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\HttpKernel\ControllerMetadata;
013
014 /**
015 * Builds {@see ArgumentMetadata} objects based on the given Controller.
016 *
017 * @author Iltar van der Berg <kjarli@gmail.com>
018 */
019 final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
020 {
021 /**
022 * If the ...$arg functionality is available.
023 *
024 * Requires at least PHP 5.6.0 or HHVM 3.9.1
025 *
026 * @var bool
027 */
028 private $supportsVariadic;
029
030 /**
031 * If the reflection supports the getType() method to resolve types.
032 *
033 * Requires at least PHP 7.0.0 or HHVM 3.11.0
034 *
035 * @var bool
036 */
037 private $supportsParameterType;
038
039 public function __construct()
040 {
041 $this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
042 $this->supportsParameterType = method_exists('ReflectionParameter', 'getType');
043 }
044
045 /**
046 * {@inheritdoc}
047 */
048 public function createArgumentMetadata($controller)
049 {
050 $arguments = [];
051
052 if (\is_array($controller)) {
053 $reflection = new \ReflectionMethod($controller[0], $controller[1]);
054 } elseif (\is_object($controller) && !$controller instanceof \Closure) {
055 $reflection = (new \ReflectionObject($controller))->getMethod('__invoke');
056 } else {
057 $reflection = new \ReflectionFunction($controller);
058 }
059
060 foreach ($reflection->getParameters() as $param) {
061 $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $this->isVariadic($param), $this->hasDefaultValue($param), $this->getDefaultValue($param), $param->allowsNull());
062 }
063
064 return $arguments;
065 }
066
067 /**
068 * Returns whether an argument is variadic.
069 *
070 * @return bool
071 */
072 private function isVariadic(\ReflectionParameter $parameter)
073 {
074 return $this->supportsVariadic && $parameter->isVariadic();
075 }
076
077 /**
078 * Determines whether an argument has a default value.
079 *
080 * @return bool
081 */
082 private function hasDefaultValue(\ReflectionParameter $parameter)
083 {
084 return $parameter->isDefaultValueAvailable();
085 }
086
087 /**
088 * Returns a default value if available.
089 *
090 * @return mixed|null
091 */
092 private function getDefaultValue(\ReflectionParameter $parameter)
093 {
094 return $this->hasDefaultValue($parameter) ? $parameter->getDefaultValue() : null;
095 }
096
097 /**
098 * Returns an associated type to the given parameter if available.
099 *
100 * @return string|null
101 */
102 private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function)
103 {
104 if ($this->supportsParameterType) {
105 if (!$type = $parameter->getType()) {
106 return null;
107 }
108 $name = $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
109 if ('array' === $name && !$type->isBuiltin()) {
110 // Special case for HHVM with variadics
111 return null;
112 }
113 } elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $parameter, $name)) {
114 $name = $name[1];
115 } else {
116 return null;
117 }
118 $lcName = strtolower($name);
119
120 if ('self' !== $lcName && 'parent' !== $lcName) {
121 return $name;
122 }
123 if (!$function instanceof \ReflectionMethod) {
124 return null;
125 }
126 if ('self' === $lcName) {
127 return $function->getDeclaringClass()->name;
128 }
129 if ($parent = $function->getDeclaringClass()->getParentClass()) {
130 return $parent->name;
131 }
132
133 return null;
134 }
135 }
136