framework startup... stupid lil idea... Oo
By: fruffl | Date: Nov 24 2009 06:02 | Format: PHP | Expires: never | Size: 13.43 KB | Hits: 1446
- <?php
- require_once('./FRUFFL/FRUFFL.php');
- $FRUFFL = new FRUFFL();
- 'FRUFFL_AUTOLOAD' => 'PAGE',
- 'test' => '123',
- 'subversion' => 1005,
- 'revision' => 11.5
- )));
- echo "<pre>";
- ?>
- <?php
- class FRUFFL_EXCEPTION EXTENDS EXCEPTION
- {
- 1010 => 'Unable to set variable "%1$s". It was already set.',
- 1100 => 'The constant "%1$s" is already defined.',
- 1110 => 'Directory "%1$s", defined in "%2$s", not found.',
- 1120 => 'File "%1$s", defined in "%2$s", not found.',
- 1130 => 'The given value "%1$s", defined in your init_config at key "%2$s", isn't a valid argument.',
- 0000 => 'Error in <b>%1$s</b> detected:<br />',
- 9999 => 'Invalid error-code given: "%1$d"',
- );
- final public static function e($error_code, $location)
- {
- $args = func_get_args();
- unset($args[0]);
- unset($args[1]);
- try
- {
- if(array_key_exists($error_code, self::$errors))
- {
- $error = vsprintf(self::$errors[$error_code], $args);
- }
- else
- {
- throw new FRUFFL_EXCEPTION
- (
- self::e
- (
- 9999,
- array('class' => __CLASS__, 'method' => __METHOD__, 'function' => __FUNCTION__),
- $error_code
- ),
- 9999
- );
- }
- }
- catch(self $e)
- {
- self::w($e);
- }
- return sprintf(self::$errors[0], $location['method']).$error;
- }
- final public static function w($e)
- {
- $fire_b = '<div style="background: #ccc; color: #222; font-size: 11px; font-family: monospace; padding: 20px;">%1$s</div>';
- $fire_l = '<div>%1$s:</div><div style="padding-left: 50px;">%2$s</div>';
- $fire_t = '<table><tr>%1$s</tr></table>';
- $fire_r = '<td>%1$s::%2$s</td>';
- foreach(($r = $e->getTrace()) as $b)
- {
- $_t = '';
- foreach($b as $k => $v)
- if($k != 'args')
- {
- $t .= sprintf($fire_l, $k, $v);
- }
- else
- {
- $_a = '';
- foreach($b['args'] as $s => $a)
- if(is_array($a))
- foreach($a as $c => $b)
- $_a .= sprintf($fire_l, $c, nl2br($b));
- $t .= sprintf($fire_l, 'args', $_a);
- }
- $t .= sprintf($fire_b, $_t);
- }
- echo sprintf($fire_b,
- sprintf($fire_l, 'Error-Code', nl2br($e->getCode())).
- sprintf($fire_l, 'Line', nl2br($e->getLine())).
- sprintf($fire_l, 'Exception', get_class($e)).
- sprintf($fire_l, 'Message', nl2br($e->getMessage())).
- sprintf($fire_l, 'String', nl2br($e->getTraceAsString())).
- sprintf($fire_l, 'Backtrace', $t)
- );
- }
- }
- class FRUFFL_INIT_EXCEPTION EXTENDS FRUFFL_EXCEPTION{}
- class FRUFFL_CONFIG_EXCEPTION EXTENDS FRUFFL_EXCEPTION{}
- class FRUFFL_CONST_EXCEPTION EXTENDS FRUFFL_EXCEPTION{}
- class FRUFFL_REGISTER_EXCEPTION EXTENDS FRUFFL_EXCEPTION{}
- abstract class FRUFFL_REGISTER
- {
- protected static $register = array();
- protected static $encrypt_key = 1;
- final protected static function crypt($key)
- {
- if(self::$encrypt_key)
- {
- if(function_exists(self::$encrypt_method))
- {
- $func = self::$encrypt_method;
- $crypt = $func($key);
- return $crypt;
- }
- return $key;
- }
- return $key;
- }
- final public static function set($key, $value)
- {
- try
- {
- if (!isset(self::$register[self::crypt($key)]))
- {
- self::$register[self::crypt($key)] = $value;
- return true;
- }
- else
- {
- throw new FRUFFL_REGISTER_EXCEPTION
- (
- FRUFFL_REGISTER_EXCEPTION::e
- (
- ($ec = 1010),
- array('class' => __CLASS__, 'method' => __METHOD__, 'function' => __FUNCTION__),
- $key
- ),
- $ec
- );
- }
- }
- catch(FRUFFL_REGISTER_EXCEPTION $e)
- {
- FRUFFL_REGISTER_EXCEPTION::w($e);
- }
- }
- final public static function get($key)
- {
- if (isset(self::$register[self::crypt($key)]))
- return self::$register[self::crypt($key)];
- return null;
- }
- final public static function getAll()
- {
- return self::$register;
- }
- final public static function remove($key)
- {
- if (isset(self::$register[self::crypt($key)]))
- {
- unset(self::$register[self::crypt($key)]);
- return true;
- }
- return false;
- }
- final public static function removeAll()
- {
- self::$register = array();
- return;
- }
- }
- INTERFACE _FRUFFL_CONFIG
- {
- public function __construct(array $init_config = array());
- }
- class FRUFFL_CONFIG IMPLEMENTS _FRUFFL_CONFIG
- {
- const VERSION = 1000;
- protected $_____valid_config_arguments = array('int' => array('subversion'),
- 'string' => array('FRUFFL_AUTOLOAD' => array('PAGE','IMAGE','BINICON','CAPTCHA','XML'), 'test' => '123'),
- 'float' => array('revision'),
- );
- public function __construct(array $init_config = array('FRUFFL_AUTOLOAD' => 'PAGE'))
- {
- if(FRUFFL_REGISTER::get(($__ = 'FRUFFL_EXECUTE_INIT_CONST')))
- if($this->init_const())
- FRUFFL_REGISTER::remove($__);
- $this->init_config($init_config);
- }
- protected function init_config(array $i)
- {
- if(is_array($i))
- {
- $c = array();
- try
- {
- foreach($this->_____valid_config_arguments as $o => $p)
- if(is_array($p) && count($p) > 0)
- foreach($p as $k => $v)
- if(is_string($k))
- {
- if(is_array($v))
- {
- if(in_array($i[$k], $v))
- {
- $c[$o][$k] = $i[$k];
- unset($i[$k]);
- }
- else
- {
- throw new FRUFFL_CONFIG_EXCEPTION
- (
- FRUFFL_CONFIG_EXCEPTION::e
- (
- ($ec = 1130),
- array('class' => __CLASS__, 'method' => __METHOD__, 'function' => __FUNCTION__),
- $i[$k],
- $k
- ),
- $ec
- );
- }
- }
- else
- {
- if($v == $i[$k])
- {
- $c[$o][$k] = $i[$k];
- unset($i[$k]);
- }
- else
- {
- throw new FRUFFL_CONFIG_EXCEPTION
- (
- FRUFFL_CONFIG_EXCEPTION::e
- (
- ($ec = 1130),
- array('class' => __CLASS__, 'method' => __METHOD__, 'function' => __FUNCTION__),
- $i[$k],
- $k
- ),
- $ec
- );
- }
- }
- }
- else
- {
- if(array_key_exists($v, $i))
- {
- $c[$o][$v] = $i[$v];
- unset($i[$v]);
- }
- }
- if(is_array($i) && (count($i) > 0))
- foreach($i as $k => $v)
- throw new FRUFFL_CONFIG_EXCEPTION
- (
- FRUFFL_CONFIG_EXCEPTION::e
- (
- ($ec = 1140),
- array('class' => __CLASS__, 'method' => __METHOD__, 'function' => __FUNCTION__),
- $k
- ),
- $ec
- );
- }
- catch(FRUFFL_CONFIG_EXCEPTION $e)
- {
- FRUFFL_CONFIG_EXCEPTION::w($e);
- }
- foreach($c as $o => $p)
- foreach($p as $k => $v)
- {
- FRUFFL_REGISTER::remove($k);
- switch($o)
- {
- case 'int':
- $config[$k] = intval($v);
- FRUFFL_REGISTER::set($k, intval($v));
- break;
- case 'string':
- if(is_string($v)) FRUFFL_REGISTER::set($k, $v);
- break;
- if(is_array($v)) FRUFFL_REGISTER::set($k, $v);
- if(is_string($v)) FRUFFL_REGISTER::set($k, explode(',', str_replace(' ', null, $v)));
- break;
- case 'float':
- $config[$k] = FRUFFL_REGISTER::set($k, floatval($v));
- break;
- }
- }
- unset($c);
- }
- }
- protected function init_const()
- {
- $c = array(
- 'FRUFFL_GLOBAL_VERSION' => self::VERSION,
- 'FRUFFL_GLOBAL_SYSTEM_ROOT' => rtrim(str_replace(array("/","\"), DIRECTORY_SEPARATOR,
- dirname(dirname(__FILE__))), '/\').DIRECTORY_SEPARATOR,
- 'FRUFFL_GLOBAL_SYSTEM_DIR' => rtrim(str_replace(array("/","\"), DIRECTORY_SEPARATOR,
- dirname(__FILE__)), '/\').DIRECTORY_SEPARATOR.self::VERSION.DIRECTORY_SEPARATOR,
- 'FRUFFL_GLOBAL_ROOT_PAGE' => rtrim(str_replace(array("/","\"), DIRECTORY_SEPARATOR,
- $_SERVER[SCRIPT_FILENAME]), '/\')
- );
- $c = array_merge($c, array(
- 'FRUFFL_DIR_SYSTEM_SOURCE' => $c['FRUFFL_GLOBAL_SYSTEM_DIR'] ."SOURCE" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_CUSTOM' => $c['FRUFFL_GLOBAL_SYSTEM_DIR'] ."CUSTOM" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_MEDIA' => $c['FRUFFL_GLOBAL_SYSTEM_DIR'] ."MEDIA" .DIRECTORY_SEPARATOR,
- ));
- $c = array_merge($c, array(
- 'FRUFFL_DIR_SYSTEM_SOURCE_AUTOLOADER' => $c['FRUFFL_DIR_SYSTEM_SOURCE'] ."autoloader" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_SOURCE_BINARIES' => $c['FRUFFL_DIR_SYSTEM_SOURCE'] ."binaries" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_SOURCE_INCLUDES' => $c['FRUFFL_DIR_SYSTEM_SOURCE'] ."includes" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_SOURCE_LIBRARIES' => $c['FRUFFL_DIR_SYSTEM_SOURCE'] ."libraries" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_SOURCE_STATICS' => $c['FRUFFL_DIR_SYSTEM_SOURCE'] ."statics" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_CUSTOM_AUTOLOADER' => $c['FRUFFL_DIR_SYSTEM_CUSTOM'] ."autoloader" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_CUSTOM_BINARIES' => $c['FRUFFL_DIR_SYSTEM_CUSTOM'] ."binaries" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_CUSTOM_INCLUDES' => $c['FRUFFL_DIR_SYSTEM_CUSTOM'] ."includes" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_CUSTOM_LIBRARIES' => $c['FRUFFL_DIR_SYSTEM_CUSTOM'] ."libraries" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_MEDIA_LANGUAGES' => $c['FRUFFL_DIR_SYSTEM_MEDIA'] ."languages" .DIRECTORY_SEPARATOR,
- 'FRUFFL_DIR_SYSTEM_MEDIA_TEMPLATES' => $c['FRUFFL_DIR_SYSTEM_MEDIA'] ."templates" .DIRECTORY_SEPARATOR,
- ));
- foreach ($c as $k => $v)
- {
- try
- {
- if(substr($k, 0, 12) == 'FRUFFL_GLOBAL_')
- {
- FRUFFL_REGISTER::set($k, $v);
- }
- else
- if(substr($k, 0, 9) == 'FRUFFL_DIR_')
- {
- if(is_dir($v))
- {
- FRUFFL_REGISTER::set($k, $v);
- }
- else
- {
- throw new FRUFFL_CONST_EXCEPTION
- (
- FRUFFL_CONST_EXCEPTION::e
- (
- ($ec = 1110),
- array('class' => __CLASS__, 'method' => __METHOD__, 'function' => __FUNCTION__),
- $v,
- $k
- ),
- $ec
- );
- }
- }
- else
- if(substr($k, 0, 10) == 'FRUFFL_FILE_')
- {
- if(is_file($v))
- {
- FRUFFL_REGISTER::set($k, $v);
- }
- else
- {
- throw new FRUFFL_CONST_EXCEPTION
- (
- FRUFFL_CONST_EXCEPTION::e
- (
- ($ec = 1120),
- array('class' => __CLASS__, 'method' => __METHOD__, 'function' => __FUNCTION__),
- $v,
- $k
- ),
- $ec
- );
- }
- }
- }
- catch(FRUFFL_CONST_EXCEPTION $e)
- {
- FRUFFL_CONST_EXCEPTION::w($e);
- }
- }
- return true;
- }
- }
- class FRUFFL
- {
- protected $config;
- public function __construct()
- {
- FRUFFL_REGISTER::set('FRUFFL_EXECUTE_INIT_CONST', true);
- $this->set_config(new FRUFFL_CONFIG(array(
- 'FRUFFL_AUTOLOAD' => 'PAGE',
- 'test' => '123',
- 'subversion' => 1005,
- 'revision' => 11.5
- )));
- if($this->load('shell')) $this->{'__SHELL'} = new SHELL;
- }
- public function set_config(_FRUFFL_CONFIG $config)
- {
- $this->config = $config;
- }
- public function __get($key)
- {
- if (!empty($key))
- {
- if(isset($this->$key))
- {
- return $this->$key;
- }
- else
- {
- return FRUFFL_REGISTER::get($key);
- }
- }
- }
- public function load($class, $type = 'SOURCE')
- {
- $f = ($_ = FRUFFL_REGISTER::get('FRUFFL_DIR_SYSTEM_'.strtoupper($type).'_INCLUDES')).'FRUFFL.%1$s.%2$s.php';
- if(!$_)
- return false;
- $c = strtolower($class);
- {
- require_once $_;
- }
- if(is_file(($_ = sprintf($f, 'interface', $c))))
- {
- require_once $_;
- }
- if(is_file(($_ = sprintf($f, 'package', $c))))
- {
- require_once $_;
- }
- if(is_file(($_ = sprintf($f, 'abstract', $c))))
- {
- require_once $_;
- }
- if(is_file(($_ = sprintf($f, 'class', $c))))
- {
- require_once $_;
- }
- if(class_exists($c)) return true;
- }
- }
- ?>
Latest pastes
8 hours ago
1 days ago
3 days ago
3 days ago
3 days ago