Esempio n. 1
0
 private function startAutoLoader()
 {
     require_once 'AutoLoader.php';
     $auto_loader = new AutoLoader();
     $auto_loader->addNamespace('sweb', $this->sWebPath);
     $auto_loader->addNamespace($this->pageNS, $this->pagePath);
     $auto_loader->register();
 }
Esempio n. 2
0
 protected static function load_classes()
 {
     $store_key = array(__DIR__, '__autoload');
     if (Store::has($store_key)) {
         $classes = Store::get($store_key);
     } else {
         $classes = array();
         $modules = array();
         $dir = path('libs');
         $itr = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
         $pattern = '/^' . preg_quote($dir, '/') . '\\/(.+?)\\.php$/';
         foreach ($itr as $elem) {
             if ($elem->isFile() && preg_match($pattern, $elem->getPathname(), $match)) {
                 $class_name = $elem->getBasename('.php');
                 if ($class_name == basename($elem->getPath())) {
                     $modules[$class_name] = str_replace('/', '.', substr($elem->getPath(), strlen($dir) + 1));
                 } else {
                     if ($class_name !== __CLASS__) {
                         $classes[$class_name] = str_replace('/', '.', $match[1]);
                     }
                 }
             }
         }
         foreach ($modules as $module_name => $module_path) {
             foreach ($classes as $class_name => $class_path) {
                 if (strpos($class_path, $module_path) === 0) {
                     unset($classes[$class_name]);
                 }
             }
         }
         $classes = $modules + $classes;
         Store::set($store_key, $classes);
     }
     self::$classes = $classes;
 }
Esempio n. 3
0
 public static function createInstance()
 {
     if (self::$autoLoader === null) {
         self::$autoLoader = new AutoLoader();
     }
     return self::$autoLoader;
 }
Esempio n. 4
0
 public static function addFolder($folder)
 {
     if (!is_array($folder)) {
         $folder = array($folder);
     }
     self::$folders = array_merge(self::$folders, $folder);
 }
 /**
  * Returns the instance of the AutoLoader Singleton or instantiates a new one
  * @return AutoLoader
  */
 public static function instance($rootDirectory = null, $reloadClassMap = true, $fileExt = null)
 {
     if (self::$instance == null) {
         self::$instance = new AutoLoader($rootDirectory, $reloadClassMap, $fileExt);
     }
     return self::$instance;
 }
Esempio n. 6
0
 public static function createInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new AutoLoader();
     }
     return self::$instance;
 }
 /**
  *   Singleton - bekomme die laufen instanz vom objekt
  */
 public static function getInstance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Esempio n. 8
0
 /**
  * @see IController::constructor()
  */
 public function constructor()
 {
     // Link loader to controller
     // and the controller instance to itself
     $this->load = Loader::$instance;
     self::$instance =& $this;
     // Method and argument back references.
     if (isset($_GET["m"])) {
         $m = filter_var($_GET["m"], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     }
     if (isset($_GET["a"])) {
         $a = filter_var($_GET["a"], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     }
     if (isset($m)) {
         $this->method = $m;
     }
     if (isset($a)) {
         $this->arg = $a;
     }
     AutoLoader::getInstance();
     /*
      * Changing the working directory to "application"
      * since we don't really need anything from the system folder.
      */
     chdir("application");
 }
Esempio n. 9
0
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new AutoLoader();
     }
     return self::$instance;
 }
Esempio n. 10
0
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Esempio n. 11
0
 public static function Factory($default_page = null, $requireLogin = true)
 {
     $prefs = UserPreferences::Instance(EGS_USERNAME);
     $default_page = $prefs->getPreferenceValue('default_page', 'shared');
     if ($default_page == null) {
         $ao = AccessObject::Instance();
         $default_page = 'module,' . $ao->getDefaultModule();
     }
     if (get_config('SETUP')) {
         if (defined('MODULE')) {
             $default_page = MODULE;
         }
     }
     $router = RouteParser::Instance();
     $modules = array();
     if (!$requireLogin || isLoggedIn()) {
         foreach ($router->getDispatch() as $key => $dispatch) {
             if (($key == 'group' || $key == 'module' || strstr($key, 'submodule')) && !empty($dispatch)) {
                 $modules[$key] = $dispatch;
             }
         }
         if (empty($modules)) {
             // Default page contains permission type and permission name
             // i.e. type is group or module
             $array = explode(',', $default_page);
             $modules[$array[0]] = $array[1];
         }
     } else {
         $modules['module'] = 'login';
     }
     $al =& AutoLoader::Instance();
     return $modules;
 }
Esempio n. 12
0
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Esempio n. 13
0
 protected function setUp()
 {
     parent::setUp();
     // Fancy dance to trigger a rebuild of AutoLoader::$autoloadLocalClassesLower
     $this->mergeMwGlobalArrayValue('wgAutoloadLocalClasses', ['TestAutoloadedLocalClass' => __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php', 'TestAutoloadedCamlClass' => __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php', 'TestAutoloadedSerializedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php']);
     AutoLoader::resetAutoloadLocalClassesLower();
     $this->mergeMwGlobalArrayValue('wgAutoloadClasses', ['TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php']);
 }
