Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PHPDaemonLoadHelper
- {
- protected $basePath;
- protected static $initialized = false;
- protected function __construct(){}
- public static function register($basePath)
- {
- if (self::$initialized) {
- return; // защита от повторной регистрации
- }
- self::$initialized = true;
- $instance = new self;
- $instance->basePath = $basePath;
- spl_autoload_register(array($instance, 'loadClass'));
- }
- public function loadClass($name) {
- $filePath = $this->basePath.DIRECTORY_SEPARATOR.$className.'.php';
- if (file_exists($filePath)) {
- include($filePath);
- }
- }
- }
- ...
- namespace \PHPDaemon\Applications;
- class DummyApp {
- public function __construct()
- {
- ...
- PHPDaemonLoadHelper::register('/var/www/mysite/classes');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement