thecodeholic / tc-php-mvc-core

103 stars 30 forks source link

Added findRoute() method to Router class #4

Closed virtual-designer closed 5 months ago

virtual-designer commented 2 years ago

Think that our public/index.php file looks like this:

<?php
//...

$app->router->get('/test', [SiteController::class, 'test']);

//...

And now if we try to access route /test with method POST, then it will return 404 Not Found, which is not very good status for this case. The router should return 405 Method Not Allowed instead.

In this commit, I've added a method findRoute() which finds a route, and returns the route action, method and the URI.

@thecodeholic

RehabCZ commented 1 year ago

Well it seems to have some problems with routes that includes params for ex. '/user/{username}' it will still throw not found