Skip to content

Commit

Permalink
Merge pull request anandkunal#14 from anandkunal/v-2.0.0-opts
Browse files Browse the repository at this point in the history
V 2.0.0 opts
  • Loading branch information
anandkunal committed Aug 14, 2012
2 parents 865fef9 + 58ebe6e commit 1781cac
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions toro.php
Expand Up @@ -9,17 +9,15 @@ public static function serve($routes) {
$discovered_handler = NULL;
$regex_matches = array();

foreach ($routes as $pattern => $handler_name) {
if ($path_info == $pattern) {
$discovered_handler = $handler_name;
break;
}
else {
if (isset($routes[$path_info])) {
$discovered_handler = $routes[$path_info];
}
else {
foreach ($routes as $pattern => $handler_name) {
$pattern = str_replace(':string', '[a-zA-Z]+', $pattern);
$pattern = str_replace(':number', '[0-9]+', $pattern);
$pattern = str_replace(':alpha', '[a-zA-Z0-9-_]+', $pattern);
$pattern = str_replace('/', '\/', $pattern);
if (preg_match('/^\/?' . $pattern . '\/?$/', $path_info, $matches)) {
if (preg_match('|^/?' . $pattern . '/?$|', $path_info, $matches)) {
$discovered_handler = $handler_name;
$regex_matches = $matches;
break;
Expand All @@ -33,11 +31,11 @@ public static function serve($routes) {

if (self::xhr_request() && method_exists($discovered_handler, $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");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
$request_method .= '_xhr';
}

Expand All @@ -53,7 +51,7 @@ public static function serve($routes) {
}

private static function xhr_request() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
}
}

Expand All @@ -72,15 +70,15 @@ public static function add($hook_name, $fn) {

public static function fire($hook_name, $params = NULL) {
$instance = self::get_instance();
if (array_key_exists($hook_name, $instance->hooks)) {
if (isset($instance->hooks[$hook_name])) {
foreach ($instance->hooks[$hook_name] as $fn) {
call_user_func_array($fn, array(&$params));
}
}
}

public static function get_instance() {
if (!isset(self::$instance)) {
if (empty(self::$instance)) {
self::$instance = new ToroHook();
}
return self::$instance;
Expand Down

0 comments on commit 1781cac

Please sign in to comment.