New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal of compact syntax for Flight::route #579
Comments
Technically it seems like Flight::group, but it's for one controller |
I like where you're going with this. I'm not sure if an array is the best way to assign the methods, or if those methods should be automatically assumed.....or maybe both? If you assign them it will follow how you assign them, but if you don't it will assume a standard. And maybe you could override just one of the methods if you wanted? Just thinking out loud. |
If you only assign 3 methods with their respective controller methods, the rest could be assumed but only if those methods are defined in the controller |
So suppose I define to |
I think the use case is pretty good and the API is pretty easy to master. You have an api in Spanish, and you only need the GET / and the POST / mapped to listAll and handleSave Flight will see that there is no POST / definition to the store method, but since it is not defined it does not add it Using a resource controller would be as simple as Flight::route('/users', UserController::class); // UserController.php
class UserController {
function __construct(MyDependency $dep) {}
function index(): void {}
function show(string $id): void {}
function create(): void {}
function store(): void {}
function edit(string $id): void {}
function update(string $id): void {}
function delete(string $id): void {}
} |
I can get behind that. If you just define a controller then it will add those 7 routes by default. |
Here is another example of the requested behavior Flight::route('/posts', PostController::class); class PostController {
static function index(): void {}
static function show(string $id): void {}
} Flight will define the following routes: [
'GET /' => 'PostController::index',
'GET /@id' => 'PostController::show'
] |
This is an alternative of Resource controllers, for people like me that name routes in spanish but controllers in english (for cohesion)
The text was updated successfully, but these errors were encountered: