GX-Feature #70204
geschlossenImplement registration of routes with php attribute in addition to routes.php
0%
Beschreibung
One of php8.0 new features are the attributes. With which custom information can be parsed more easily. Frameworks like Symphony use this to register methods of controller classes to a specific route.
This should also be possible for our action classes. Instead of mapping a class in a dedicated routes.php this example code should also be valid
declare(strict_types=1);
namespace Gambio\Api\Modules\Customer\Submodules\Memos\App\Actions;
use Gambio\Core\Application\Http\Request;
use Gambio\Core\Application\Http\Response;
use Gambio\Core\Application\Routing\Attribute\Route;
/**
* Class TestRouteWithAttribute
*
* @package Gambio\Api\Modules\Customer\Submodules\Memos\App\Actions
*/
#[Route('/api.php/v3/test-attributes', 'GET')]
class TestRouteWithAttribute
{
/**
* @param Request $request
* @param Response $response
* @param array $args
*
* @return Response
*/
public function __invoke(Request $request, Response $response, array $args): Response
{
return $response->withJson(['success' => 1]);
}
}
This would also make it easier to see the exact route is assigned to an action without needing to look it up in the routes.php
Checkliste 0/0
Von Marvin Muxfeld vor mehr als 2 Jahren aktualisiert
- Status wurde von In Bearbeitung zu Feedback geändert
- Zugewiesen an wurde von Marvin Muxfeld zu Tobias Schindler geändert
Von Tobias Schindler vor mehr als 2 Jahren aktualisiert
- Status wurde von Feedback zu Abgewiesen geändert
We come to a conclusion, that we don't implement support for routes as PHP-Attribute.
The first reason is consistency. All routes are implemented similarly by using the routes.php
in the module directory. This also makes tooling easier. Another reason is control. By injecting the RouteCollector
, the function callback is more flexible than attributes, for example by adding middleware and routing groups