flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.6k stars 407 forks source link

[Refactor] Flight::get() need to be renamed #562

Closed ampmonteiro closed 3 months ago

ampmonteiro commented 3 months ago

Hi,

Even if you in the docs to not use Flight::get() to set a get router soon or later someone will do this mistake.

As such and to be consistent Flight::get() should be rename, for example to Flight::getKey and let to use Flight::get() be a route definition, similar to frameworks like laravel.

Flight::group('/api', function () {
  Flight::group('/v1', function () {
    // Flight::get() gets variables, it doesn't set a route! See object context below
    Flight::route('GET /users', function () {
      // Matches GET /api/v1/users
    });

    Flight::post('/posts', function () {
      // Matches POST /api/v1/posts
    });

    Flight::put('/posts/1', function () {
      // Matches PUT /api/v1/posts
    });
  });
  Flight::group('/v2', function () {

    // Flight::get() gets variables, it doesn't set a route! See object context below
    Flight::route('GET /users', function () {
      // Matches GET /api/v2/users
    });
  });
});

Thanks

n0nag0n commented 3 months ago

So I hear you. It is frustrating and I've run into it a few times myself as well. The problem is that I have to maintain backwards compatibility with the framework. In v4, we can totally do that so it's a getKey() setKey() type situation to allow for Flight::get() to be meant for a route.

Your alternative that you could do is you could call $router = Flight::router() to get the router and then you can do group(), get(), post(), etc as expected.

ampmonteiro commented 3 months ago

Hi,

ok, so please do it in the next major version.

Thanks, feel free to close the issue.