updated-packages
This commit is contained in:
@@ -50,7 +50,7 @@ class ArgumentMetadata
|
||||
*
|
||||
* The type is the PHP class in 5.5+ and additionally the basic type in PHP 7.0+.
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
@@ -99,7 +99,7 @@ class ArgumentMetadata
|
||||
public function getDefaultValue()
|
||||
{
|
||||
if (!$this->hasDefaultValue) {
|
||||
throw new \LogicException(sprintf('Argument $%s does not have a default value. Use %s::hasDefaultValue() to avoid this exception.', $this->name, __CLASS__));
|
||||
throw new \LogicException(sprintf('Argument $%s does not have a default value. Use "%s::hasDefaultValue()" to avoid this exception.', $this->name, __CLASS__));
|
||||
}
|
||||
|
||||
return $this->defaultValue;
|
||||
|
@@ -21,20 +21,25 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createArgumentMetadata($controller)
|
||||
public function createArgumentMetadata($controller): array
|
||||
{
|
||||
$arguments = array();
|
||||
$arguments = [];
|
||||
|
||||
if (\is_array($controller)) {
|
||||
$reflection = new \ReflectionMethod($controller[0], $controller[1]);
|
||||
$class = $reflection->class;
|
||||
} elseif (\is_object($controller) && !$controller instanceof \Closure) {
|
||||
$reflection = (new \ReflectionObject($controller))->getMethod('__invoke');
|
||||
$reflection = new \ReflectionMethod($controller, '__invoke');
|
||||
$class = $reflection->class;
|
||||
} else {
|
||||
$reflection = new \ReflectionFunction($controller);
|
||||
if ($class = str_contains($reflection->name, '{closure}') ? null : $reflection->getClosureScopeClass()) {
|
||||
$class = $class->name;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($reflection->getParameters() as $param) {
|
||||
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull());
|
||||
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $class), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull());
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
@@ -42,30 +47,23 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
|
||||
|
||||
/**
|
||||
* Returns an associated type to the given parameter if available.
|
||||
*
|
||||
* @param \ReflectionParameter $parameter
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function)
|
||||
private function getType(\ReflectionParameter $parameter, ?string $class): ?string
|
||||
{
|
||||
if (!$type = $parameter->getType()) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$name = $type->getName();
|
||||
$lcName = strtolower($name);
|
||||
$name = $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
|
||||
|
||||
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;
|
||||
if (null !== $class) {
|
||||
switch (strtolower($name)) {
|
||||
case 'self':
|
||||
return $class;
|
||||
case 'parent':
|
||||
return get_parent_class($class) ?: null;
|
||||
}
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ namespace Symfony\Component\HttpKernel\ControllerMetadata;
|
||||
interface ArgumentMetadataFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $controller The controller to resolve the arguments for
|
||||
* @param string|object|array $controller The controller to resolve the arguments for
|
||||
*
|
||||
* @return ArgumentMetadata[]
|
||||
*/
|
||||
|
Reference in New Issue
Block a user