Esempio n. 14
0
 /**
  * 获得实例的方法
  * @return AutoLoader AutoLoader的实例
  * @author winsen
  */
 public static function getInstance()
 {
     if (is_null(self::$obj)) {
         $class = __CLASS__;
         self::$obj = new $class();
     }
     return self::$obj;
 }
 /**
  * @return AutoLoader
  */
 public static function &getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
         self::$_instance->initialize();
         return self::$_instance;
     } else {
         return self::$_instance;
     }
 }
Esempio n. 16
0
 /**
  * Loads classes from cache.
  *
  * @return boolean True on success, otherwise false
  */
 public static function loadFromCache()
 {
     if (file_exists(self::$_cacheFile)) {
         self::$_classNames = unserialize(file_get_contents(self::$_cacheFile));
         $result = true;
     } else {
         $result = false;
     }
     return $result;
 }
 protected function setUp()
 {
     global $wgAutoloadLocalClasses, $wgAutoloadClasses;
     parent::setUp();
     // Fancy dance to trigger a rebuild of AutoLoader::$autoloadLocalClassesLower
     $this->testLocalClasses = array('TestAutoloadedLocalClass' => __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php', 'TestAutoloadedCamlClass' => __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php', 'TestAutoloadedSerializedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php');
     $this->setMwGlobals('wgAutoloadLocalClasses', $this->testLocalClasses + $wgAutoloadLocalClasses);
     AutoLoader::resetAutoloadLocalClassesLower();
     $this->testExtensionClasses = array('TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php');
     $this->setMwGlobals('wgAutoloadClasses', $this->testExtensionClasses + $wgAutoloadClasses);
 }
Esempio n. 18
0
 /**
  *  make sure autoload registers and unregisters correctly
  */
 public function testRegisterUnregister()
 {
     $al_orig_count = count(spl_autoload_functions());
     $al = new AutoLoader();
     $al->register();
     $al_count = count(spl_autoload_functions());
     $this->assertSame($al_orig_count + 1, $al_count);
     $al->unregister();
     $al_count = count(spl_autoload_functions());
     $this->assertSame($al_orig_count, $al_count);
     $al->register();
     $al_count = count(spl_autoload_functions());
     $this->assertSame($al_orig_count + 1, $al_count);
     $al_map = array();
     $al_map[0] = $al;
     $al_map[0]->unregister();
     $al_count = count(spl_autoload_functions());
     $this->assertSame($al_orig_count, $al_count);
     ///\out::e(spl_autoload_functions());
 }
Esempio n. 19
0
/**
 * Gets called, when an undefined class is being instanciated
 *d
 * @param_string $load_class_name
 */
function feng__autoload($load_class_name)
{
    static $loader = null;
    $class_name = strtoupper($load_class_name);
    // Try to get this data from index...
    if (isset($GLOBALS[AutoLoader::GLOBAL_VAR])) {
        if (isset($GLOBALS[AutoLoader::GLOBAL_VAR][$class_name])) {
            return include $GLOBALS[AutoLoader::GLOBAL_VAR][$class_name];
        }
        // if
    }
    // if
    if (!$loader) {
        $loader = new AutoLoader();
        $loader->addDir(ROOT . '/application');
        $loader->addDir(ROOT . '/environment');
        $loader->addDir(ROOT . '/library');
        $loader->setIndexFilename(ROOT . '/cache/autoloader.php');
    }
    // if
    try {
        $loader->loadClass($class_name);
    } catch (Exception $e) {
        try {
            if (function_exists("__autoload")) {
                __autoload($class_name);
            }
        } catch (Exception $ex) {
            die('Caught Exception in AutoLoader: ' . $ex->__toString());
        }
    }
    // try
}
Esempio n. 20
0
 public static function registerDirectory($dirName)
 {
     $di = new DirectoryIterator($dirName);
     foreach ($di as $file) {
         if ($file->isDir() && !$file->isLink() && !$file->isDot()) {
             // recurse into directories other than a few special ones
             self::registerDirectory($file->getPathname());
         } elseif (substr($file->getFilename(), -4) === '.php') {
             $className = self::getFullNamespacedName($file->getPathName());
             AutoLoader::registerClass($className, $file->getPathname());
         }
     }
 }
Esempio n. 21
0
 public static function init()
 {
     $directoryIterator = new RecursiveDirectoryIterator(__DIR__);
     $iterator = new RecursiveIteratorIterator($directoryIterator);
     $dirs = [];
     foreach ($iterator as $file) {
         if ($file->isDir()) {
             $dirs[] = $file->getRealPath();
         }
     }
     $dirs = array_unique($dirs);
     self::$dirs = $dirs;
 }
