/** * Singleton - bekomme die laufen instanz vom objekt */ public static function getInstance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
public static function createInstance() { if (self::$instance == NULL) { self::$instance = new AutoLoader(); } return self::$instance; }
public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new AutoLoader(); } return self::$instance; }
/** * 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; }
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); } }
<?php /** * Rebuilds the class mapping cache file for the auto_loader * This can be done at run time but is real slow for big projects * and definately doesn't want to be run in production so this * should be run as part of deployment * @example php ./rebuild_class_map.php * @author Jason Paige */ if (php_sapi_name() != 'cli') { die("This script can only be run on the command line."); } define("ROOT_PATH", __DIR__ . DIRECTORY_SEPARATOR . ".."); require_once ROOT_PATH . "/AutoLoader.php"; $autoLoader = AutoLoader::instance(ROOT_PATH, true); $autoLoader->expireCache(); $autoLoader->ignore(ROOT_PATH . "ignore_folder")->ignore(ROOT_PATH . "ignore_folder2"); $autoLoader->init(); // correct the generated file paths $classMap = file_get_contents($autoLoader->getCacheLocation()); if (!file_put_contents($autoLoader->getCacheLocation(), $classMap)) { echo "Unable to write class map cache!"; exit(1); } else { echo "New class map cache generated at " . $autoLoader->getCacheLocation() . "\n"; exit; }