Procházet zdrojové kódy

[CORE][Controller] Make Controller abstract, `handle` an optional non static method and use `static::class` rather than `get_called_class`

remotes/upstream/experimental
Hugo Sales před 1 rokem
rodič
revize
2d8b220e92
Podepsáno: someonewithpc <hugo@hsal.es> ID GPG klíče: 7D0C7EAFC9D835A0
1 změnil soubory, kde provedl 6 přidání a 5 odebrání
  1. +6
    -5
      src/Core/Controller.php

+ 6
- 5
src/Core/Controller.php Zobrazit soubor

@@ -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);
}
}



Načítá se…
Zrušit
Uložit