diff --git a/flight/Flight.php b/flight/Flight.php index 6328db3..6bfc0a7 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -206,7 +206,7 @@ class Flight { * @return mixed */ public static function get($key) { - return self::$vars[$key]; + return isset(self::$vars[$key]) ? self::$vars[$key] : null; } /** @@ -216,7 +216,6 @@ class Flight { * @param string $value Value */ public static function set($key, $value = null) { - // If key is an array, save each key value pair if (is_array($key) || is_object($key)) { foreach ($key as $k => $v) { self::$vars[$k] = $v; @@ -273,9 +272,10 @@ class Flight { $callback = $router->route($request); if ($callback !== false) { + $params = array_values($router->params); self::$dispatcher->execute( $callback, - array_values($router->params) + $params ); } else { diff --git a/flight/core/Dispatcher.php b/flight/core/Dispatcher.php index a1ebea9..89b9813 100644 --- a/flight/core/Dispatcher.php +++ b/flight/core/Dispatcher.php @@ -71,7 +71,7 @@ class Dispatcher { * @param callback $callback Callback function */ public function get($name) { - return $this->events[$name]; + return isset($this->events[$name]) ? $this->events[$name] : null; } /** diff --git a/flight/net/Request.php b/flight/net/Request.php index 6177495..6db99f8 100644 --- a/flight/net/Request.php +++ b/flight/net/Request.php @@ -45,14 +45,14 @@ class Request { 'url' => $_SERVER['REQUEST_URI'], 'base' => str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])), 'method' => $_SERVER['REQUEST_METHOD'], - 'referrer' => $_SERVER['HTTP_REFERER'], + 'referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'ip' => $_SERVER['REMOTE_ADDR'], - 'ajax' => ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'), + 'ajax' => isset($_SERVER['HTTP_X_REQUESTED_WITH']) ? ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') : false, 'scheme' => $_SERVER['SERVER_PROTOCOL'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'body' => file_get_contents('php://input'), - 'type' => $_SERVER['CONTENT_TYPE'], - 'length' => $_SERVER['CONTENT_LENGTH'], + 'type' => isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '', + 'length' => isset($_SERVER['CONTENT_LENGTH']) ? $_SERVER['CONTENT_LENGTH'] : 0, 'query' => new Collection($_GET), 'data' => new Collection($_POST), 'cookies' => new Collection($_COOKIE), diff --git a/flight/net/Response.php b/flight/net/Response.php index 1da1ad5..23a7965 100644 --- a/flight/net/Response.php +++ b/flight/net/Response.php @@ -151,7 +151,9 @@ class Response { * Sends the response and exits the program. */ public function send() { - ob_end_clean(); + if (ob_get_length() > 0) { + ob_end_clean(); + } if (!headers_sent()) { foreach ($this->headers as $field => $value) { diff --git a/flight/net/Router.php b/flight/net/Router.php index 4115758..5b3a492 100644 --- a/flight/net/Router.php +++ b/flight/net/Router.php @@ -58,9 +58,9 @@ class Router { * @param callback $callback Callback function */ public function map($pattern, $callback) { - list($method, $url) = explode(' ', trim($pattern), 2); + if (strpos($pattern, ' ') !== false) { + list($method, $url) = explode(' ', trim($pattern), 2); - if (!is_null($url)) { foreach (explode('|', $method) as $value) { $this->routes[$value][$url] = $callback; } @@ -85,7 +85,7 @@ class Router { if ($str == '*') { $str = '(.*)'; } - else if ($str{0} == '@') { + else if ($str != null && $str{0} == '@') { if (preg_match('/@(\w+)(\:([^\/]*))?/', $str, $matches)) { $ids[$matches[1]] = true; return '(?P<'.$matches[1].'>'.(isset($matches[3]) ? $matches[3] : '[^(\/|\?)]+').')'; @@ -120,7 +120,8 @@ class Router { $this->matched = null; $this->params = array(); - $routes = ($this->routes[$request->method] ?: array()) + ($this->routes['*'] ?: array()); + $routes = isset($this->routes[$request->method]) ? $this->routes[$request->method] : array(); + if (isset($this->routes['*'])) $routes += $this->routes['*']; foreach ($routes as $pattern => $callback) { if ($pattern === '*' || $request->url === $pattern || self::match($pattern, $request->url)) { diff --git a/flight/util/Collection.php b/flight/util/Collection.php index 85d86bc..eae2b28 100644 --- a/flight/util/Collection.php +++ b/flight/util/Collection.php @@ -36,7 +36,7 @@ class Collection implements \ArrayAccess, \Iterator, \Countable { * @return mixed Value */ public function __get($key) { - return $this->data[$key]; + return isset($this->data[$key]) ? $this->data[$key] : null; } /**