<?php
/*
=================================
H E L L Y
---------------------------------
@author : Fesor
@email : fesors@gmail.com
@homepage: http://helly.fesor.ru
@version : 0.8 RC1
@date : 07.08.2009
=================================
*/
$time = microtime(1);
define('ROOT', dirname(__FILE__).'/');
define('SYSTEM', ROOT.'system/');
define('APPS', ROOT.'apps/');
define('CACHE', ROOT.'cache/');
function __autoload($name)
{
require SYSTEM.system::$components[strtolower($name)];
}
//Initialisation of components
new cache;
system::$components['db'] = 'db/drivers/'.system::getConfig('dbDriver').'.php';
class system
{
private static $isAjax,
$_app,
$rebuildDataCache=false,
$rebuildMessagesCache=false,
$_messages,
$_data;
//Initialisation of system
function __construct()
{
//is site in offline mode?
if(!self::getConfig('offline'))
die(self::message('Site is offline!'));
//Define URI string and match route
new router;
//Load and dispatch application
self::$_app = new application( router::getAppName(), router::getRoute() );
//Return page
view::renderLayout();
}
function __destruct()
{
//Rebuild Cache
self::app()->clear();
if(self::$rebuildDataCache)
cache::set('data', self::$_data);
if(self::$rebuildMessagesCache)
cache::set('messages-'.self::$_data['configs']['_system']['local'], self::$_messages);
}
//return's singleton of application
public function app()
{
return self::$_app;
}
//return's configs
public function getConfig($name, $app="_system")
{
//Load configs if it isn't defined
if(!is_null(self::$_data))
{
if(cache::isCached('data'))
self::$_data = cache::get('data');
else
{
self::$_data['configs']['_system'] = require ROOT.'data/configs.php';
self::$rebuildDataCache = true;
}
}
if(!isset(self::$_data['configs'][$app]))
{
if($app == '_system')
self::$_data['configs']['_system'] = require ROOT.'data/configs.php';
else
self::$_data['configs'][$app] = require APPS.$app.'/data/configs.php';
self::$rebuildDataCache = true;
}
return self::$_data['configs'][$app][$name];
}
//return's params
public function getParams($name, $app="_system")
{
//Load params if it isn't defined
if(!is_null(self::$_data))
{
if(cache::isCached('data'))
self::$_data = cache::get('data');
else
{
self::$_data['params']['_system'] = require ROOT.'data/params.php';
self::$rebuildDataCache = true;
}
}
if(!isset(self::$_data['params'][$app]))
{
if($app == '_system')
self::$_data['params']['_system'] = require ROOT.'data/params.php';
else
self::$_data['params'][$app] = require APPS.$app.'/data/params.php';
self::$rebuildDataCache = true;
}
return self::$_data['params'][$app][$name];
}
public function message($msg, $app="_system")
{
if(is_null(self::$_messages) AND cache::isCached('messages-'.system::getConfig('locale')))
self::$_messages = cache::get('messages-'.system::getConfig('locale'));
if(!isset(self::$_messages[$app]))
{
if($app == '_system')
self::$_data = require ROOT.'data/messages/'.system::getConfig('locale').'.php';
else
self::$_data = require APPS.$app.'/data/messages/'.system::getConfig('locale').'.php';
self::$rebuildMessageCache = true;
}
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(
'application' => 'base/application.php',
'model' => 'base/model.php',
'widget' => 'base/widget.php',
'controller' => 'base/controller.php',
'view' => 'base/view.php',
'cache' => 'cache/cache.php',
'viewcompiler' => 'base/view_compiler.php',
);
}
new system;
echo "\n<!-- Generated in ".round(microtime(1)-$time, 4)." seconds | Memory used: ".round(memory_get_usage()/1024)." KB -->";