This repository has been archived by the owner on Dec 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
executable file
·79 lines (66 loc) · 3.06 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Fari MVC Framework 1.2.0.0 (Jan 2, 2010)
*
* Main point of access, a bootstrapping file. Here we declare variables and set configurations.
*
* @author Radek Stepan <radek.stepan@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*
* @package Fari MVC Framework
*/
// start session
if (!isset($_SESSION)) session_start();
// start benchmarking
$_SESSION['Fari\Benchmark\Total'] = microtime();
// set so that we can check if PHP pages have been accessed directly
if (!defined('FARI')) define('FARI', 'Fari MVC Framework 1.2.0.0');
// get absolute pathname and define it as a constant (server install path)
if (!defined('BASEPATH')) define('BASEPATH', dirname(__FILE__));
// www root dir (path for links in your views)
if (!defined('WWW_DIR')) {
// now we can have the app in the root
dirname($_SERVER['SCRIPT_NAME']) == '/' ? define('WWW_DIR', '') : define('WWW_DIR', dirname($_SERVER['SCRIPT_NAME']));
}
// default file extension (.php)
if (!defined('EXT')) define('EXT', '.' . pathinfo(__FILE__, PATHINFO_EXTENSION));
// default Action for the application (index() is always implemented as is abstract)
if (!defined('DEFAULT_ACTION')) define('DEFAULT_ACTION', 'index');
// include database and application settings
require BASEPATH . '/config/config' . EXT;
// initialize Error & Exceptions handling
require BASEPATH . '/fari/Diagnostics' . EXT;
// initialize the Router (load Controller)
require BASEPATH . '/fari/Router' . EXT;
// initialize the 'optional' Model (business logic)
require BASEPATH . '/fari/Model' . EXT;
// initialize the Controller (load Actions)
require BASEPATH . '/fari/Controller' . EXT;
// initialize the View (templating)
require BASEPATH . '/fari/View' . EXT;
// check that we have a high enough version of PHP (5.2.0)
try { if (version_compare(phpversion(), '5.2.0', '<=') == TRUE) {
throw new Fari_Exception('Fari MVC Framework requires PHP 5.2.0, you are using ' . phpversion() . '.'); }
} catch (Fari_Exception $exception) { $exception->fire(); }
// check if user is using Apache user-directory found on temporary links to web hosting (e.g., http://site.com/~user/)
try { if (substr_count(WWW_DIR, '~') > 0) {
throw new Fari_Exception('Apache user-directory ' . WWW_DIR . ' not supported by Fari Framework.'); }
} catch (Fari_Exception $exception) { $exception->fire(); }
// autoload Model classes when needed (before exception is thrown)
function __autoload($className) {
// are we working with a Fari Helper?
if (strpos($className, 'Fari_') === FALSE) {
$modelFilePath = BASEPATH . '/'. APP_DIR . '/models/' . strtolower($className) . EXT;
} else {
// remove fari_ and build path
$modelFilePath = BASEPATH . '/fari/helpers/' . substr($className, 5) . EXT;
}
try {
// check that model class exists
if (!file_exists($modelFilePath)) {
throw new Fari_Exception('Missing Model Class: ' . $modelFilePath . '.');
} else include($modelFilePath); // include file
} catch (Fari_Exception $exception) { $exception->fire(); }
}
// load Controller on static Router
Fari_Router::loadRoute();