PHP-Router icon indicating copy to clipboard operation
PHP-Router copied to clipboard

Skip dispatch after match

Open fitdev-pro opened this issue 7 years ago • 4 comments

  • PHPRouter version: 1.2.0-alpha
  • PHP version: PHP 7.1:
  • Exact steps to cause this issue
    1. I configured RouteCollection
    2. I run method matchCurrentRequest on Router
  • What you expected
    • I expected to get all information about route and use this information in other middleware using psr 15
  • What happened instead
    • Router create controller object and run the action

Is it possible to turn of run method dispatch() after find route by configuration flag.

fitdev-pro avatar Jun 05 '17 20:06 fitdev-pro

It would be great ! it reminds me a feature request here : #115 .

I have a private fork with a simple mecanism, i could make a pull request on this if owners change their minds.

lpotherat avatar Jun 06 '17 07:06 lpotherat

@lpotherat please do it, send a PR.

malukenho avatar Jun 06 '17 09:06 malukenho

PR made here #121 . It is a simple implementation that fit my needs, it may be enhanced.

lpotherat avatar Jun 09 '17 11:06 lpotherat

As to avoid touching the lib and keeping it detached from the project and maintained via composer i have created this little wrapper to fit my functionality in a little dirty clever way so i can get the url in the middle of the request process instead of after the request process. A neat improvement would be to have ALL the request information available as a Router->getRequestInfo method or something like that.

Having it returned after the full request has been processed is nice and all, but is information you might need in the middle of the process more that at the end.

Here is my little code: https://gist.github.com/animalillo/e395beed4919a4325c8fdb26b7803e84

Another nice feature would be to set a base namespace for all the classes that run your routes and don't have to repeat the namespace for every route.

animalillo avatar Jan 03 '18 15:01 animalillo