This commit is contained in:
xl
2024-08-29 13:43:45 +08:00
parent 1795b59b88
commit be1badfa5c
2 changed files with 38 additions and 30 deletions
+5 -27
View File
@@ -42,40 +42,18 @@ class Handler implements RequestHandlerInterface
protected ContainerInterface $container;
/**
* @var array
*/
protected array $parameters;
/**
* @param array|Closure $handler
* @param ReflectionMethod|ReflectionFunction $parameter
* @param array $parameters
* @param string|null $parameter
*/
public function __construct(public array|Closure $handler, ReflectionMethod|ReflectionFunction $parameter)
public function __construct(public array|Closure $handler, public array $parameters, ?string $parameter)
{
if ($parameter->getReturnType() != null) {
$this->format = Kiri::getDi()->get($this->returnType($parameter));
if ($parameter !== null) {
$this->format = Kiri::getDi()->get($parameter);
} else {
$this->format = Kiri::getDi()->get(MixedFormat::class);
}
$this->parameters = Kiri::getDi()->getMethodParams($parameter);
}
/**
* @param ReflectionMethod $reflectionType
* @return string
*/
protected function returnType(ReflectionMethod $reflectionType): string
{
return match ($reflectionType->getReturnType()->getName()) {
'array' => ArrayFormat::class,
'mixed', 'object' => MixedFormat::class,
'int', 'string', 'bool' => OtherFormat::class,
'void' => VoidFormat::class,
default => ResponseFormat::class
};
}