php -------------------- -------------- package Base version author Fe

  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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/*
==================================
H E L L Y C M S
----------------------------------
@package: Base
@version: 0.4
@author: Fesor
@eMail: fesors@gmail.com
@homepage: helly.fesor.ru
@inspiration: YII Framework
==================================
*/
$time = microtime(1);
define('ROOT', dirname(__FILE__).'/');
define('SYSTEM', ROOT.'system/');
define('APPS', ROOT.'apps/');
define('CACHE', ROOT.'cache/');
function __autoload($name)
{
require system::$components[strtolower($name)];
}
class system
{
private static $isAjax;
private static $_app;
private static $_data=array();
private static $_messages=array();
private static $rebuildData = false;
private static $rebuildMessages = false;
//Initialisation of system
public function __construct()
{
new cache;
//Load of configs
if(cache::isCached('data'))
self::$_data = cache::get('data');
else
{
self::$_data['configs']['_system'] = require ROOT.'data/configs.php';
self::$_data['params']['_system'] = require ROOT.'data/params.php';
self::$rebuildData = true;
}
//Load messages of system
if(cache::isCaches('messages-'.self::$_data['configs']['_system']['local']))
self::$_messages = cache::get('messages-'.self::$_data['configs']['_system']['local']);
else
{
self::$_messages['_system'] = require ROOT.'data/messages/'.self::$_data['configs']['_system']['local'].'.php';
self::$rebuildMessages = true;
}
//Define URI string
self::$uri = new router;
//Match APP
self::$_app = router::getAppName();
//Load configs of application
if(!isset(self::$_data['configs'][self::$_app])
{
self::$_data['configs'][self::$_app] = require APPS.'data/configs.php';
self::$rebuildData = true;
//Prepare routing rules
if(isset(self::$_data['configs'][self::$_app]['routing']))
self::$_data['configs'][self::$_app]['routing'] = router::prepare(self::$_data['configs'][self::$_app]['routing']);
}
if(!isset(self::$_data['params'][self::$_app])
{
self::$_data['params'][self::$_app] = require APPS.'data/params.php';
self::$rebuildData = true;
}
//Load messages of application
if(!isset(self::$_messages[self::$_app]))
{
self::$_messages[self::$_app] = require APPS.'data/messages/'.self::$_data['configs']['_system']['local'].'.php';
self::$rebuildMessages = true;
}
//Match Route
self::$route = router::getRoute(self::$_data['configs'][self::$_app]['routing']);
//Initialise application
self::$_app = new CApplication(self::$_app, self::$route);
//Render Layout
view::RenderLayout();
}
//return's singleton of application
public function app()
{
return self::$_app;
}
//return's configs
public function getConfig($name, $app="_system")
{
if(isset(self::$_data['configs'][$app][$name]))
return self::$_data['configs'][$app][$name];
}
//return's params
public function getParams($name, $app="_system")
{
if(isset(self::$_data['params'][$app][$name]))
return self::$_data['params'][$app][$name];
}
public function message($msg, $app="_system")
{
return isset(self::$_messages[$app][$msg])? self::$_messages[$app][$msg] : $msg ;
}
//Check's is ajax callback or not
public function isAjaxCallback()
{
if(is_null(self::$isAjax))
self::$isAjax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')? true:false;
return self::$isAjax;
}
public static $components = array(
'capplication' => 'base/application.php',
'cmodel' => 'base/model.php',
'cplugin' => 'base/plugin.php',
'cwidget' => 'base/widget.php',
'ccontroller' => 'base/controller.php',
'view' => 'base/view.php',
'viewcompiler' => 'base/view.compiler.php',
'activerecord' => 'db/ar.php',
'cache' => 'cache/base.php',
);
}
new system;
echo "<!-- Execution time: ".round(microtime(1)-$time, 4)." Seconds | Memory used: ".round(memory_get_usage()/1024)." Kb -->";