Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Type-hinting for method signatures and cleanup in Zepto\Router
Browse files Browse the repository at this point in the history
  • Loading branch information
hassankhan committed Jan 21, 2014
1 parent a845684 commit 886a992
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions library/Zepto/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class Router
/**
* Contains the callback function to execute, retrieved during run()
*
* @var string|array
* @var Closure
*/
protected $callback = null;

/**
* 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;

Expand Down Expand Up @@ -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) {
Expand All @@ -221,25 +221,24 @@ 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');
}

/**
* 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');
}
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 886a992

Please sign in to comment.