yiisoft / router

Router is a request matcher and URL generator
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
59 stars 24 forks source link

Inconsistent \Yiisoft\Router\CurrentRoute #188

Open xepozz opened 1 year ago

xepozz commented 1 year ago

Due to \Yiisoft\Router\CurrentRoute doesn't have any restrictions it may be created with $container->get(), but it has whole empty state:

image

It's unexpected and cause lots of if's over it. Isn't it better to add RouteProvider with the getCurrent() method that will return either CurrentRoute or Route or throw an exception because it wasn't set before?

vjik commented 1 year ago

Returns CurrentRoute|Route is confused.

By fact, CurrentRoute is RouteProvider.

xepozz commented 1 year ago

It's not a provider by design.