Skip to content

Commit

Permalink
Minor formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Apr 7, 2011
1 parent 845ed65 commit fb971f1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions klein.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function dispatch($request_uri = null, $request_method = null, array $params = n
$i = 0;
}

//Check for a hard match
if ($_route === $request_uri || $_route === '*') {
$match = true;
} else {
Expand All @@ -82,7 +83,8 @@ function dispatch($request_uri = null, $request_method = null, array $params = n
} elseif (null === $substr) {
$c = $_route[$i];
$n = $_route[$i + 1];
if ($c === '[' || $c === '(' || $c === '.' || $n === '?' || $n === '+' || $n === '*' || $n === '{') {
if ($c === '[' || $c === '(' || $c === '.' ||
$n === '?' || $n === '+' || $n === '*' || $n === '{') {
$substr = $route;
}
}
Expand All @@ -109,13 +111,14 @@ function dispatch($request_uri = null, $request_method = null, array $params = n
$match = preg_match($regex, $request_uri, $params);
}

//Handle a match
if ($match ^ $negate) {
$matched = true;

//Merge named parameters
if (null !== $params) {
$__params = array_merge($__params, $params);
}

try {
//Ignore callbacks that return false
if (false === $callback($request, $response, $app)) {
Expand All @@ -138,6 +141,7 @@ function compile_route($route) {
return '`' . substr($route, 1) . '`';
}
$regex = $route;

if (preg_match_all('`(/?\.?)\[([^:]*+)(?::([^:\]]++))?\](\?)?`', $route, $matches, PREG_SET_ORDER)) {
$match_types = array(
'i' => '[0-9]++',
Expand All @@ -149,6 +153,7 @@ function compile_route($route) {
);
foreach ($matches as $match) {
list($block, $pre, $type, $param, $optional) = $match;

if (isset($match_types[$type])) {
$type = $match_types[$type];
}
Expand All @@ -174,6 +179,7 @@ public function params($mask = null) {
$mask = func_get_args();
}
$params = array_intersect_key($params, array_flip($mask));
//Make sure each key in $mask has at least a null value
foreach ($mask as $key) {
if (!isset($params[$key])) $params[$key] = null;
}
Expand Down Expand Up @@ -284,8 +290,10 @@ public function flash($msg, $type = 'error') {
public function send($object, $type = 'json', $filename = null) {
$this->discard();
set_time_limit(1200);

header("Pragma: no-cache");
header('Cache-Control: no-store, no-cache');

switch ($type) {
case 'json':
$json = json_encode($object);
Expand Down Expand Up @@ -374,6 +382,7 @@ public function query($new, $value = null) {
} else {
$query[$new] = $value;
}

$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
if (strpos($request_uri, '?') !== false) {
$request_uri = strstr($request_uri, '?', true);
Expand Down Expand Up @@ -411,7 +420,7 @@ public function error(Exception $err) {
if (count($this->_errorCallbacks) > 0) {
foreach (array_reverse($this->_errorCallbacks) as $callback) {
if (is_callable($callback)) {
if($callback($this, $msg, $type)) {
if ($callback($this, $msg, $type)) {
return;
}
} else {
Expand All @@ -428,7 +437,9 @@ public function error(Exception $err) {
//Returns an escaped request paramater
public function param($param, $default = null) {
global $__params;
if (!isset($__params[$param])) return null;
if (!isset($__params[$param])) {
return null;
}
return htmlentities($__params[$param], ENT_QUOTES, 'UTF-8');
}

Expand Down

0 comments on commit fb971f1

Please sign in to comment.