Skip to content

Commit

Permalink
Fixed PHP notices
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Jan 5, 2012
1 parent 8783134 commit 8300887
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions flight/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static function after($name, $callback) {
* @return mixed
*/
public static function get($key) {
return self::$vars[$key];
return isset(self::$vars[$key]) ? self::$vars[$key] : null;
}

/**
Expand All @@ -216,7 +216,6 @@ public static function get($key) {
* @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;
Expand Down Expand Up @@ -273,9 +272,10 @@ public static function _start() {
$callback = $router->route($request);

if ($callback !== false) {
$params = array_values($router->params);
self::$dispatcher->execute(
$callback,
array_values($router->params)
$params
);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion flight/core/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function set($name, $callback) {
* @param callback $callback Callback function
*/
public function get($name) {
return $this->events[$name];
return isset($this->events[$name]) ? $this->events[$name] : null;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions flight/net/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public function __construct($config = array()) {
'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),
Expand Down
4 changes: 3 additions & 1 deletion flight/net/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ public function cache($expires) {
* 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) {
Expand Down
9 changes: 5 additions & 4 deletions flight/net/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public function clear() {
* @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;
}
Expand All @@ -85,7 +85,7 @@ function($str) use (&$ids){
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] : '[^(\/|\?)]+').')';
Expand Down Expand Up @@ -120,7 +120,8 @@ public function route(Request $request) {
$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)) {
Expand Down
2 changes: 1 addition & 1 deletion flight/util/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(array $data = array()) {
* @return mixed Value
*/
public function __get($key) {
return $this->data[$key];
return isset($this->data[$key]) ? $this->data[$key] : null;
}

/**
Expand Down

0 comments on commit 8300887

Please sign in to comment.