aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mekanisti.fi>2009-10-26 14:34:44 +0200
committerFilipp Lepalaan <filipp@mekanisti.fi>2009-10-26 14:34:44 +0200
commit735c8bf38f0b1c66470fdff312eacfcc21ab8ae8 (patch)
tree13248e6ad519057baf63b5c60b787bbadf34ebf9
parent56ae4ac94b1775bb58c63b5ed83bead4369dcdd1 (diff)
parent1038b52baf3e67c024527eb27f7493d9cbcae438 (diff)
downloadmain-735c8bf38f0b1c66470fdff312eacfcc21ab8ae8.tar.gz
main-735c8bf38f0b1c66470fdff312eacfcc21ab8ae8.tar.bz2
main-735c8bf38f0b1c66470fdff312eacfcc21ab8ae8.zip
Merge branch 'master' of github.com:filipp/main
-rw-r--r--App.php56
-rw-r--r--Db.php2
-rw-r--r--README37
3 files changed, 77 insertions, 18 deletions
diff --git a/App.php b/App.php
index d7ae2e9..ec26b58 100644
--- a/App.php
+++ b/App.php
@@ -12,7 +12,10 @@ class App
* Fire up the application
*/
static public function init()
- {
+ {
+ // Set custom error handler
+ set_error_handler("App::error_handler");
+
@list($controller, $param, $action) = App::url();
if (empty($param)) {
@@ -89,22 +92,49 @@ class App
}
- static function ok($msg)
+ static function json($msg)
{
- $ok = array('result' => 'ok', 'msg' => $msg);
- $json = json_encode($ok);
+ $json = json_encode($msg);
header("Content-Type: application/json");
header("Content-Length: " . strlen($json));
print $json;
}
+ static function ok($msg)
+ {
+ $ok = array('result' => 'ok', 'msg' => $msg);
+ self::json($ok);
+ }
+
static function error($msg)
{
- $err = array('result' => 'error', 'msg' => $msg);
- $json = json_encode($err);
- header("Content-Type: application/json");
- header("Content-Length: " . strlen($json));
- print $json;
+ $err = array('result' => 'error', 'msg' => $msg);
+ self::json($msg);
+ self::log($msg);
+ }
+
+ /**
+ * Log an error to our own logging system
+ */
+ static function log($msg)
+ {
+ if (is_array($msg)) {
+ $msg = print_r($msg, true);
+ }
+ $c = self::conf("app.error_log");
+ $file = realpath(__FILE__."/../../../../data/$c");
+ if (!$file) {
+ return false;
+ }
+ $fh = fopen($file, "a+");
+ fwrite($fh, $msg);
+ fclose($fh);
+ }
+
+ static function error_handler($errno, $errstr, $errfile, $errline)
+ {
+ $str = sprintf("%s\t%s\t%s\t%s\n", date("d.m @ H:i:s"), basename($errfile), $errline, $errstr);
+ self::log($str);
}
/**
@@ -124,14 +154,6 @@ class App
list($loc, $lang) = explode("-", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
return sprintf("%s_%s", $loc, strtoupper($lang));
}
-
- static function log($msg)
- {
- if (is_array($msg)) {
- $msg = print_r($msg, true);
- }
- syslog(LOG_ERR, $msg);
- }
public function delete($table, $where)
{
diff --git a/Db.php b/Db.php
index c98d1cb..e90362f 100644
--- a/Db.php
+++ b/Db.php
@@ -69,7 +69,7 @@ class Db
$stmt = self::getInstance()->prepare($sql);
$result = $stmt->execute($data);
-
+
if (!$result) {
$e = $stmt->errorInfo();
exit(App::error($e[2]));
diff --git a/README b/README
new file mode 100644
index 0000000..4054ef7
--- /dev/null
+++ b/README
@@ -0,0 +1,37 @@
+MAIN - the simple PHP framework
+
+## Folder structure ##
+
+site:
+ public (this is the DocRoot for your site)
+ index.php
+ system (put all system support files in here)
+ lib
+ main
+ classes (store all your model files in here)
+ views (create a folder for each controller and an action.html file for every view)
+ data (a good place to store all your application data, logs, etc)
+
+## index.php ##
+
+A typical index.php using MAIN would look like this:
+<?php
+
+ $sysdir = realpath(dirname(__FILE__).'/../system');
+
+ set_include_path(
+ get_include_path() . PATH_SEPARATOR
+ . $sysdir . PATH_SEPARATOR
+ . "{$sysdir}/lib" . PATH_SEPARATOR
+ . "{$sysdir}/conf" . PATH_SEPARATOR
+ . "{$sysdir}/classes" . PATH_SEPARATOR
+ );
+
+ require_once "main/app.php";
+ require_once "main/controller.php";
+ $locale = App::locale();
+ setlocale(LC_ALL, $locale);
+ session_start();
+ App::init();
+
+?>