* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpKernel\ControllerMetadata; /** * Builds {@see ArgumentMetadata} objects based on the given Controller. * * @author Iltar van der Berg */ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface { /** * If the ...$arg functionality is available. * * Requires at least PHP 5.6.0 or HHVM 3.9.1 * * @var bool */ private $supportsVariadic; /** * If the reflection supports the getType() method to resolve types. * * Requires at least PHP 7.0.0 or HHVM 3.11.0 * * @var bool */ private $supportsParameterType; public function __construct() { $this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic'); $this->supportsParameterType = method_exists('ReflectionParameter', 'getType'); } /** * {@inheritdoc} */ public function createArgumentMetadata($controller) { $arguments = array(); if (is_array($controller)) { $reflection = new \ReflectionMethod($controller[0], $controller[1]); } elseif (is_object($controller) && !$controller instanceof \Closure) { $reflection = (new \ReflectionObject($controller))->getMethod('__invoke'); } else { $reflection = new \ReflectionFunction($controller); } foreach ($reflection->getParameters() as $param) { $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $this->isVariadic($param), $this->hasDefaultValue($param), $this->getDefaultValue($param), $param->allowsNull()); } return $arguments; } /** * Returns whether an argument is variadic. * * @param \ReflectionParameter $parameter * * @return bool */ private function isVariadic(\ReflectionParameter $parameter) { return $this->supportsVariadic && $parameter->isVariadic(); } /** * Determines whether an argument has a default value. * * @param \ReflectionParameter $parameter * * @return bool */ private function hasDefaultValue(\ReflectionParameter $parameter) { return $parameter->isDefaultValueAvailable(); } /** * Returns a default value if available. * * @param \ReflectionParameter $parameter * * @return mixed|null */ private function getDefaultValue(\ReflectionParameter $parameter) { return $this->hasDefaultValue($parameter) ? $parameter->getDefaultValue() : null; } /** * Returns an associated type to the given parameter if available. * * @param \ReflectionParameter $parameter * * @return null|string */ private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function) { if ($this->supportsParameterType) { if (!$type = $parameter->getType()) { return; } $name = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString(); if ('array' === $name && !$type->isBuiltin()) { // Special case for HHVM with variadics return; } } elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $parameter, $name)) { $name = $name[1]; } else { return; } $lcName = strtolower($name); if ('self' !== $lcName && 'parent' !== $lcName) { return $name; } if (!$function instanceof \ReflectionMethod) { return; } if ('self' === $lcName) { return $function->getDeclaringClass()->name; } if ($parent = $function->getDeclaringClass()->getParentClass()) { return $parent->name; } } } __halt_compiler();----SIGNATURE:----WXuFxDN4IJpnzM7tW48znNwMVUdAwRX+9KeEuJbaO6IeZwmkzWkfLoExheWCl2q4kXOKA/GwJczFAWXcV7+V6xatHd3rftscCizWa1tBWheKNRzRILWCKhUQu3oCSIJMJfbclVLvmSspISAaF/L6+NmromyCFUUcYccM4f/tIK7qs6yZxkNL920AnEWhUiCOUn0B88IAbEuhB3g7BIsdYzDCv3nfLP8k/jUHJVQlAxPTrUkzmMIvFBr69xjjDXXdreN3JBf/xsnpVs7tEitSym5JjbcElf7htwJbycl1HzyySuRudd3IUceiEk2SOyFLf7OIbL0h0W8I5Q2ac3af/UYeMjnPTcR7jo5ypHOjYAdgYni0I2pB5V/HYrwNdFLPVmU8Mf77TH+zGcYTYzSUo/aGacNXCN+Pm/me/c7h3AppATfYKha+K2xGuviwmQ7V0RDSdyvenUGJj4x3awFK45SVU2tb6JYroJT4j01aU8wUMVgx+k9mtXrW9ZWb0qEsPSBoRJdI1HGVpJ5X1PfMNm9+sjudHngUli+w6cDaKDPsUtTIs12q4bXgOTbGsoxrIsSc3+QZaiLST4fe0ZYaxH/7wZQoxCuRyQ/QLX4UlZvvDTvo5ItYdYhOxyybEvQgzWc5mxXAotYzHKUUXrlDcGDIwgolnAsGLZ4cGi77VuI=----ATTACHMENT:----NjQ5NTI3Mzk0MDUyMzk5NiA2MDgzMjA5OTUxMTIzNTExIDQzNTM3OTIxMjgwMjM2Mzk=