예제 #1
0
 public function register()
 {
     // Params
     set_time_limit(0);
     clearstatcache();
     // Error log
     $this->initErrorHandling();
     // External classes
     require_once $this->getCorePath() . '/classes/class.util.php';
     Util::logSeparator();
     // Autoloader
     require_once $this->getCorePath() . '/classes/class.autoloader.php';
     $neardAutoloader = new Autoloader();
     $neardAutoloader->register();
     // Load
     self::loadCore();
     self::loadConfig();
     self::loadLang();
     self::loadBins();
     self::loadTools();
     self::loadApps();
     self::loadWinbinder();
     self::loadRegistry();
     self::loadHomepage();
     // Init
     if ($this->isBootstrap) {
         $this->procs = Win32Ps::getListProcs();
     }
 }
예제 #2
0
 /**
  * Asserts that the tokenizer is used as default
  *
  * @return void
  */
 public function testAutoloaderUsesTokenizer()
 {
     $this->assertTrue(AutoloaderFileParser_Tokenizer::isSupported());
     $autoloader = new Autoloader();
     $autoloader->register();
     $autoloader->remove();
     $this->assertTrue($autoloader->getParser() instanceof AutoloaderFileParser_Tokenizer);
 }
예제 #3
0
 /**
  * @return void
  * @covers \pdepend\reflection\Autoloader
  * @group reflection
  * @group unittest
  */
 public function testAutoloaderIncludesMatchingSourceFile()
 {
     $classFixture = '\\pdepend\\reflection\\autoloader\\Test';
     if (class_exists($classFixture, false)) {
         $this->fail('Class ' . $classFixture . ' should not exist');
     }
     $autoloader = new Autoloader(__DIR__ . '/_source/');
     $autoloader->autoload($classFixture);
     $this->assertTrue(class_exists($classFixture, false), 'Class should exist ' . $classFixture);
 }
예제 #4
0
 /**
  * __construct
  *
  * Constructs the object.
  *
  * @access public
  * @param  \Pimple $pimple
  * @return void
  */
 public function __construct(\Pimple $pimple)
 {
     $this->pimple = $pimple;
     $this->config = $pimple['config'];
     $this->setReporting();
     $appDir = $this->config['general.appDir'] . 'src';
     $appLoader = new Autoloader($this->config['general.namespace'], $appDir);
     $appLoader->register();
     $this->router = new Router($this->pimple);
     $this->session = $this->pimple['session'];
     $this->session->start();
     $this->session->set('language', $this->session->get('language', $this->config['general.default_language']));
 }
예제 #5
0
 /**
  * This method will load and register a new autoloader for the system
  * multiple autoloader instances may be used.
  */
 public static function registerAutoloaders()
 {
     require_once 'Autoloader.php';
     $autoloader = new Autoloader(__NAMESPACE__, BASE);
     $autoloader->register();
     /**
      * Override Basic error handling with Whoops
      */
     $whoopsload = new Autoloader('Whoops', BASE . 'vendor' . DS . 'filp' . DS . 'whoops' . DS . 'src' . DS . '');
     $whoopsload->register();
     $wh = new \Whoops\Run();
     $wh->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $wh->register();
 }
 public static function LoadComponents()
 {
     $Components = array('Classes');
     foreach ($Components as $Component) {
         Autoloader::LoadOrder($Component);
     }
 }
예제 #7
0
 public static function getPath()
 {
     if (!self::$path) {
         self::$path = realpath(dirname(__FILE__));
     }
     return self::$path;
 }
예제 #8
0
 public static function GetInstance()
 {
     if (!self::$_Instance) {
         self::$_Instance = new self();
     }
     return self::$_Instance;
 }
예제 #9
0
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
예제 #10
0
 /**
  * Add a path to the class directories
  *
  * @param string        $sDir                The path to the directory
  * @param string|null    $sNamespace            The associated namespace
  * @param array         $aExcluded            The functions that are not to be exported
  *
  * @return boolean
  */
 public function addClassDir($sDir, $sNamespace = null, array $aExcluded = array())
 {
     if (!is_dir($sDir = trim($sDir))) {
         return false;
     }
     if (!($sNamespace = trim($sNamespace))) {
         $sNamespace = null;
     }
     if ($sNamespace) {
         $sNamespace = trim($sNamespace, '\\');
         // If there is an autoloader, register the dir with PSR4 autoloading
         if ($this->xAutoloader) {
             $this->xAutoloader->setPsr4($sNamespace . '\\', $sDir);
         }
     } else {
         if ($this->xAutoloader) {
             // If there is an autoloader, register the dir with classmap autoloading
             $itDir = new RecursiveDirectoryIterator($sDir);
             $itFile = new RecursiveIteratorIterator($itDir);
             // Iterate on dir content
             foreach ($itFile as $xFile) {
                 // skip everything except PHP files
                 if (!$xFile->isFile() || $xFile->getExtension() != 'php') {
                     continue;
                 }
                 $this->xAutoloader->addClassMap(array($xFile->getBasename('.php') => $xFile->getPathname()));
             }
         }
     }
     $this->aClassDirs[] = array('path' => $sDir, 'namespace' => $sNamespace, 'excluded' => $aExcluded);
     return true;
 }
예제 #11
0
 /**
  * Discover application classes
  */
 private static function discover()
 {
     if (!is_null(self::$application_mappers)) {
         return;
     }
     self::$application_mappers = array();
     foreach (array('auth', 'constants', 'endpoints', 'model', 'utils') as $type) {
         $path = APPLICATION_BASE . '/classes/' . $type . '/';
         foreach (scandir($path) as $i) {
             if (!is_file($path . $i)) {
                 continue;
             }
             if (substr($i, -10) != '.class.php') {
                 continue;
             }
             self::$application_mappers[substr($i, 0, -10)] = $type . '/' . $i;
         }
     }
     // Exceptions
     $path = APPLICATION_BASE . '/classes/exceptions/';
     foreach (scandir($path) as $i) {
         if (!is_file($path . $i)) {
             continue;
         }
         if (preg_match('/^(.+)Exception\\.class\\.php$/', $i, $m)) {
             self::$application_mappers[$m[1] . 'Exception'] = 'exceptions/' . $i;
             continue;
         }
         if (preg_match('/^(.+)Exceptions\\.class\\.php$/', $i, $m)) {
             self::$application_mappers[$m[1] . '*Exception'] = 'exceptions/' . $i;
             continue;
         }
     }
 }
예제 #12
0
파일: php.php 프로젝트: takawasitobi/pembit
 /**
  * Formats the output and saved it to disc.
  *
  * @param   string     $identifier  filename
  * @param   $contents  $contents    language array to save
  * @return  bool       \File::update result
  */
 public function save($identifier, $contents)
 {
     // store the current filename
     $file = $this->file;
     // save it
     $return = parent::save($identifier, $contents);
     // existing file? saved? and do we need to flush the opcode cache?
     if ($file == $this->file and $return and static::$flush_needed) {
         if ($this->file[0] !== '/' and (!isset($this->file[1]) or $this->file[1] !== ':')) {
             // locate the file
             if ($pos = strripos($identifier, '::')) {
                 // get the namespace path
                 if ($file = \Autoloader::namespace_path('\\' . ucfirst(substr($identifier, 0, $pos)))) {
                     // strip the namespace from the filename
                     $identifier = substr($identifier, $pos + 2);
                     // strip the classes directory as we need the module root
                     $file = substr($file, 0, -8) . 'lang' . DS . $identifier;
                 } else {
                     // invalid namespace requested
                     return false;
                 }
             } else {
                 $file = \Finder::search('lang', $identifier);
             }
         }
         // make sure we have a fallback
         $file or $file = APPPATH . 'lang' . DS . $identifier;
         // flush the opcode caches that are active
         static::$uses_opcache and opcache_invalidate($file, true);
         static::$uses_apc and apc_compile_file($file);
     }
     return $return;
 }
예제 #13
0
 public function testCacheFileCanBeManuallySaved()
 {
     Autoloader::saveCachedPaths();
     $this->assertTrue(file_exists($this->cacheFile), 'Cache file should exist');
     $this->assertTrue(filesize($this->cacheFile) > 0, 'Cache file should be non-empty');
     $this->removeCacheFile();
 }
 public function attach()
 {
     if (!isset($this->name)) {
         $this->name = Autoloader::uniqueName();
     }
     Autoloader::attach($this);
 }
예제 #15
0
 public static function initialize()
 {
     if (defined('TESTS_ENV') || self::is_dev()) {
         ini_set('display_errors', 'on');
         error_reporting(E_ALL);
     } else {
         ini_set('display_errors', 'off');
         error_reporting(0);
     }
     require_once ROOT_PATH . DS . 'common' . DS . 'classes' . DS . 'autoloader.php';
     Autoloader::init_autoload();
     FileSystemHelper::init_dirs();
     LIVR::defaultAutoTrim(true);
     /**
      * @var $system \System
      */
     $system = static::get_class(\System::class);
     $system->initialize();
     /**
      * @var $configuration Configuration
      */
     $configuration = Application::get_class(Configuration::class);
     $current_lang = $configuration->language;
     defined('CURRENT_LANG') or define('CURRENT_LANG', $current_lang);
 }
예제 #16
0
 public static function init()
 {
     if (self::$loader == NULL) {
         self::$loader = new self();
     }
     return self::$loader;
 }
 public static function setExtension($extension)
 {
     if (!preg_match('/^\\./', $extension)) {
         $extension = '.' . $extension;
     }
     self::$extension = $extension;
 }
예제 #18
0
 /**
  * Test unregister method unregisters autoloader class and method properly.
  */
 public function testUnregisterRegistersAutoloaderProperly()
 {
     $this->setUpAutoloaderWithStrategy();
     $this->registerAutoloaderStrategyMock();
     $this->autoloader->unregister();
     $this->assertAutoloaderUnregistered();
 }
예제 #19
0
 public function testAutoloadValidGeodeticClass()
 {
     $className = 'Geodetic\\Angle';
     $result = Autoloader::Load($className);
     //    Check that class has been loaded
     $this->assertTrue(class_exists($className));
 }
예제 #20
0
 /**
  * 获取实例
  * 
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public static function init()
 {
     if (!self::$_loader instanceof self) {
         self::$_loader = new self();
     }
     return self::$_loader;
 }
예제 #22
0
 static function loadAutoloader($class)
 {
     spl_autoload_unregister(array(__CLASS__, __FUNCTION__));
     require PATCHWORK_PROJECT_PATH . '.patchwork.autoloader.php';
     spl_autoload_register(array('Patchwork\\Autoloader', 'loadClass'));
     Autoloader::loadClass($class);
 }
예제 #23
0
 /**
  * Well, if you want, you can use it as a singleton....
  * @return Autoloader $singleton instance
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new Autoloader();
     }
     return self::$instance;
 }
예제 #24
0
 public static function autoload($sClassName)
 {
     if (isset(self::$CLASS_MAPPING[$sClassName])) {
         if (self::$CLASS_MAPPING[$sClassName] === null) {
             return;
         }
         require_once self::$CLASS_MAPPING[$sClassName];
         return;
     }
     foreach (self::getClassFinders() as $sClassFinder) {
         $sIncludeFilePath = self::$sClassFinder($sClassName);
         if ($sIncludeFilePath) {
             $sIncludeFilePath = stream_resolve_include_path($sIncludeFilePath);
             if ($sIncludeFilePath === false) {
                 $sIncludeFilePath = null;
                 continue;
             }
             break;
         }
     }
     self::$CLASS_MAPPING[$sClassName] = $sIncludeFilePath;
     self::$MAPPING_HAS_BEEN_MODIFIED = true;
     if ($sIncludeFilePath) {
         require_once $sIncludeFilePath;
     }
 }
예제 #25
0
 public function testLoad()
 {
     $autoloader = new Autoloader();
     $autoloader->addPath('Foo', 'src/Models');
     $autoloader->addPath('Foo', 'src/Helpers');
     $autoloader->addPath('Foo\\Selection', 'src/Models/Selection');
     $this->assertFalse($autoloader->load('Bar'));
     $this->assertFalse($autoloader->load('Foo\\Bar'));
     $this->assertTrue($autoloader->load('Foo\\Helper'));
     $this->assertTrue($autoloader->load('Foo\\Model'));
     $this->assertTrue($autoloader->load('Foo\\Selection\\SelectionBuilder'));
     // TODO: mock loadFrom and test paths etc.
 }
예제 #26
0
 public function run()
 {
     $loader = Autoloader::instance();
     pc($loader, 'loader');
     $ViewClass = $loader->view();
     $view = new $ViewClass();
     $view->render();
 }
예제 #27
0
 /**
  * Подключить карту расположения классов
  * @property string $path
  * @return array
  */
 public static function loadMap($path)
 {
     if (!file_exists($path)) {
         self::$_classMap = array();
         return;
     }
     self::$_classMap = (include $path);
 }
예제 #28
0
 public static function load_class($class_name)
 {
     $filename = Autoloader::load_class_path($class_name);
     if (file_exists($filename)) {
         require $filename;
         return true;
     }
 }
예제 #29
0
파일: Autoloader.php 프로젝트: kafruhs/fws
 /**
  * create an autoloader instance
  *
  * @return Autoloader
  */
 public static function singleton()
 {
     if (self::$_instance instanceof self === true) {
         return self::$_instance;
     }
     self::$_instance = new self();
     return self::$_instance;
 }
예제 #30
0
 /**
  * Asserts that the class $class is loadable after
  * registration of its class definition $path
  *
  * @param String $class The class which is autoloaded
  * @param String $path  The class defintion
  * 
  * @dataProvider provideTestAutoload
  * @return void
  * @see InternalAutoloader::registerClass()
  */
 public function testAutoload($class, $path)
 {
     $autoloaderTestHelper = new AutoloaderTestHelper($this);
     Autoloader::removeAll();
     $autoloaderTestHelper->assertNotLoadable($class);
     InternalAutoloader::getInstance()->registerClass($class, $path);
     $autoloaderTestHelper->assertLoadable($class);
 }