Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI_Runtime
- * @package ILLI
- * @subpackage Runtime
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\Runtime;
- /**
- * ILLI Thread
- *
- * @category ILLI_Runtime
- * @package ILLI
- * @subpackage Runtime
- * @namespace ILLI\Runtime
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.0-1
- * @version 2.0.0-1
- */
- ABSTRACT CLASS Thread
- {
- private static $__instances = [];
- public static function getThread()
- {
- $thread = self::getThreadName();
- if(FALSE === array_key_exists($thread, self::$__instances))
- self::$__instances[$thread] = new $thread;
- return self::$__instances[$thread];
- }
- public static function getThreadName()
- {
- return get_called_class();
- }
- protected function __construct()
- {
- }
- protected function __clone()
- {
- }
- }
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI_Runtime
- * @package ILLI
- * @subpackage Runtime
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\Runtime;
- /**
- * ILLI Load Class
- *
- * Extract namespace and real-name of requested class and create the file-path
- *
- * Example: load class \ILLI\System\Collection\Test_Loader
- *
- * Base NS: \ILLI
- * NS: \System\Collection
- * Class Test_Loader
- *
- * File: /ILLI/System.Collection/Test/Loader.php
- *
- * <code>
- * ILLI\Runtime\Load_Class Object
- * (
- * [__requestOrig :ILLI\Runtime\Load_Class:private] => ILLI\System\Collection\Test_Loader
- * [__request :ILLI\Runtime\Load_Class:private] => ILLI/System/Collection/Test_Loader
- * [__class :ILLI\Runtime\Load_Class:private] => Test_Loader
- * [__namespace :ILLI\Runtime\Load_Class:private] => ILLI\System\Collection
- * [__ns :ILLI\Runtime\Load_Class:private] => System\Collection
- * [__nsBase :ILLI\Runtime\Load_Class:private] => ILLI/
- * [__nsDir :ILLI\Runtime\Load_Class:private] => System.Collection/
- * [__nsPath :ILLI\Runtime\Load_Class:private] => ILLI/System.Collection/
- * [__classDir :ILLI\Runtime\Load_Class:private] => Test/Loader
- * [__file :ILLI\Runtime\Load_Class:private] => ILLI/System.Collection/Test/Loader
- * [__filePath :ILLI\Runtime\Load_Class:private] => ILLI/System.Collection/Test/Loader.php
- * )
- * </code>
- *
- * @category ILLI_Runtime
- * @package ILLI
- * @subpackage Runtime
- * @namespace ILLI\Runtime
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.0-1
- * @version 2.0.0-1
- */
- CLASS Loader
- {
- private static $__cache = [];
- private static $__NDS = '.';
- private static $__CDS = DIRECTORY_SEPARATOR;
- private $__requestOrig = NULL;
- private $__request = NULL;
- private $__class = NULL;
- private $__namespace = NULL;
- private $__ns = NULL;
- private $__nsBase = NULL;
- private $__nsDir = NULL;
- private $__nsPath = NULL;
- private $__classDir = NULL;
- private $__file = NULL;
- private $__filePath = NULL;
- public function __construct($request)
- {
- if(TRUE === array_key_exists($request, self::$__cache))
- return;
- $this->__requestOrig = $request;
- $this->__request = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $this->__requestOrig);
- $_nA =
- $_nB = explode(DIRECTORY_SEPARATOR, $this->__request);
- $f = 0;
- $s = sizeof($_nA);
- $l = $s - 1;
- $this->__nsBase = ($l === 0) ? NULL : $_nA[$f].DIRECTORY_SEPARATOR;
- $this->__class = $_nA[$l];
- unset($_nA[$l], $_nB[$l], $_nB[$f], $request);
- $this->__namespace = ($l === 0) ? NULL : implode('\\', $_nA);
- $this->__ns = ($l === 0) ? NULL : implode('\\', $_nB);
- $this->__nsDir = ($l <= 1) ? NULL : implode(self::$__NDS, $_nB).DIRECTORY_SEPARATOR;
- $this->__nsPath = ($l === 0) ? NULL : $this->__nsBase.$this->__nsDir;
- $this->__classDir = str_replace('_', self::$__CDS, $this->__class);
- $this->__file = $this->__nsBase.$this->__nsDir.$this->__classDir;
- $this->__filePath = $this->__file.'.php';
- /*
- $current="";
- foreach($namespaces as $namepart)
- {
- $current.='\\' . $namepart;
- if(in_array($current, self::$loadedNamespaces))
- continue;
- $fnload = $current . DIRECTORY_SEPARATOR . "__init.php";
- if(file_exists($fnload))
- require($fnload);
- self::$loadedNamespaces[] = $current;
- }*/
- }
- public static function extract($request)
- {
- return new self($request);
- }
- public static function getCache()
- {
- return self::$__cache;
- }
- public function getFilePath()
- {
- return $this->__filePath;
- }
- public function getClassRealName()
- {
- return $this->__class;
- }
- public function getClassPath()
- {
- return $this->__file;
- }
- public function getClassDir()
- {
- return $this->__classDir;
- }
- public function getNs()
- {
- return $this->__ns;
- }
- public function getNsDir()
- {
- return $this->__nsDir;
- }
- public function getNsPath()
- {
- return $this->__nsPath;
- }
- public function getNsBase()
- {
- return $this->__nsBase;
- }
- public function getRequestOriginal()
- {
- return $this->__requestOrig;
- }
- public function getRequest()
- {
- return $this->__request;
- }
- public function getNamespace()
- {
- return $this->__namespace;
- }
- }
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI_Runtime
- * @package ILLI
- * @subpackage Runtime
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\Runtime;
- USE \ILLI\Application AS Application;
- USE \ILLI\System\IO\Directory AS Directory;
- USE \ILLI\Runtime\Thread AS Thread;
- require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'Thread.php';
- require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'Loader.php';
- /**
- * ILLI Initial Program
- *
- * Note:
- * An instance of ILLI\Program must be extended by ILLI\Application.
- *
- * @category ILLI_Runtime
- * @package ILLI
- * @subpackage Runtime
- * @namespace ILLI\Runtime
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.0-1
- * @version 2.0.0-1
- * @abstract
- */
- ABSTRACT CLASS Program EXTENDS Thread
- {
- private static $__installDir = NULL;
- private static $__vendorDir = NULL;
- private static $__instances = [];
- private $__threadName = NULL;
- private $__autoLoader = [];
- final public static function getThread()
- {
- $thread = self::getThreadName();
- if(TRUE === array_key_exists($thread, self::$__instances))
- return self::$__instances[$thread];
- self::$__instances[$thread] = parent::getThread();
- self::$__instances[$thread]->__threadName = $thread;
- self::$__instances[$thread]->__autoLoader = [$thread, 'loadClass'];
- self::registerAutoloadFunction();
- Directory::registerIncludePath(self::getVendorDir());
- Directory::registerIncludePath(self::getInstallDir());
- if(FALSE === (self::$__instances[$thread] instanceOf Application))
- throw new ProgramException(self::$__instances[$thread], E::INSTANCE_OF_APPLICATION_EXPECTED,
- ['thread' => $thread, 'class' => __CLASS__, 'required' => __NAMESPACE__.'\Application']);
- return self::$__instances[$thread];
- }
- final public static function loadClass($request)
- {
- $file = self::getVendorDir().(new Loader($request))->getFilePath();
- if(FALSE === is_file($file))
- throw new ProgramException(self::$__instances[self::getThreadName()], E::CLASSFILE_NOT_FOUND,
- ['thread' => parent::getThreadName(), 'request' => $request, 'file' => $file]);
- if(FALSE === is_readable($file))
- throw new ProgramException(self::$__instances[self::getThreadName()], E::CLASSFILE_NOT_ACCESSIBLE,
- ['thread' => parent::getThreadName(), 'request' => $request, 'file' => $file]);
- require_once $file;
- if(FALSE === class_exists($request, FALSE)
- && FALSE === interface_exists($request, FALSE))
- throw new ProgramException(self::$__instances[self::getThreadName()], E::CLASS_OR_INTERFACE_EXPECTED,
- ['thread' => parent::getThreadName(), 'request' => $request, 'file' => $file]);
- }
- final public static function getVendorDir()
- {
- return (NULL !== self::$__vendorDir)
- ? self::$__vendorDir
- : self::$__vendorDir = realpath(dirname(self::getInstallDir())).DIRECTORY_SEPARATOR;
- }
- final public static function getInstallDir()
- {
- return (NULL !== self::$__installDir)
- ? self::$__installDir
- : self::$__installDir = realpath(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR;
- }
- final public function __destruct()
- {
- self::unregisterAutoloadFunction();
- }
- private static function registerAutoloadFunction()
- {
- spl_autoload_register(self::$__instances[self::getThreadName()]->__autoLoader);
- }
- private static function unregisterAutoloadFunction()
- {
- spl_autoload_unregister(self::$__instances[self::getThreadName()]->__autoLoader);
- }
- //abstract protected function getConfig();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement