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

@@ -23,22 +23,17 @@ use Symfony\Component\HttpFoundation\Request;
*/
class ControllerResolver implements ControllerResolverInterface
{
private $logger;
private ?LoggerInterface $logger;
public function __construct(LoggerInterface $logger = null)
{
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function getController(Request $request)
public function getController(Request $request): callable|false
{
if (!$controller = $request->attributes->get('_controller')) {
if (null !== $this->logger) {
$this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing.');
}
$this->logger?->warning('Unable to look for the controller as the "_controller" parameter is missing.');
return false;
}
@@ -48,15 +43,8 @@ class ControllerResolver implements ControllerResolverInterface
try {
$controller[0] = $this->instantiateController($controller[0]);
} catch (\Error|\LogicException $e) {
try {
// We cannot just check is_callable but have to use reflection because a non-static method
// can still be called statically in PHP but we don't want that. This is deprecated in PHP 7, so we
// could simplify this with PHP 8.
if ((new \ReflectionMethod($controller[0], $controller[1]))->isStatic()) {
return $controller;
}
} catch (\ReflectionException $reflectionException) {
throw $e;
if (\is_callable($controller)) {
return $controller;
}
throw $e;
@@ -98,11 +86,9 @@ class ControllerResolver implements ControllerResolverInterface
/**
* Returns a callable for the given controller.
*
* @return callable
*
* @throws \InvalidArgumentException When the controller cannot be created
*/
protected function createController(string $controller)
protected function createController(string $controller): callable
{
if (!str_contains($controller, '::')) {
$controller = $this->instantiateController($controller);
@@ -123,7 +109,7 @@ class ControllerResolver implements ControllerResolverInterface
if ((new \ReflectionMethod($class, $method))->isStatic()) {
return $class.'::'.$method;
}
} catch (\ReflectionException $reflectionException) {
} catch (\ReflectionException) {
throw $e;
}
@@ -139,15 +125,13 @@ class ControllerResolver implements ControllerResolverInterface
/**
* Returns an instantiated controller.
*
* @return object
*/
protected function instantiateController(string $class)
protected function instantiateController(string $class): object
{
return new $class();
}
private function getControllerError($callable): string
private function getControllerError(mixed $callable): string
{
if (\is_string($callable)) {
if (str_contains($callable, '::')) {