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

Commit

Permalink
Removed Zepto\Router::execute(), moved logic to ``Zepto\Router::r…
Browse files Browse the repository at this point in the history
…un()``, now 500 errors are officially handled. Fixed reference in ``Zepto\Zepto`` as well.
  • Loading branch information
hassankhan committed Jan 30, 2014
1 parent fb45afb commit 67311df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
38 changes: 13 additions & 25 deletions library/Zepto/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Router
{

/**
* Supported HTTP Methods
* Supported HTTP Methods (might not be strictly accurate ... yet - I've only tested GET and POST')
*/
const METHOD_HEAD = 'HEAD';
const METHOD_GET = 'GET';
Expand Down Expand Up @@ -227,38 +227,26 @@ public function run()
if ($route === null) {
$this->not_found();
}
// If route is a valid Route object, then try and execute its callback
else {
// Set current route
$this->current_route = $route;

// Get parameters from request
$params = $this->parse_parameters($route);

// Execute callback, and set returned string as response content
$this->response->setContent(call_user_func_array($route->get_callback(), $params));
// Try to execute callback for route, if it fails, catch the exception
// and generate a HTTP 500 error
try {
// Set response content
$this->response->setContent(call_user_func_array($route->callback(), array($params)));

// Send response
$this->response->send();
}
}

/**
* Tries to run the routing engine and generate a response, if any exceptions
* are thrown then it executes the error handler
*
* @uses Router::run()
* @return
*/
public function execute()
{
try{
$this->run();
}
catch (Exception $e) {

$this->error($e->getMessage());
// Add logging stuff here - maybe?
// Maybe make it do a HTTP 500 error?
// Send response
$this->response->send();
}
catch (\Exception $e) {
$this->error($e->getMessage());
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zepto/Zepto.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function() {
*/
public function run()
{
return $this->container['router']->execute();
return $this->container['router']->run();
}

/**
Expand Down

0 comments on commit 67311df

Please sign in to comment.