Welcome Guest, Not a member yet? Register   Sign In
Could #-attributes in PHP 8.1 be used for routes in the future?

I have no clue what I am talking about so I am just dumping my thoughts here...
I have a fairly large project in CI4.2 which is a REST backend to an admin interface written as SPA JavaScript application. The Routes.php file is starting to get very long with segments like this to manage a single object in the system:

PHP Code:
// Routes for handling Users and Employees
$routes->group('users', ['filter' => 'bearer-auth:user,empl'], function($routes) {
$routes->resource('users', ['controller' => 'Users''filter' => 'bearer-auth:user,empl']); 

Especially the filter settings are hord to remember the correct syntax. Also making sure that all possible routes are covered and maintained is getting harder and harder. Refactoring is also a nightmare.
So I thought: what if Attributes in the Controller itself could be used to describe the routes allowed in the Controller. Sort of lite auto-routes from before but with better maintainability. Example:

PHP Code:


class Users extends BaseController {

public function certificates() {
// ...

public function showcert($id) {
// ...

As you can see I don't have a clue if this is possible or not but I just wanted to put my thoughts in writing and possibly start a discussion.

Messages In This Thread
Could #-attributes in PHP 8.1 be used for routes in the future? - by tgix - 09-21-2022, 06:07 AM

Theme © iAndrew 2016 - Forum software by © MyBB