Skip to content

Commit

Permalink
Merge pull request #1 from krasimir/master
Browse files Browse the repository at this point in the history
Few templates changes + small Logger change
  • Loading branch information
Krasimir Tsonev committed Oct 23, 2011
2 parents d4c207d + f0720de commit 74f422f
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 209 deletions.
2 changes: 1 addition & 1 deletion controllers/Intro.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public function run($req, $res) {
view("views/layout-default.html", array(
"content" => view("views/intro.html"),
"time" => $req->benchmark->elpasedTime(),
"siteURL" => $req->base
"host" => $req->host
))
);
}
Expand Down
2 changes: 0 additions & 2 deletions controllers/SampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public function run2($req, $res) {
$response =
view("views/layout-default.html", array(
"content" => view("views/sample.html", array(

"content" => $req->param("key1", "defaultKey1Value"),

"footer" => view("views/sample-footer.html", array(
"content" => $req->param("key2", "defaultKey2Value")
))
Expand Down
15 changes: 8 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@
$app->router->get("/error", "controllers/SampleController.php", 'simulateError');
$app->router->get("", "controllers/Intro.php");

// -------------------------------- setup custom 500 page ---------------------
require_once ("modules/view.php");
$app->logger->render500 = function(Exception $e) use ($app) {
$app->response->send(view(dirname(__FILE__)."/views/500.html", array(
// -------------------------------- setup custom error page ---------------------
$app->logger->errorHandler = function(Exception $e) use ($app) {
require_once("modules/view.php");
$app->response->send(view(dirname(__FILE__)."/views/error.html", array(
"message" => $e->getMessage(),
"location" => "File: ".$e->getFile()." Line: ".$e->getLine(),
"stackTrace" => '<li>'.implode(explode("\n",$e->getTraceAsString()), '<li>')
"stackTrace" => '<li>'.implode(explode("\n", $e->getTraceAsString()), '<li>')
)), 500);
};

// -------------------------------- setup custom 404 page ---------------------
$app->router->all("*", function($req, $res){
$res->send(view("views/404.html", array("url"=>$app->request->url)), 404);
$app->router->all("*", function($req, $res) use ($app) {
require_once("modules/view.php");
$res->send(view("views/404.html", array("url" => $app->request->url)), 404);
});

// finally run the application in the defined mode (/config/config.json)
Expand Down
13 changes: 13 additions & 0 deletions modules/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function __construct($config = array()) {
if (empty($config)) {
$config = array(
'url' => $_SERVER['REQUEST_URI'],
'host' => $this->getHost(),
'base' => str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])),
'method' => $_SERVER['REQUEST_METHOD'],
'referrer' => isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:"",
Expand Down Expand Up @@ -74,5 +75,17 @@ public function parseQueryParams($url) {
public function param($key, $defaultValue = NULL) {
return isset($this->params[$key])?$this->params[$key]:$defaultValue;
}

function getHost() {
$host = 'http';
if(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$host .= "s";
}
$host .= "://".$_SERVER['HTTP_HOST'];
if(substr($host, strlen($host) - 1, 1) != "/") {
$host .= "/";
}
return $host;
}
}
?>
2 changes: 1 addition & 1 deletion modules/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function cache($expires) {
* if $status is NULL, then $response->status will be used instead, defaults to 200.
* All headers are send using this method if they have not been send already.
*/
public function send($body = NULL,$status = NULL) {
public function send($body = NULL, $status = NULL) {

if (!headers_sent()) {
if($status != NULL)
Expand Down
6 changes: 3 additions & 3 deletions modules/middleware/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Logger {
static $instance;
public $DEBUG = TRUE;
public $ERROR_SEND = FALSE;
public $render500 = NULL;
public $errorHandler = NULL;

public function __construct(){
static::$instance = $this;
Expand Down Expand Up @@ -55,8 +55,8 @@ public function error(Exception $e) {
if($this->ERROR_SEND == TRUE)
return;
$this->ERROR_SEND = TRUE;
if($this->render500 != NULL) {
$handler = $this->render500;
if($this->errorHandler != NULL) {
$handler = $this->errorHandler;
$handler($e);
} else {
header(($_SERVER['SERVER_PROTOCOL'] ?: 'HTTP/1.1').' Internal Server Error', true, 500);
Expand Down
76 changes: 56 additions & 20 deletions views/404.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,56 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8"><title>404 Error</title><style>body { text-align: center;}
h1 { font-size: 50px; text-align: center }
span[frown] { transform: rotate(90deg); display:inline-block; color: #bbb; }
body { font: 20px Constantia, 'Hoefler Text', "Adobe Caslon Pro", Baskerville, Georgia, Times, serif; color: #999; text-shadow: 2px 2px 2px rgba(200, 200, 200, 0.5); }
::-moz-selection{ background:#FF5E99; color:#fff; }
::selection { background:#FF5E99; color:#fff; }
article {display:block; text-align: left; width: 500px; margin: 0 auto; }
a { color: rgb(36, 109, 56); text-decoration:none; }
a:hover { color: rgb(96, 73, 141) ; text-shadow: 2px 2px 2px rgba(36, 109, 56, 0.5); }
</style>
</head>
<body>
<article><h1>404 &nbsp;<span frown>:(</span></h1><div><p>Sorry, but the page {url} you were trying to view does not exist.</p><p>It looks like this was the result of either:</p><ul><li>a mistyped address</li><li>an out-of-date link</li></ul>
<script>var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),
GOOG_FIXURL_SITE = location.host;
</script>
<script src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script></div></article>
</body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 Error</title>
<style type="text/css">
body {
width: 100%;
height: 100%;
margin: 50px 0 0 0;
padding: 0;
font-family: Tahoma, Verdana;
font-size: 14px;
color: #000;
}
.content {
display: block;
width: 950px;
margin: 0 auto;
border: solid 1px #999;
padding: 20px;
}
h1 {
font-size: 40px;
font-weight: normal;
margin: 0 0 20px 0;
padding: 0 0 20px 0;
color: #808080;
border-bottom: solid 1px #999;
text-align: center;
}
p {
margin: 10px;
padding: 0;
}
</style>
</head>
<body>
<div class="content">
<h1>404</h1>
<p>Sorry, but the page <strong>{url}</strong> you were trying to view does not exist.</p>
<p>It looks like this was the result of either:</p>
<p>
<ul>
<li>a mistyped address</li>
<li>an out-of-date link</li>
</ul>
</p>
</div>
<!-- offers google search
<script>
var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2), GOOG_FIXURL_SITE = location.host;
</script>
<script src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script></div></article>
-->
</body>
</html>
158 changes: 0 additions & 158 deletions views/500.html

This file was deleted.

44 changes: 44 additions & 0 deletions views/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 Error</title>
<style type="text/css">
body {
width: 100%;
height: 100%;
margin: 50px 0 0 0;
padding: 0;
font-family: "Helvetica Neue", Tahoma, Verdana;
font-size: 14px;
color: #000;
}
.content {
display: block;
width: 950px;
margin: 0 auto;
border: solid 1px #999;
padding: 20px;
}
h1 {
font-size: 40px;
font-weight: normal;
margin: 0 0 20px 0;
padding: 0 0 20px 0;
color: #808080;
border-bottom: solid 1px #999;
text-align: center;
}
p {
margin: 10px;
padding: 0;
}
</style>
</head>
<body>
<div class="content">
<h1>{message}</h1>
<p>{location}</p>
<ul>{stackTrace}</ul>
</div>
</body>
</html>
Loading

0 comments on commit 74f422f

Please sign in to comment.