[CORE][Controller] Add default handler for when using http methods

This commit is contained in:
Diogo Peralta Cordeiro 2022-03-23 13:19:51 +00:00
parent 2f7fdf6ee4
commit 259d2da05a
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 16 additions and 4 deletions

View File

@ -51,7 +51,7 @@ class OEmbed extends Controller
/** /**
* Handle OEmbed server requests * Handle OEmbed server requests
*/ */
protected function handle(Request $request) public function handle(Request $request)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
// $url = $this->trimmed('url'); // $url = $this->trimmed('url');

View File

@ -81,9 +81,9 @@ abstract class Controller extends AbstractController implements EventSubscriberI
*/ */
public function __invoke(Request $request) public function __invoke(Request $request)
{ {
$class = static::class; $class = static::class;
$method = 'on' . ucfirst(mb_strtolower($request->getMethod())); $method = 'on' . ucfirst(mb_strtolower($request->getMethod()));
$attributes = array_diff_key($request->attributes->get('_route_params'), array_flip(['_format', '_fragment', '_locale', 'template', 'accept', 'is_system_path'])); $attributes = array_diff_key($request->attributes->get('_route_params'), array_flip(['_format', '_fragment', '_locale', 'template', 'accept', 'is_system_path']));
if (method_exists($class, $method)) { if (method_exists($class, $method)) {
return $this->{$method}($request, ...$attributes); return $this->{$method}($request, ...$attributes);
} }
@ -91,6 +91,18 @@ abstract class Controller extends AbstractController implements EventSubscriberI
return $this->handle($request, ...$attributes); return $this->handle($request, ...$attributes);
} }
public function handle(Request $request)
{
$class = static::class;
$method = 'on' . ucfirst(mb_strtolower($request->getMethod()));
if (method_exists($class, $method)) {
return $this->{$method}($request);
}
$attributes = array_diff_key($request->attributes->get('_route_params'), array_flip(['_format', '_fragment', '_locale', 'template', 'accept', 'is_system_path']));
return $this->handle($request, ...$attributes);
}
/** /**
* Symfony event when it's searching for which controller to use * Symfony event when it's searching for which controller to use
*/ */