Projekt

Allgemein

Aktionen

GX-Feature #70204

geschlossen

Implement registration of routes with php attribute in addition to routes.php

Von Marvin Muxfeld vor mehr als 2 Jahren hinzugefügt. Vor mehr als 2 Jahren aktualisiert.

Status:
Abgewiesen
Priorität:
Normal
Zugewiesen an:
Tobias Schindler
Kategorie:
REST-API
Zielversion:
-
% erledigt:

0%

Geschätzter Aufwand:
Steps to reproduce:
Betroffene Versionen:
Unbestimmt
Release Notes Langtext:

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

Aktionen #1

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
Aktionen #3

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

Aktionen