alexdodonov / mezon-router

Small and fast router
https://twitter.com/mezonphp
267 stars 18 forks source link

fetchActions only for GET? #19

Closed FLasH3r closed 3 years ago

FLasH3r commented 3 years ago

Why does fetchActions creates the same route for GET & POST? Is there a way to disable this behavior?

    public function fetchActions(object $object): void
    {
        $methods = get_class_methods($object);

        foreach ($methods as $method) {
            if (strpos($method, 'action') === 0) {
                $route = Utils::convertMethodNameToRoute($method);
                $this->addGetRoute($route, $object, $method);
                $this->addPostRoute($route, $object, $method);
            }
        }
    }
alexdodonov commented 3 years ago

@FLasH3r Hi!

Now you can specify the behaviour of this method. This is the example:

$router->fetchActions($mySite = new MySite(), [
    'Index' => 'GET',
    'Contacts' => 'POST',
    'Faq' => ['GET', 'POST'],
]);

Hope it was helpfull )

Do you have any other feature requests?

FLasH3r commented 3 years ago

That works for me, thanks :-)