Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // thread
- NAMESPACE ILLI\Runtime;
- ABSTRACT CLASS Thread
- {
- private static $__instances = array();
- 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()
- {
- }
- }
- // program
- 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';
- ABSTRACT CLASS Program EXTENDS Thread
- {
- private static $__autoloadFunction = 'loadClass';
- private static $__installDir = NULL;
- private static $__vendorDir = NULL;
- private static $__instances = array();
- private $__threadName = NULL;
- private $__autoloader = array();
- 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 = array($thread, self::$__autoloadFunction);
- self::registerAutoloadFunction();
- Directory::registerIncludePath(self::getVendorDir());
- Directory::registerIncludePath(self::getInstallDir());
- if(FALSE === (self::$__instances[$thread] instanceOf Application))
- throw new ProgramException(E::NO_INSTANCE_OF_APPLICATION, array(
- 'thread' => $thread,
- 'class' => __CLASS__,
- 'required' => __NAMESPACE__.'\Application'));
- return self::$__instances[$thread];
- }
- final public static function loadClass($request)
- {
- $load = Loader::extract($request);
- $file = self::getVendorDir().$load->getFilePath();
- if(FALSE === is_file($file))
- throw new ProgramException(E::CLASSFILE_NOT_FOUND, array(
- 'thread' => parent::getThreadName(),
- 'class' => $request,
- 'path' => $file));
- if(FALSE === is_readable($file))
- throw new ProgramException(E::CLASSFILE_NOT_ACCESSIBLE, array(
- 'thread' => parent::getThreadName(),
- 'class' => $request,
- 'path' => $file));
- require_once $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();
- }
- //index.php
- namespace localhost\illiFW\dev;
- require_once(ILLI_SYSTEM_ROOT.'Runtime/Program.php');
- require_once(ILLI_SYSTEM_ROOT.'Application.php');
- use ILLI\Application as Application;
- use ILLI\Runtime\Program as Program;
- //class root extends Program{} // exception
- class root extends Application{}
- class lucas extends Application{}
- try
- {
- $l = root::getThread();
- $i = lucas::getThread();
- var_dump($l, $i);
- var_dump($l->getThreadName(), $i->getThreadName());
- var_dump(new \ILLI\Runtime\ProgramInfo($l));
- var_dump(new \ILLI\Runtime\ProgramInfo($i));
- }
- catch(\ILLI\Exception\Base $e)
- {
- print $e->export()->asText();
- }
- // result:
- object(localhost\illiFW\dev\root)#1 (2) {
- ["__threadName":"ILLI\Runtime\Program":private]=>
- string(25) "localhost\illiFW\dev\root"
- ["__autoloader":"ILLI\Runtime\Program":private]=>
- array(2) {
- [0]=>
- string(25) "localhost\illiFW\dev\root"
- [1]=>
- string(9) "loadClass"
- }
- }
- object(localhost\illiFW\dev\lucas)#3 (2) {
- ["__threadName":"ILLI\Runtime\Program":private]=>
- string(26) "localhost\illiFW\dev\lucas"
- ["__autoloader":"ILLI\Runtime\Program":private]=>
- array(2) {
- [0]=>
- string(26) "localhost\illiFW\dev\lucas"
- [1]=>
- string(9) "loadClass"
- }
- }
- string(25) "localhost\illiFW\dev\root"
- string(26) "localhost\illiFW\dev\lucas"
- object(ILLI\Runtime\ProgramInfo)#5 (5) {
- ["__fileName":"ILLI\Runtime\ProgramInfo":private]=>
- string(48) "/var/www/clients/client5/web22/web/dev/index.php"
- ["__startLine":"ILLI\Runtime\ProgramInfo":private]=>
- int(15)
- ["__endLine":"ILLI\Runtime\ProgramInfo":private]=>
- int(17)
- ["__hash":"ILLI\Runtime\ProgramInfo":private]=>
- string(32) "0000000025550f220000000018c79413"
- ["__threadName":"ILLI\Runtime\ProgramInfo":private]=>
- string(25) "localhost\illiFW\dev\root"
- }
- object(ILLI\Runtime\ProgramInfo)#5 (5) {
- ["__fileName":"ILLI\Runtime\ProgramInfo":private]=>
- string(48) "/var/www/clients/client5/web22/web/dev/index.php"
- ["__startLine":"ILLI\Runtime\ProgramInfo":private]=>
- int(18)
- ["__endLine":"ILLI\Runtime\ProgramInfo":private]=>
- int(18)
- ["__hash":"ILLI\Runtime\ProgramInfo":private]=>
- string(32) "0000000025550f200000000018c79413"
- ["__threadName":"ILLI\Runtime\ProgramInfo":private]=>
- string(26) "localhost\illiFW\dev\lucas"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement