From 347b6a4b56e6cb97548ae322f463df852f176b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Plusquellec?= Date: Sat, 11 Feb 2017 10:11:19 +0100 Subject: [PATCH] middleware --- lib/arrays.php | 2 +- lib/routes.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/arrays.php b/lib/arrays.php index 16699a8..80e4ffd 100644 --- a/lib/arrays.php +++ b/lib/arrays.php @@ -19,7 +19,7 @@ public static function makeResourceWithName($name, array $array = []) self::$resources[$name] = $resource; - return $this; + return $resource; } public static function makeFromResourceName($name, $default = [], $unserialize = true) diff --git a/lib/routes.php b/lib/routes.php index 4be6b85..5891901 100644 --- a/lib/routes.php +++ b/lib/routes.php @@ -208,13 +208,17 @@ public static function __callStatic($m, $a) return $route->setName($name); }); + $route->macro('middleware', function (callable $cb) use ($route) { + return $route->setMiddleware($cb); + }); + $route->macro('uses', function ($string) use ($route) { if (fnmatch('*@*', $string)) { list($controller, $action) = explode('@', $string, 2); - } - - if (fnmatch('*#*', $string)) { + } elseif (fnmatch('*#*', $string)) { list($controller, $action) = explode('#', $string, 2); + } elseif (fnmatch('*.*', $string)) { + list($controller, $action) = explode('.', $string, 2); } return $route