yiisoft / yii-web

Yii web components
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
78 stars 46 forks source link

Middlewares in route annotations #277

Open xepozz opened 4 years ago

xepozz commented 4 years ago

I think it would be great to have this feature.


/**
 * @Middleware\IpFilter("127.0.0.1")
 * @Middleware\JsonParser()
 * @Middleware\ResponseDataFormatter("json")
 * @Middleware\Autologin()
 */
public function action()
{
    return $response
}
samdark commented 4 years ago
  1. Collecting annotations runtime is performance killer.
  2. We don't want to introduce container compiler pass since it complicates development and container itself significantly.
  3. There won't be a single place to define your routes.
xepozz commented 4 years ago

Collecting annotations runtime is performance killer.

It doesn't matter for long-running applications

We don't want to introduce container compiler pass since it complicates development and container itself significantly.

I think this will be a necessary measure, otherwise you will have to give up a lot of amenities. I suggest to find out the opinion of the developers (for example, by voting on the forum).

There won't be a single place to define your routes.

Too much developers likes annotations (hello PHP 8 attributes). Annotations/attributes is preferable way to configure routes.

samdark commented 4 years ago

It doesn't matter for long-running applications

Correct but main usage of the framework won't be long running applications.

samdark commented 4 years ago

Technically that would be

  1. General purpose annotation collector that, given a list of directories will scan for annotations.
  2. For runtime it can be router-specific annotation collector that calls addRoute(). That could be used in an event handler bound to ApplicationStartup event.
  3. For production it can be a console command that will collect routes and dump them into config/routes.php.
samdark commented 4 years ago

Will wait for more requests for the feature.