Esempio n. 22
0
 /**
  * Store the filename (sans extension) & full path of all ".php" files found
  */
 public static function registerDirectory($dirName)
 {
     $di = new DirectoryIterator($dirName);
     foreach ($di as $file) {
         if ($file->isDir() && !$file->isLink() && !$file->isDot()) {
             // recurse into directories other than a few special ones
             self::registerDirectory($file->getPathname());
         } elseif (substr($file->getFilename(), -4) === '.php') {
             // save the class name / path of a .php file found
             $className = toCamelCase(substr($file->getFilename(), 0, -4));
             AutoLoader::registerClass($className, $file->getPathname());
         }
     }
 }
Esempio n. 23
0
 /**
  * Register autoloader.
  * @return void
  */
 public function register()
 {
     $cache = $this->getCache();
     $data = $cache['data'];
     if ($data['opt'] === array($this->scanDirs, $this->ignoreDirs, $this->acceptFiles)) {
         $this->list = $data['list'];
     } else {
         $this->rebuild();
     }
     if (isset($this->list[strtolower(__CLASS__)]) && class_exists('NetteLoader', FALSE)) {
         NetteLoader::getInstance()->unregister();
     }
     parent::register();
 }
Esempio n. 24
0
 public function method_missing()
 {
     $as = AutoLoader::get_asset_server();
     if (!$this->filename) {
         $this->filename = array_pop($this->route_array);
     }
     $this->filename = substr($this->filename, 0, strrpos($this->filename, "."));
     if (!$this->type) {
         $this->type = $this->route_array[2];
     }
     $this->response->add_header("Content-Type", $as->mime($this->type));
     $this->hash = $this->route_array[1];
     $this->response->write($as->built_bundle($this->filename, $this->type, $this->hash));
 }
Esempio n. 25
0
 /**
  * Register autoloader.
  * @return void
  */
 public function register()
 {
     $cache = $this->getCache();
     $key = $this->getKey();
     if (isset($cache[$key])) {
         $this->list = $cache[$key];
     } else {
         $this->rebuild();
     }
     if (isset($this->list[strtolower(__CLASS__)]) && class_exists('NetteLoader', FALSE)) {
         NetteLoader::getInstance()->unregister();
     }
     parent::register();
 }
Esempio n. 26
0
 public function testAll()
 {
     $defaults = array('AutoCoupon', 'TotalAction');
     $all = AutoLoader::ListModules('TotalAction', true);
     foreach ($defaults as $d) {
         $this->assertContains($d, $all);
     }
     foreach ($all as $class) {
         $obj = new $class();
         $this->assertInstanceOf('TotalAction', $obj, $class . ' is not a TotalAction');
         $result = $obj->apply();
         $this->assertInternalType('boolean', $result, $class . ' apply() does not return boolean');
     }
 }
 public function testExpireCache()
 {
     $cache = file_get_contents(AutoLoader::instance()->getCacheLocation());
     $this->assertGreaterThan(0, strlen($cache));
     AutoLoader::instance()->expireCache();
     try {
         if (!($cache = file_get_contents(AutoLoader::instance()->getCacheLocation()))) {
             $this->assertTrue(true);
         } else {
             $this->assertTrue(false);
         }
     } catch (Exception $ex) {
         $this->assertTrue(true);
     }
 }
Esempio n. 28
0
 /**
  * Store the filename (sans extension) & full path of all ".php" files found
  */
 public static function registerDirectory($dirName, $namespace = '')
 {
     $di = new DirectoryIterator($dirName);
     foreach ($di as $file) {
         /** @var DirectoryIterator $file */
         if ($file->isDir() && !$file->isLink() && !$file->isDot()) {
             // recurse into directories other than a few special ones
             self::registerDirectory($file->getPathname(), (empty($namespace) ? '' : $namespace . '\\') . $file->getBasename());
         } elseif (substr($file->getFilename(), -4) === '.php') {
             // save the class name / path of a .php file found
             $className = substr($file->getFilename(), 0, -4);
             AutoLoader::registerClass($className, $file->getPathname(), $namespace);
         }
     }
 }
Esempio n. 29
0
 public static function registerDirectory($dirName, $mainDir = '')
 {
     $di = new \DirectoryIterator($dirName);
     if (empty($mainDir)) {
         $mainDir = $dirName;
     }
     foreach ($di as $file) {
         if ($file->isDir() && !$file->isLink() && !$file->isDot()) {
             self::registerDirectory($file->getPathname(), $mainDir);
         } elseif (substr($file->getFilename(), -4) === '.php') {
             $namespace = 'Mautic' . str_replace('/', '\\', substr(str_replace($mainDir, '', $file->getPathname()), 0, -4));
             AutoLoader::registerClass($namespace, $file->getPathname());
         }
     }
 }
Esempio n. 30
0
 /**
  * Called when a class needs to be loaded
  * @param $class - the name of the class
  */
 public function loadClass($class)
 {
     // Find out where the class is stored, from the cache
     $filePath = apc_fetch($this->cacheKey . $class);
     // Did we find it?
     if ($filePath === false) {
         // Not in the cache, so find out where the class is kept
         $filePath = parent::getFilePath($class);
         // store it in the cache
         if ($filePath !== false) {
             apc_store($this->cacheKey . $class, $filePath);
         }
     }
     // include it if we got a hit
     if ($filePath !== false) {
         require $filePath;
     }
 }