PHP Code:
<?php defined( 'COREPATH' ) or
die( 'Direct access to this file is
forbidden.' );
/// These values should be left
for ScriptID
define(
'IC_VERSION' , '1.0' );
define( 'IC_CODE_NAME' , 'app
debuti' );
/**
* IoniCore class
*
* Main class that handles most
of IoniCore's processes
*
* @package IoniCore PHP
* @author Neo Ighodaro
* @copyright CreativityKills
* @license http://removed
*/
class ionicore{
protected static $cache;
protected static $lang_dir;
protected static $force_locale;
protected static $config_dir;
/**
* Class constructor
*
* @return void
*/
private function __construct(){
if( ! is_array($this-
> cache))$
this->cache = array();
$this->lang_dir =
'lang' ;
$this->force_locale = false;
$this->config_dir =
'config' ;
}
public static function
autoloader($class){
/// capitalize the first letter in
classname
$class = ucfirst($class);
/// set classes array in cache
self::write_cache(
'classes' );
/// if class already exists
if(class_exists($class)){
self::write_cache(
'classes' , $
class, array());
return;
}
/// get path to file
$file = COREPATH.
'classes/' .$
class. '.php' ;
/// Find file in directory
if(file_exists($file)){
include_once($file);
self::write_cache(
'classes' , $
class, array( 'file' => $file));
return;
}
}
public static function load($
key){
/// prepare the key
if(strpos(
'.' ,$key) === TRUE){
list($dir,$file) = explode( '.' , trim
($key), 2);
$_dir = $dir;
}else{
throw new ionicore_Exception
(sprintf(self::lang
(
'syserror.invalid_key' ),$key));
return FALSE;
}
die(
'ha' );
/// Set load array in cache
self::write_cache(
'load' );
/// check if key is cached
if(array_key_exists($key, self::$
cache[
'load' ]))return TRUE;
/// get the file path
$dir = self::$lang_dir;
$locale = (self::$force_locale) ?
self::$force_locale : self::config
(
'core.default_locale' );
$loadfile = $dir. '/' .$locale. '/' .$
file. '.php' ;
}else{
$loadfile = $dir.
'/' .$file. '.php' ;
}
/// Include the file
if( ! file_exists($loadfile)){
throw new ionicore_Exception
(sprintf(ionicore::lang
(
'syserror.file_not_found' ),$
loadfile));
return FALSE;
}else{
/// include file and cache data
if(include_once($loadfile)){
$file_var = (isset($$_dir)) ? $$_
dir : array();
$cache = array($$_dir => $file_
var);
ionicore::write_cache(
'load' , $
key, $cache);
return TRUE;
}
}
/// Script will probably never
get here
throw new ionicore_Exception
(self::lang(
'syserror.unknown_
error' ));
return FALSE;
}
/**
* Loads a value or values
(array) from a config file
*
* @param string file_
name.array_key
* @return string/array
*/
public static function config($
key){
/// Prepare key for use
if(strpos(
'.' ,$key) === TRUE){
list($file,$val) = explode( '.' , trim
($key), 2);
}else{
/// Load entire file array
$file = $key;
$val = false;
}
/// Load config file
$loadkey = self::$config_dir.'.'.$
file;
try{
self::load($loadkey);
}catch(ionicore_Exception $e){
echo $e->errorMessage();
}
/// check if load updated cache
$cache = self::$cache[
'load' ][$
loadkey][self::$config_dir];
if(isset($cache) AND ! empty($
cache)){
return ($val) ? $cache[$val] : $
cache;
}else{
return null;
}
}
public static function lang($key,
$force_locale = false){
/// force another locale
if($force_locale)self::$force_
locale = $force_locale;
/// Prepare key for use
if(strpos(
'.' ,$key) === TRUE){
list($file,$val) = explode( '.' , trim
($key), 2);
}else{
/// Load entire file array
$file = $key;
$val = false;
}
/// Load lang file
$loadkey =
'lang.' .$file;
try{
self::load($loadkey);
}catch(ionicore_Exception $e){
echo $e->errorMessage();
}
/// check if load updated cache
$cache = self::$cache[ 'load' ][$
loadkey][ 'lang' ];
if(isset($cache) AND ! empty($
cache)){
return ($val) ? $cache[$val] :
(array) $cache;
}else{
return null;
}
}
/**
* Writes value to class cache
*
* @param string
* @param string
* @param array
* @return boolean
*/
private static function write_
cache($key, $subkey=null, $
val=array()){
try{
if( ! $key || ! is_array($val))
throw new ionicore_Exception
(self::lang(
'syserror.invalid_
param' ));
return false;
}catch(ionicore_Exception $e){
echo $e->errorMessage();
}
if( ! array_key_exists($key,self::
$cache)){
$key = array($key => array());
self::$cache = array_merge($
key,self::$cache);
}
if($subkey AND ! array_key_
exists($subkey,self::$cache[$
key])){
$key = array($subkey => $val);
self::$cache[$key] = array_
merge($subkey,self::$cache[$
key]);
}
return true;
}
/**
* Resets class cache
*
* @return void
*/
public static function reset_
cache(){
self::$cache = array();
}
/**
* Generates a backtrace for
debugging
*
* @return string
*/
public static function backtrace
(){
return
'@todo' ;
}
} /// End of class:
'ionicore'
Comment