<?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 -->";