flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.61k stars 407 forks source link

Route alias and phpstan updates #510

Closed n0nag0n closed 6 months ago

n0nag0n commented 6 months ago

Added the ability to set an alias and to rehydrate a url

n0nag0n commented 6 months ago

@krmu Thanks so much for the feedback! I haven't used this as heavily as some of you other devs out there. I didn't go back and catch optional params so I can build tests against that and figure out why it's not working on group and unit test against that.

krmu commented 6 months ago

Thank you for fixing aliases, now we have another issue with params that has numbers inside. Code:

Flight::route('/homepage(/@param1)', function ($param1) {
    echo 'Homepage';
},false,$alias = 'homepage');
Flight::start();
echo "Url:". Flight::getUrl('homepage',array('param1'=>'test'));

Response: Url:/homepage/1)

n0nag0n commented 6 months ago

@krmu Ok I have grouping fixed and tested against (with your very example) and I fixed the params with numbers in them. I noticed that earlier, but I wasn't sure if numbers were valid as url params. Whelp, they are now :D

n0nag0n commented 6 months ago

P.S. You could hop in the chat room if you ever wanted to discuss anything. I usually keep that tab open on my computer. Chat room link is on the Readme

krmu commented 6 months ago

Im not sure, but seems that it still wont work. Currently not even allowing to get simple url.

n0nag0n commented 6 months ago

Possibly??? This is me statically calling getUrl() just fine. image

And it definitely is a mapped method.

image

krmu commented 6 months ago

Everything works, my bad. Sorry for that. So currently this monster from:

Flight::group('/user', function () {
    Flight::group('/all_users', function () {
        Flight::group('/check_user', function () {
            Flight::group('/check_one', function () {
                Flight::route("/normalpath", function () {
                    echo "normalpath";
                },false,"normalpathalias");
            });
        });
    });
});

Converts into:

normalpath/user/all_users/check_user/check_one/normalpath

So it works.

krmu commented 6 months ago

Also numbered params works.

n0nag0n commented 6 months ago

k, I just need to add some docs to the readme and then it looks like this can go live and be versioned.