From 886a99202029406e7eba6239205619374d73ae87 Mon Sep 17 00:00:00 2001 From: Hassan Khan Date: Tue, 21 Jan 2014 20:49:04 +0000 Subject: [PATCH] Type-hinting for method signatures and cleanup in ``Zepto\Router`` --- library/Zepto/Router.php | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/library/Zepto/Router.php b/library/Zepto/Router.php index b1298dc..c6ac0e7 100644 --- a/library/Zepto/Router.php +++ b/library/Zepto/Router.php @@ -65,7 +65,7 @@ class Router /** * Contains the callback function to execute, retrieved during run() * - * @var string|array + * @var Closure */ protected $callback = null; @@ -73,7 +73,7 @@ class Router * Contains the callback function to execute if none of the given routes can * be matched to the current URL. * - * @var Callable + * @var Closure */ public $error_404 = null; @@ -207,9 +207,9 @@ public function execute() } catch (Exception $e) { // Add logging stuff here - maybe? + // Maybe make it do a HTTP 500 error? } - // Removing this makes testing easier, how can I fix this? $this->error_404 = $this->routes['GET']['#^/404/$#']; if ($this->callback == null || $this->params == null) { @@ -221,13 +221,12 @@ public function execute() } /** - * Convenience method for HTTP GET routes - * - * @param string $route - * @param Callable $callback + * Convenience method for HTTP GET routes* [get description] + * @param string $route + * @param Closure $callback * @return boolean */ - public function get($route, $callback) + public function get($route, \Closure $callback) { return $this->route($route, $callback, 'GET'); } @@ -235,11 +234,11 @@ public function get($route, $callback) /** * Convenience method for HTTP POST routes * - * @param string $route - * @param Callable $callback + * @param string $route + * @param Closure $callback * @return boolean */ - public function post($route, $callback) + public function post($route, \Closure $callback) { return $this->route($route, $callback, 'POST'); } @@ -248,12 +247,12 @@ public function post($route, $callback) * Adds a new URL routing rule to the routing table, after converting any of * our special tokens into proper regular expressions. * - * @param string $route - * @param Callable $callback - * @param integer $request_method + * @param string $route + * @param Closure $callback + * @param string $request_method * @return boolean */ - public function route($route, $callback, $request_method = 'GET') + public function route($route, \Closure $callback, $request_method = 'GET') { // Keep the original routing rule for debugging/unit tests $original_route = $route; @@ -303,11 +302,13 @@ public function get_routes() } /** - * Sets the 404 callback + * Sets the 404 callback. If a callable function is provided as a parameter, + * then that is set as the callback for HTTP 404 errors */ public function set_404_callback() { - if (func_num_args() === 1 && gettype(func_get_arg(0)) === 'Callable') { + // If a callable function is passed to + if (func_num_args() === 1 && gettype(func_get_arg(0)) === 'Closure') { return $callback; } return function() {