aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MainApp.php (renamed from App.php)64
-rw-r--r--MainController.php (renamed from Controller.php)16
-rw-r--r--MainDb.php (renamed from Db.php)13
-rw-r--r--MainView.php (renamed from View.php)9
-rw-r--r--README31
5 files changed, 61 insertions, 72 deletions
diff --git a/App.php b/MainApp.php
index 9e59c4c..e55a74a 100644
--- a/App.php
+++ b/MainApp.php
@@ -1,33 +1,27 @@
<?php
////
-// main/App.php
+// main/MainApp.php
// @author Filipp Lepalaan <filipp@mekanisti.fi>
// @copyright (c) 2009 Filipp Lepalaan
-class App
+class MainApp
{
////
// Fire up the application
static public function init()
- {
- self::log($_SERVER);
- // Set custom error handler
- set_error_handler('App::error_handler');
- // Set correct timezone
- date_default_timezone_set(self::conf('app.timezone'));
-
+ {
@list($controller, $param, $action) = App::url();
- // No action given, read default one
+ // no action given, read default one
if (empty($param)) {
$action = self::conf('defaults.action');
}
- // No controller given, read default one
+ // no controller given, read default one
if (!$controller) {
$controller = self::conf('defaults.controller');
}
- // Fire up the output buffer
+ // fire up the output buffer
ob_start();
// Dispatch correct controller
@@ -62,6 +56,7 @@ class App
static function url($index = null)
{
$url = parse_url($_SERVER['REQUEST_URI']);
+
if ($index == 'query') {
return $url['query'];
}
@@ -70,9 +65,8 @@ class App
return (is_numeric($index)) ? $array[$index] : $array;
}
- /**
- *
- */
+ ////
+ // return parameter part of URL
static function param()
{
$url = App::url();
@@ -80,21 +74,29 @@ class App
}
////
- // Return configuration data from ini file
- static function conf($key = null)
+ // get configuration data from ini file
+ static function conf($key = NULL)
{
$cpath = realpath('../system/config.ini');
+
+ if (!file_exists($cpath)) {
+ trigger_error('Failed to open config file', E_USER_ERROR);
+ exit();
+ }
+
$config = parse_ini_file($cpath, true);
$config = $config['development'];
if ($key && ! $config[$key]) {
- return self::error("No such config key: $key");
+ return self::error('No such config key: '.$key);
}
return ($key) ? $config[$key] : $config;
}
+ ////
+ // determine template type of request
static function type()
{
$tokens = explode('/', $_SERVER['REQUEST_URI']);
@@ -133,7 +135,7 @@ class App
}
////
- // Log an error to our own logging system
+ // log an error to our own logging system
static function log($msg)
{
if (is_array($msg)) {
@@ -154,19 +156,7 @@ class App
}
////
- // Set our own PHP error handler
- 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);
-
- }
-
- ////
- // Do a proper HTTP redirect
+ // do a proper HTTP redirect
// @param string [$where] URL to redirect to
// @return void
static function redirect($url = null)
@@ -180,11 +170,11 @@ class App
}
////
- // Determine locale from USER_AGENT
+ // determine locale from USER_AGENT
static function locale()
{
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
- return false;
+ return NULL;
}
// Set language to whatever the browser is set to
list($loc, $lang) = explode('-', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
@@ -206,7 +196,7 @@ class App
}
////
- // Insert something in the database
+ // insert something in the database
static function insert($table, $data)
{
if (empty($data)) {
@@ -235,7 +225,7 @@ class App
{
$out = array();
- $query = "?";
+ $query = '?';
$values = array(1);
if (is_array($where)) {
@@ -264,7 +254,7 @@ class App
$out[] = $row;
}
- if (count($out) == 1 && $what != "*") {
+ if (count($out) == 1 && $what != '*') {
return $out[0][$what];
}
diff --git a/Controller.php b/MainController.php
index 2534397..e1545b7 100644
--- a/Controller.php
+++ b/MainController.php
@@ -1,16 +1,12 @@
<?php
-
-/**
- * main/Controller.php
- * "VC" version of Beof
- * @TODO: transfer boeuf.php here
- */
-
-class Controller
+////
+// main/MainController.php
+// @TODO: transfer boeuf.php here
+class MainController
{
public $view; // Where to store the data to be rendered
- public $pageTitle = ""; // Title of the rendered page
- public $defaultAction = ""; // Method to run when none specified
+ public $pageTitle = ''; // Title of the rendered page
+ public $defaultAction = ''; // Method to run when none specified
const OrderBy = "";
const HasMany = "";
diff --git a/Db.php b/MainDb.php
index f09cd85..0922cdf 100644
--- a/Db.php
+++ b/MainDb.php
@@ -1,12 +1,9 @@
<?php
-
-/**
- * main/Db.php
- * @author Filipp Lepalaan <filipp@mekanisti.fi>
- * http://www.php.net/manual/en/language.oop5.patterns.php
- */
-
-class Db
+////
+// main/MainDb.php
+// @author Filipp Lepalaan <filipp@mekanisti.fi>
+// http://www.php.net/manual/en/language.oop5.patterns.php
+class MainDb
{
private static $instance = NULL;
diff --git a/View.php b/MainView.php
index 762d75b..d964b6c 100644
--- a/View.php
+++ b/MainView.php
@@ -1,9 +1,8 @@
<?php
-/**
- * main/MainView.php
- * @created 31.10.2009
- * @author Filipp Lepalaan <filipp@mac.com>
- */
+////
+// main/MainView.php
+// @created 31.10.2009
+// @author Filipp Lepalaan <filipp@mac.com>
class MainView
{
/**
diff --git a/README b/README
index 552e770..158ca0f 100644
--- a/README
+++ b/README
@@ -17,23 +17,30 @@ site:
A typical index.php using Main would look like this:
<?php
-
+
+ if (true) {
+ error_reporting(E_ALL|E_STRICT);
+ ini_set('display_errors', 'On');
+ }
+
$sysdir = realpath(dirname(__FILE__).'/../system');
- np
+
set_include_path(
- get_include_path() . PATH_SEPARATOR
- . $sysdir . PATH_SEPARATOR
- . "{$sysdir}/lib" . PATH_SEPARATOR
- . "{$sysdir}/conf" . PATH_SEPARATOR
- . "{$sysdir}/classes" . PATH_SEPARATOR
- );
+ get_include_path() . PATH_SEPARATOR
+ . $sysdir . PATH_SEPARATOR
+ . "{$sysdir}/lib" . PATH_SEPARATOR
+ . "{$sysdir}/conf" . PATH_SEPARATOR
+ . "{$sysdir}/classes" . PATH_SEPARATOR
+ );
+
+ require_once 'main/MainApp.php';
+ require_once 'main/MainController.php';
- require_once "main/app.php";
- require_once "main/controller.php";
- $locale = App::locale();
+ $locale = MainApp::locale();
setlocale(LC_ALL, $locale);
session_start();
- App::init();
+
+ MainApp::init();
?>