package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -28,25 +28,34 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
*/
final class ControllerArgumentsEvent extends KernelEvent
{
private $controller;
private $arguments;
private ControllerEvent $controllerEvent;
private array $arguments;
private array $namedArguments;
public function __construct(HttpKernelInterface $kernel, callable $controller, array $arguments, Request $request, ?int $requestType)
public function __construct(HttpKernelInterface $kernel, callable|ControllerEvent $controller, array $arguments, Request $request, ?int $requestType)
{
parent::__construct($kernel, $request, $requestType);
$this->controller = $controller;
if (!$controller instanceof ControllerEvent) {
$controller = new ControllerEvent($kernel, $controller, $request, $requestType);
}
$this->controllerEvent = $controller;
$this->arguments = $arguments;
}
public function getController(): callable
{
return $this->controller;
return $this->controllerEvent->getController();
}
public function setController(callable $controller)
/**
* @param array<class-string, list<object>>|null $attributes
*/
public function setController(callable $controller, array $attributes = null): void
{
$this->controller = $controller;
$this->controllerEvent->setController($controller, $attributes);
unset($this->namedArguments);
}
public function getArguments(): array
@@ -57,5 +66,38 @@ final class ControllerArgumentsEvent extends KernelEvent
public function setArguments(array $arguments)
{
$this->arguments = $arguments;
unset($this->namedArguments);
}
public function getNamedArguments(): array
{
if (isset($this->namedArguments)) {
return $this->namedArguments;
}
$namedArguments = [];
$arguments = $this->arguments;
foreach ($this->controllerEvent->getControllerReflector()->getParameters() as $i => $param) {
if ($param->isVariadic()) {
$namedArguments[$param->name] = \array_slice($arguments, $i);
break;
}
if (\array_key_exists($i, $arguments)) {
$namedArguments[$param->name] = $arguments[$i];
} elseif ($param->isDefaultvalueAvailable()) {
$namedArguments[$param->name] = $param->getDefaultValue();
}
}
return $this->namedArguments = $namedArguments;
}
/**
* @return array<class-string, list<object>>
*/
public function getAttributes(): array
{
return $this->controllerEvent->getAttributes();
}
}