@@ -21,6 +21,7 @@ class Route
2121 private $ _action ;
2222 private $ _jails ;
2323 private $ _name ;
24+ private $ _middleware ;
2425 private $ _type ;
2526 private $ _variables = [];
2627
@@ -43,13 +44,14 @@ class Route
4344 * @param null $name
4445 * @param null $type
4546 */
46- public function __construct ($ method , $ route , $ action , $ name = null , $ type = null )
47+ public function __construct ($ method , $ route , $ action , $ name = null , $ middleware = ' public ' , $ type = null )
4748 {
4849 $ this ->_method = strtolower ($ method );
4950 $ this ->_route = $ route ;
5051 $ this ->_action = $ action ;
5152 $ this ->_jails = self ::$ jails ;
5253 $ this ->_name = $ name ;
54+ $ this ->_middleware = $ middleware ;
5355 $ this ->_type = $ type ;
5456 }
5557
@@ -77,6 +79,14 @@ public function name()
7779 return $ this ->_name ;
7880 }
7981
82+ /**
83+ * @return null
84+ */
85+ public function middleware ()
86+ {
87+ return $ this ->_middleware ;
88+ }
89+
8090 /**
8191 * @return string
8292 */
@@ -223,6 +233,7 @@ public function check($method, $url)
223233
224234
225235 // Check jails
236+ //TODO: deprecated!
226237 foreach ($ this ->_jails as $ jail ) {
227238 $ jail = explode ('@ ' , $ jail );
228239
@@ -246,6 +257,7 @@ public function check($method, $url)
246257 public static function group ($ args , $ fn )
247258 {
248259 // Prepare
260+ //TODO: deprecated use MW
249261 if (isset ($ args ['jail ' ])) {
250262 self ::$ jails [] = $ args ['jail ' ];
251263 }
@@ -262,6 +274,7 @@ public static function group($args, $fn)
262274 // Restore
263275 self ::$ _prefix = $ old_prefix ;
264276
277+ // TODO: deprecated use MW
265278 if (isset ($ args ['jail ' ])) {
266279 array_pop (self ::$ jails );
267280 }
@@ -289,11 +302,11 @@ public static function find($requestUrl, $requestMethod)
289302 * @param null $name
290303 * @param string $type
291304 */
292- public static function register ($ method , $ route , $ action , $ name = null , $ type = '' )
305+ public static function register ($ method , $ route , $ action , $ name = null , $ middleware = ' public ' , $ type = '' )
293306 {
294307 $ route = self ::$ _prefix . $ route ;
295308 foreach (explode ("| " , $ method ) as $ m ) {
296- $ r = new Route ($ m , $ route , $ action , $ name , $ type );
309+ $ r = new Route ($ m , $ route , $ action , $ name , $ middleware , $ type );
297310 self ::$ _routes [] = $ r ;
298311 self ::$ _route_index [ $ name ] = $ r ;
299312 }
@@ -304,19 +317,19 @@ public static function register($method, $route, $action, $name = null, $type =
304317 * @param $action
305318 * @param null $name
306319 */
307- public static function get ($ route , $ action , $ name = null )
320+ public static function get ($ route , $ action , $ name = null , $ middleware = ' public ' )
308321 {
309- return self ::register ("get " , $ route , $ action , $ name , 'get ' );
322+ return self ::register ("get " , $ route , $ action , $ name , $ middleware , 'get ' );
310323 }
311324
312325 /**
313326 * @param $route
314327 * @param $action
315328 * @param null $name
316329 */
317- public static function post ($ route , $ action , $ name = null )
330+ public static function post ($ route , $ action , $ name = null , $ middleware = ' public ' )
318331 {
319- return self ::register ("post " , $ route , $ action , $ name , 'post ' );
332+ return self ::register ("post " , $ route , $ action , $ name ,$ middleware , 'post ' );
320333 }
321334
322335
@@ -327,9 +340,9 @@ public static function post($route, $action, $name = null)
327340 * @param null $name
328341 * @param string $req
329342 */
330- public static function put ($ route , $ action , $ name = null , $ req = 'put ' )
343+ public static function put ($ route , $ action , $ name = null , $ middleware = ' public ' , $ req = 'put ' )
331344 {
332- return self ::register ("put " , $ route , $ action , $ name , $ req );
345+ return self ::register ("put " , $ route , $ action , $ name ,$ middleware , $ req );
333346 }
334347
335348 // need to work on POST too
@@ -339,9 +352,9 @@ public static function put($route, $action, $name = null, $req = 'put')
339352 * @param null $name
340353 * @param string $req
341354 */
342- public static function delete ($ route , $ action , $ name = null , $ req = 'delete ' )
355+ public static function delete ($ route , $ action , $ name = null , $ middleware = ' public ' , $ req = 'delete ' )
343356 {
344- return self ::register ("delete " , $ route , $ action , $ name , $ req );
357+ return self ::register ("delete " , $ route , $ action , $ name , $ middleware , $ req );
345358 }
346359
347360
@@ -350,7 +363,7 @@ public static function delete($route, $action, $name = null, $req = 'delete')
350363 * @param $action
351364 * @param null $name
352365 */
353- public static function resource ($ route , $ action , $ name = null )
366+ public static function resource ($ route , $ action , $ name = null , $ middleware = ' public ' )
354367 {
355368 // Remove possible method name
356369 if (($ pos = strpos ($ action , '@ ' )) !== false ) {
@@ -391,9 +404,9 @@ public static function resource($route, $action, $name = null)
391404 * @param $action
392405 * @param null $name
393406 */
394- public static function any ($ route , $ action , $ name = null )
407+ public static function any ($ route , $ action , $ name = null , $ middleware = ' public ' )
395408 {
396- return self ::register ("any " , $ route , $ action , $ name , 'any ' );
409+ return self ::register ("any " , $ route , $ action , $ name , $ middleware , 'any ' );
397410 }
398411
399412 /**
0 commit comments