From bd45fb25660b934f5b1f896bac62f573621cb0a1 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Sun, 9 Aug 2015 07:26:12 +0000 Subject: [PATCH] route : add the 'multi' method to allow multiple methods to be applied to the same route and function git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2225 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- route.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/route.php b/route.php index f2efd14..79e467e 100644 --- a/route.php +++ b/route.php @@ -344,6 +344,22 @@ class route return $this->map ($route, $function); } + /** Allow multiple methods to execute the function if the route is + corresponding to the URL. + Ex. : $app->multi("get,post,put,delete", '/hello/{name}', function ($name) { + echo "Hello, $name"; + }); + @param string $methods The allowed methods, separated by commas (,) + @param string $route Route to check with the URL + @param function $function Function to be executed if the route match */ + public function multi ($methods, $route, $function) + { + foreach (explode (",", $methods) as $method) + { + $this->$method ($route, $function); + } + } + /** Do the mapping between the url and the route : call the function if thereis a match @param string $route Route to check with the URL