Advertisement
Etki

Untitled

Apr 8th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1.     class PHPDaemonLoadHelper
  2.     {
  3.         protected $basePath;
  4.         protected static $initialized = false;
  5.         protected function __construct(){}
  6.         public static function register($basePath)
  7.         {
  8.             if (self::$initialized) {
  9.                 return; // защита от повторной регистрации
  10.             }
  11.             self::$initialized = true;
  12.             $instance = new self;
  13.             $instance->basePath = $basePath;
  14.             spl_autoload_register(array($instance, 'loadClass'));
  15.         }
  16.         public function loadClass($name) {
  17.             $filePath = $this->basePath.DIRECTORY_SEPARATOR.$className.'.php';
  18.             if (file_exists($filePath)) {
  19.                 include($filePath);
  20.             }
  21.         }
  22.     }
  23.     ...
  24.     namespace \PHPDaemon\Applications;
  25.     class DummyApp {
  26.         public function __construct()
  27.         {
  28.             ...
  29.             PHPDaemonLoadHelper::register('/var/www/mysite/classes');
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement