anandkunal / ToroPHP

Toro is a PHP router for developing RESTful web applications and APIs.
http://toroweb.org
MIT License
1.17k stars 173 forks source link

Passing 2 parameters with a default value for the first (optional) parameter #102

Closed MonkeyTime closed 3 years ago

MonkeyTime commented 3 years ago

Hi,

I have a problem with the default value of the first parameter with 2 paramaters defined.

When the first parameter is optional and have a default value Toro seems to not working

class VendorHandler {

    function get($languri = 'fr-be', $vendor) {

        include (CONTROLLER_PATH . '/vendor/Get.php');
    }
}

Toro::serve(array(
    '/?([a-z]{2,2}-[a-z]{2,2})?/vendor/([a-zA-Z0-9-_]+)' => 'VendorHandler'
));

Toro.php line 35

if (preg_match('#^/?' . $pattern . '/?$#', $path_info, $matches)) not matched and no default value because builded on pathinfo.

Toro.php line 69

$regex_matches

How to change this or retrieve the default parameter ?

martinbean commented 3 years ago

Optional parameters should always be at the end of a function’s argument list in PHP (or any language, really).