TypeRocket / typerocket

TypeRocket is a highly integrated MVC WordPress framework with beautiful UI components for the modern developer.

Home Page:https://typerocket.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Routes matching query string

matteo-greco opened this issue · comments

Hello,

I'm trying to write some redirects for an old website that had a bunch of "filename.php?id=123" URL. I tried matching them like this:

tr_route()
->get()
->noTrailingSlash()
->match( '/test/filename.php\?id=(.*)', [ 'id' ] )
->do(
	function( $id ) {
		return 'Gotcha! ' . $id;
	}
);

However, this wouldn't work. Digging through the code, I found out that the Routes class only matches on the URL path, not the full URI, so it leaves out the query string. So I made the following change

# typerocket\vendor\typerocket\core\src\Http\Routes.php
public function detectRoute()
{
    // $path = self::$request->getPath();
    $path = self::$request->getUri();
    ...

And now my route matches as I was hoping.

Is there a reason why this isn't the standard behavior of the framework? Does my change risk breaking anything?

Hey @matteo-greco

What you are doing shouldn't break anything. I may add this into core as an option to enable.

Hey @matteo-greco

I'm adding a filter to help with your use case.

# typerocket\vendor\typerocket\core\src\Http\Routes.php
public function detectRoute()
{
    ....
    $requestPath = apply_filters('tr_routes_path', $requestPath );