Skip to content

Commit

Permalink
Merge pull request #55 from abeaumet/master
Browse files Browse the repository at this point in the history
Added ability to specify closures for route handlers.
  • Loading branch information
martinbean committed Sep 26, 2013
2 parents 0f3942c + 26f3fca commit 470ae04
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Toro.php
Expand Up @@ -43,11 +43,21 @@ public static function serve($routes)
}

$result = null;
if ($discovered_handler && class_exists($discovered_handler)) {

$handler_instance = null;
if ($discovered_handler) {
if (is_string($discovered_handler)) {
$handler_instance = new $discovered_handler();
}
elseif (is_callable($discovered_handler)) {
$handler_instance = $discovered_handler();
}
}

if ($handler_instance) {
unset($regex_matches[0]);
$handler_instance = new $discovered_handler();

if (self::is_xhr_request() && method_exists($discovered_handler, $request_method . '_xhr')) {
if (self::is_xhr_request() && method_exists($handler_instance, $request_method . '_xhr')) {
header('Content-type: application/json');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
Expand Down

0 comments on commit 470ae04

Please sign in to comment.