thephpleague / route

Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.
http://route.thephpleague.com
MIT License
651 stars 126 forks source link

assign value to Route $path protected property #192

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi, is there any chance you implement a setter method for a protected property '$path' in Route class?

I would like to implement a route path localization based on desired language, but I cannot override protected property path (ie. en path "/en/home" .... sl path: "/sl/domov")? All route data stays the same (name, callable, ... ) except for a path, which I would like to change dynamically.

Please help me with a better approach or if it makes sense I can prepare PR?

Br, K

philipobenito commented 6 years ago

I still don't think that solves your problem.

If your route paths were the same but only the locale was changing I'd suggest a wildcard.

$route->get('/{locale}/home', 'Controller::method');

Then you could determine the locale in your controller or some type of abstraction.

But because the language of the path also changes, I'd suggest defining multiple routes that point to the same controller.

$route->get('/en/home', 'Controller::method');
$route->get('/sl/domov', 'Controller::method');