mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 15:34:12 +01:00
Package operations: 2 installs, 23 updates, 0 removals - Updating psr/log (1.1.0 => 1.1.2) - Updating symfony/debug (v3.4.30 => v3.4.35) - Updating symfony/console (v3.4.30 => v3.4.35) - Updating symfony/dotenv (v3.4.30 => v3.4.35) - Updating symfony/routing (v3.4.30 => v3.4.35) - Updating symfony/finder (v3.4.30 => v3.4.35) - Updating symfony/filesystem (v3.4.30 => v3.4.35) - Installing symfony/polyfill-util (v1.12.0) - Installing symfony/polyfill-php56 (v1.12.0) - Updating symfony/http-foundation (v3.4.30 => v3.4.35) - Updating symfony/event-dispatcher (v3.4.30 => v3.4.35) - Updating symfony/http-kernel (v3.4.30 => v3.4.35) - Updating symfony/config (v3.4.30 => v3.4.35) - Updating symfony/dependency-injection (v3.4.30 => v3.4.35) - Updating symfony/class-loader (v3.4.30 => v3.4.35) - Updating symfony/cache (v3.4.30 => v3.4.35) - Updating symfony/framework-bundle (v3.4.30 => v3.4.35) - Updating twig/twig (v1.42.2 => v1.42.4) - Updating symfony/twig-bridge (v3.4.30 => v3.4.35) - Updating symfony/twig-bundle (v3.4.30 => v3.4.35) - Updating symfony/yaml (v3.4.30 => v3.4.35) - Updating symfony/stopwatch (v3.4.30 => v3.4.35) - Updating symfony/var-dumper (v3.4.30 => v3.4.35) - Updating symfony/web-profiler-bundle (v3.4.30 => v3.4.35) - Updating symfony/css-selector (v3.4.30 => v3.4.35)
136 lines
3.9 KiB
PHP
136 lines
3.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* 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 <kjarli@gmail.com>
|
|
*/
|
|
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 = [];
|
|
|
|
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.
|
|
*
|
|
* @return bool
|
|
*/
|
|
private function isVariadic(\ReflectionParameter $parameter)
|
|
{
|
|
return $this->supportsVariadic && $parameter->isVariadic();
|
|
}
|
|
|
|
/**
|
|
* Determines whether an argument has a default value.
|
|
*
|
|
* @return bool
|
|
*/
|
|
private function hasDefaultValue(\ReflectionParameter $parameter)
|
|
{
|
|
return $parameter->isDefaultValueAvailable();
|
|
}
|
|
|
|
/**
|
|
* Returns a default value if available.
|
|
*
|
|
* @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.
|
|
*
|
|
* @return string|null
|
|
*/
|
|
private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function)
|
|
{
|
|
if ($this->supportsParameterType) {
|
|
if (!$type = $parameter->getType()) {
|
|
return null;
|
|
}
|
|
$name = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString();
|
|
if ('array' === $name && !$type->isBuiltin()) {
|
|
// Special case for HHVM with variadics
|
|
return null;
|
|
}
|
|
} elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $parameter, $name)) {
|
|
$name = $name[1];
|
|
} else {
|
|
return null;
|
|
}
|
|
$lcName = strtolower($name);
|
|
|
|
if ('self' !== $lcName && 'parent' !== $lcName) {
|
|
return $name;
|
|
}
|
|
if (!$function instanceof \ReflectionMethod) {
|
|
return null;
|
|
}
|
|
if ('self' === $lcName) {
|
|
return $function->getDeclaringClass()->name;
|
|
}
|
|
if ($parent = $function->getDeclaringClass()->getParentClass()) {
|
|
return $parent->name;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|