Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI
- * @package ILLI
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright 2007-2011, ILLI Conference
- */
- /**
- * ILLI Core
- *
- * init -> configure -> run
- *
- * @category ILLI
- * @package ILLI
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright 2007-2011, ILLI Conference
- */
- CLASS ILLI
- {
- /**
- * instance
- *
- * @var ILLI $__ILLI
- * @static
- */
- private static $__ILLI = NULL;
- /**
- * VENDOR-path
- *
- * @var string $__installDir
- * @static
- */
- private static $__installDir = NULL;
- /**
- * initialize instance of ILLI
- *
- * @return ILLI instance
- * @uses ILLI::getInstallDir()
- * @uses ILLI::registerIncludePath()
- * @uses ILLI::ILLI
- * @uses ILLI::$__ILLI
- * @uses ILLI::__construct()
- * @static
- */
- public static function init()
- {
- self::registerIncludePath(self::getInstallDir());
- self::registerIncludePath(self::getInstallDir().__CLASS__);
- self::registerAutoloadFunction();
- return ((NULL !== self::$__ILLI)
- ? self::$__ILLI
- : self::$__ILLI = new self);
- }
- /**
- * register include-path
- *
- * @param string $path full directory
- * @return ILLI|NULL instance of ILLI
- * @uses ILLI::$__ILLI
- * @uses ILLI_Exception_DataHandlerNotFound
- * @uses ILLI_Exception_DataHandlerNotFound::ERROR_PATH_NOT_FOUND
- * @throws {@link ILLI_Exception_DataHandlerNotFound::ERROR_PATH_NOT_FOUND}
- * @static
- */
- public static function registerIncludePath($path = NULL)
- {
- $path = realpath($path);
- if(FALSE === $path)
- throw new ILLI_Exception_DataHandlerNotFound
- (ILLI_Exception_DataHandlerNotFound::ERROR_PATH_NOT_FOUND, $file);
- set_include_path(implode(PATH_SEPARATOR, array
- (
- $path,
- get_include_path()
- )));
- return self::$__ILLI;
- }
- /**
- * get install-path (VENDOR-path)
- *
- * @return string install-path (VENDOR-path)
- * @uses ILLI::$__installDir
- * @static
- */
- public static function getInstallDir()
- {
- return ((NULL !== self::$__installDir)
- ? self::$__installDir
- : (self::$__installDir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR));
- }
- /**
- * load php-file
- *
- * @param string $file absolute or relative path below {@link ILLI::$__installDir}
- * @return bool
- * @uses ILLI::getInstallDir()
- * @uses ILLI::loadFile()
- * @uses ILLI_Exception_DataHandlerNotFound
- * @uses ILLI_Exception_DataHandlerNotFound::ERROR_FILE_NOT_FOUND
- * @throws {@link ILLI_Exception_DataHandlerNotFound::ERROR_FILE_NOT_FOUND}
- * @static
- */
- public static function loadFile($file)
- {
- if(is_file($file))
- {
- require_once $file;
- return TRUE;
- }
- if(substr($file, 0, strlen(self::getInstallDir())) != self::getInstallDir())
- return self::loadFile(self::getInstallDir().$file);
- throw new ILLI_Exception_DataHandlerNotFound
- (ILLI_Exception_DataHandlerNotFound::ERROR_FILE_NOT_FOUND, $file);
- return FALSE;
- }
- /**
- * load class
- *
- * @param string $request class-name or equivalent file-path below {@link ILLI::$__installDir}
- * @return bool
- * @uses ILLI::registerAutoloadFunction()
- * @uses ILLI::loadFile()
- * @uses ILLI::getInstallDir()
- * @uses ILLI::isInstantiable()
- * @static
- */
- public static function loadClass($request)
- {
- $class = str_replace(array('/', '\\'), '_', $request);
- $path = str_replace(array('_'), DIRECTORY_SEPARATOR, $class);
- $file = $path.'.php';
- //var_dump(array($request, $class, $path, $file));
- return ((TRUE === self::loadFile(self::getInstallDir().$file))
- ? self::isInstantiable($class)
- : FALSE);
- }
- /**
- * instantiable-check of a class
- *
- * @param string $class class-name
- * @return bool
- * @uses ILLI_Exception_DataHandlerNotFound
- * @uses ILLI_Exception_DataHandlerNotFound::ERROR_CLASS_NOT_FOUND
- * @throws {@link ILLI_Exception_DataHandlerNotFound::ERROR_CLASS_NOT_FOUND}
- * @static
- */
- public static function isInstantiable($class)
- {
- try
- {
- $r = new ReflectionClass($class);
- return $r->isInstantiable();
- }
- catch(ReflectionException $e)
- {
- throw new ILLI_Exception_DataHandlerNotFound
- (ILLI_Exception_DataHandlerNotFound::ERROR_CLASS_NOT_FOUND, $e, $class);
- }
- }
- /**
- * complicated stuff
- */
- private function __construct()
- {
- }
- /**
- * register __autoload
- *
- * @uses ILLI::loadClass()
- * @static
- */
- private static function registerAutoloadFunction()
- {
- spl_autoload_register(array(__CLASS__, 'loadClass'));
- }
- }
- try
- {
- ILLI::init();
- new blaaa;
- }
- catch(ILLI_Exception_DataHandlerNotFound $e)
- {
- switch($e->getCode()...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement