From 2d8b220e92e1e6f5eb4ffb9e765e469f92141ecf Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Mon, 27 Sep 2021 10:36:48 +0100 Subject: [PATCH] [CORE][Controller] Make Controller abstract, `handle` an optional non static method and use `static::class` rather than `get_called_class` --- src/Core/Controller.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Core/Controller.php b/src/Core/Controller.php index baa4a4ea2a..63c116f121 100644 --- a/src/Core/Controller.php +++ b/src/Core/Controller.php @@ -51,8 +51,9 @@ use Symfony\Component\Validator\Exception\ValidatorException; * @method int int(string $param) * @method bool bool(string $param) * @method string string(string $param) + * @method mixed handle(Request $request, mixed ...$extra) */ -class Controller extends AbstractController implements EventSubscriberInterface +abstract class Controller extends AbstractController implements EventSubscriberInterface { private array $vars = []; protected ?Request $request = null; @@ -70,13 +71,13 @@ class Controller extends AbstractController implements EventSubscriberInterface public function __invoke(Request $request) { $this->request = $request; - $class = get_called_class(); + $class = static::class; $method = 'on' . ucfirst(strtolower($request->getMethod())); - $attributes = array_diff_key($request->attributes->get('_route_params'), array_flip(['_format', '_fragment', '_locale', 'template', 'accept'])); + $attributes = array_diff_key($request->attributes->get('_route_params'), array_flip(['_format', '_fragment', '_locale', 'template', 'accept', 'is_system_path'])); if (method_exists($class, $method)) { - return $class::$method($request, ...$attributes); + return $this->{$method}($request, ...$attributes); } else { - return $class::handle($request, ...$attributes); + return $this->handle($request, ...$attributes); } }