/**
     * Replaces all regular UniversalClassLoader instances by a DebugUniversalClassLoader ones.
     */
    static public function enable()
    {
        if (!is_array($functions = spl_autoload_functions())) {
            return;
        }

        foreach ($functions as $function) {
            spl_autoload_unregister($function);
        }

        foreach ($functions as $function) {
            if (is_array($function) && $function[0] instanceof UniversalClassLoader) {
                $loader = new static();
                $loader->registerNamespaceFallbacks($function[0]->getNamespaceFallbacks());
                $loader->registerPrefixFallbacks($function[0]->getPrefixFallbacks());
                $loader->registerNamespaces($function[0]->getNamespaces());
                $loader->registerPrefixes($function[0]->getPrefixes());
                $loader->useIncludePath($function[0]->getUseIncludePath());

                $function[0] = $loader;
            }

            spl_autoload_register($function);
        }
    }
Exemple #2
0
 public static function reautoload($paths = array(), $ext = '.class.php')
 {
     if (is_string($paths)) {
         $paths = array($paths);
     }
     foreach ($paths as $path) {
         self::add_autoload_path($path, $ext);
     }
     // unregister old
     //spl_autoload_unregister(array('Think', 'autoload'));
     /*
      Array ( [0] => Array ( 
      [0] => Think [1] => autoload ) 
      [1] => Array ( [0] => (object) [1] => autoload )  
      [2] => import ) 
     */
     // check loaded?
     if ($aLoadedFuncs = spl_autoload_functions()) {
         foreach ($aLoadedFuncs as $f) {
             if ($f && is_array($f) && is_string($f[0]) && $f[0] == __CLASS__ && $f[1] == 'autoload') {
                 return;
             }
         }
     }
     // register Runder::autoload
     spl_autoload_register(array(__CLASS__, 'autoload'));
 }
 public function setUp()
 {
     $autoloaders = spl_autoload_functions();
     $this->app = new Application($autoloaders[0][0]);
     $this->app->registerStandardCommands();
     $this->sourceDir = __DIR__ . '/../../src/Core/Tests/fixtures/project';
 }
Exemple #4
0
 public function testCreateDefinitionsDoesNotReadCompiledDefinitionsIfUseCompiledIsFalse()
 {
     $this->filesystemDriverMock->expects($this->never())->method('isReadable');
     $this->assertInstanceOf('\\Magento\\Framework\\ObjectManager\\Definition\\Runtime', $this->model->createClassDefinition(null, false));
     $autoloadFunctions = spl_autoload_functions();
     spl_autoload_unregister(array_pop($autoloadFunctions));
 }
 /**
  * {@inheritDoc}
  */
 public function getLoader()
 {
     $this->validate();
     $previous = spl_autoload_functions();
     foreach ($this->information as $path) {
         if ($path = realpath($this->prependPathWithBaseDir($path))) {
             require $path;
         }
     }
     $found = array();
     $after = spl_autoload_functions();
     foreach ($after as $loader) {
         if (!in_array($loader, $previous)) {
             spl_autoload_unregister($loader);
             $found[] = $loader;
         }
     }
     return function ($class) use($found) {
         foreach ($found as $loader) {
             if (call_user_func($loader, $class)) {
                 return true;
             }
         }
         return null;
     };
 }
Exemple #6
0
 /**
  * testAutoloader
  *
  * @since 2.1.0
  */
 public function testAutoloader()
 {
     /* result */
     $result = spl_autoload_functions();
     /* compare */
     $this->assertInternalType('array', $result);
 }
 /**
  * testAutoloader
  *
  * @since 2.1.0
  */
 public function testAutoloader()
 {
     /* actual */
     $actual = spl_autoload_functions();
     /* compare */
     $this->assertInternalType('array', $actual);
 }
Exemple #8
0
 public static function register($prepend = false)
 {
     $error = false;
     if (self::$autoloader_set) {
         trigger_error("Auto loader already set", E_USER_NOTICE);
     } else {
         self::add_path(__DIR__ . DIRECTORY_SEPARATOR . "..");
         $class_extensions = spl_autoload_extensions();
         if (strpos($class_extensions, ".php") === false) {
             spl_autoload_extensions($class_extensions . ",.php");
         }
         if (is_array(spl_autoload_functions()) && in_array("spl_autoload", spl_autoload_functions())) {
             trigger_error("Auto loader already set", E_USER_NOTICE);
         } else {
             if (PHP_VERSION_ID < 50300) {
                 if (!spl_autoload_register("spl_autoload")) {
                     $error = true;
                 }
             } else {
                 if (!spl_autoload_register("spl_autoload", true, $prepend)) {
                     $error = true;
                 }
             }
         }
         if ($error) {
             trigger_error("Could not add autoloader to the queue", E_USER_NOTICE);
         } else {
             self::$autoloader_set = true;
         }
     }
 }
 public static function register2($stopProcessing = false)
 {
     if (!$stopProcessing && !self::$_registered) {
         $rewriter = new Aitoc_Aitsys_Model_Rewriter();
         $rewriter->preRegisterAutoloader();
         // unregistering all autoloaders to make our performing first
         $autoloaders = spl_autoload_functions();
         $firstAutoloader = $autoloaders[0];
         // EXTENDWARE CHANGE
         if ($autoloaders && is_array($autoloaders) && !empty($autoloaders)) {
             foreach ($autoloaders as $autoloader) {
                 spl_autoload_unregister($autoloader);
             }
         }
         // EXTENDWARE CHANGE
         if (is_callable($firstAutoloader)) {
             spl_autoload_register($firstAutoloader, false);
         }
         // register our autoloader
         spl_autoload_register(array(self::instance(), 'autoload'), false);
         // register 1.3.1 and older autoloader
         if (version_compare(Mage::getVersion(), '1.3.1', 'le')) {
             spl_autoload_register(array(self::instance(), 'performStandardAutoload'), true);
         }
         // register back all unregistered autoloaders
         if ($autoloaders && is_array($autoloaders) && !empty($autoloaders)) {
             foreach ($autoloaders as $autoloader) {
                 spl_autoload_register($autoloader, is_array($autoloader) && $autoloader[0] instanceof Varien_Autoload);
             }
         }
         self::$_registered = true;
     }
 }
Exemple #10
0
 public function __construct()
 {
     //Make sure autoloader is loaded
     if (version_compare(PHP_VERSION, '5.1.2', '>=') and !spl_autoload_functions() || !in_array('DocxMergeAutoload', spl_autoload_functions())) {
         require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'DocxMerge' . DIRECTORY_SEPARATOR . 'DocxMergeAutoload.php';
     }
 }
Exemple #11
0
 /**
  * @return IBridgeInterface
  */
 public function registerLoader()
 {
     /**
      * Prevent multiple Loader-Instance
      */
     $Loader = spl_autoload_functions();
     if (is_array($Loader)) {
         array_walk($Loader, function (&$Loader) {
             if (is_array($Loader)) {
                 $Stack = $Loader[0];
             } else {
                 $Stack = $Loader;
             }
             if ($Stack instanceof Bridge) {
                 if ($Stack->getLoaderHash() == $this->getLoaderHash()) {
                     $Loader = false;
                 }
             }
         }, $this);
         $Loader = in_array(false, $Loader);
     } else {
         // @codeCoverageIgnoreStart
         $Loader = false;
         // @codeCoverageIgnoreEnd
     }
     /**
      * Register Loader-Instance
      */
     if (!$Loader) {
         spl_autoload_register(array($this, 'loadSourceFile'), true, false);
     }
     return $this;
 }
Exemple #12
0
 /**
  * set the faker autoloader
  */
 public function setAutoload()
 {
     require_once Mage::getBaseDir('lib') . DS . 'Zend' . DS . 'Loader.php';
     $autoLoader = Zend_Loader_Autoloader::getInstance();
     // get all Varien autoloaders an unregister them
     $autoloader_callbacks = spl_autoload_functions();
     $original_autoload = null;
     foreach ($autoloader_callbacks as $callback) {
         if (is_array($callback) && $callback[0] instanceof Varien_Autoload) {
             $original_autoload = $callback;
         }
     }
     spl_autoload_unregister($original_autoload);
     // the faker autoloader
     function fakerLoader($className)
     {
         $className = ltrim($className, '\\');
         $fileName = '';
         if ($lastNsPos = strripos($className, '\\')) {
             $namespace = substr($className, 0, $lastNsPos);
             $className = substr($className, $lastNsPos + 1);
             $fileName = lcfirst(str_replace('\\', DS, $namespace) . DS);
         }
         $fileName = Mage::getBaseDir('lib') . DS . 'fzaninotto' . DS . $fileName . DS . $className . '.php';
         if (file_exists($fileName)) {
             require_once $fileName;
             return true;
         }
         return false;
     }
     $autoLoader->pushAutoloader('fakerLoader', 'Faker\\');
     // re-add the original autoloader
     $autoLoader->pushAutoloader($original_autoload);
 }
 public static function register($stopProcessing = false)
 {
     if (Mage::getConfig()->getNode('default/aitsys/rewriter_status') != 1) {
         self::$_registered = true;
         return;
     }
     if (!$stopProcessing && !self::$_registered) {
         $rewriter = new Aitoc_Aitsys_Model_Rewriter();
         $rewriter->preRegisterAutoloader();
         // unregistering all autoloaders to make our performing first
         $autoloaders = spl_autoload_functions();
         if ($autoloaders && is_array($autoloaders) && !empty($autoloaders)) {
             foreach ($autoloaders as $autoloader) {
                 spl_autoload_unregister($autoloader);
             }
         }
         // register our autoloader
         spl_autoload_register(array(self::instance(), 'autoload'), false);
         // register 1.3.1 and older autoloader
         if (version_compare(Mage::getVersion(), '1.3.1', 'le')) {
             spl_autoload_register(array(self::instance(), 'performStandardAutoload'), true);
         }
         // register back all unregistered autoloaders
         if ($autoloaders && is_array($autoloaders) && !empty($autoloaders)) {
             foreach ($autoloaders as $autoloader) {
                 spl_autoload_register($autoloader, is_array($autoloader) && $autoloader[0] instanceof Varien_Autoload);
             }
         }
         self::$_registered = true;
     }
 }
 /**
  * Installs this class loader on the SPL autoload stack as the only class loader.
  * 
  * @throws DoctrineException If the SPL autoload stack already contains other autoloaders. 
  */
 public function register()
 {
     if (spl_autoload_functions() !== false) {
         throw new DoctrineException("Autoload stack is not empty. GlobalClassLoader does not work " . "in an autoload stack.");
     }
     spl_autoload_register(array($this, 'loadClass'));
 }
Exemple #15
0
 public function testUnregister()
 {
     Autoloader::register();
     $numOfAutoloaders = count(spl_autoload_functions());
     Autoloader::unregister();
     $this->assertCount($numOfAutoloaders - 1, spl_autoload_functions());
 }
Exemple #16
0
 /**
  * Turns autoloading off.
  */
 protected function disableAutoload()
 {
     $this->autoloadList = spl_autoload_functions();
     foreach ($this->autoloadList as $function) {
         spl_autoload_unregister($function);
     }
 }
Exemple #17
0
 protected function forceAutoloader()
 {
     $splAutoloadFunctions = spl_autoload_functions();
     if (!$splAutoloadFunctions || !in_array('ZendTest_Autoloader', $splAutoloadFunctions)) {
         include __DIR__ . '/../../_autoload.php';
     }
 }
Exemple #18
0
 public function scan($namespace)
 {
     $namespace = trim($namespace, "\\") . "\\";
     $paths = [];
     foreach (spl_autoload_functions() as $loader) {
         if (is_array($loader) && count($loader) === 2) {
             if ($loader[0] instanceof ComposerLoader) {
                 foreach ($loader[0]->getPrefixes() as $prefix => $loaderPaths) {
                     if (strpos($prefix . "\\", $namespace) === 0) {
                         $paths = array_merge($paths, $loaderPaths);
                     } else {
                         if (strpos($namespace, $prefix . "\\") === 0) {
                             $paths = array_merge($paths, array_map(function ($path) use($namespace, $prefix) {
                                 return $path . "/" . str_replace("\\", "/", $namespace);
                             }, $loaderPaths));
                         }
                     }
                 }
             }
         }
     }
     array_map([$this->phpLoader, "load"], $paths);
     return array_filter(array_merge(get_declared_classes(), get_declared_interfaces()), function ($name) use($namespace) {
         return stripos($name, $namespace) === 0;
     });
 }
Exemple #19
0
 static function loadEbayClasses()
 {
     // make sure this only runs once
     $autoload_functions = spl_autoload_functions();
     if (is_array($autoload_functions)) {
         foreach ($autoload_functions as $func) {
             // return if WPL_Autoloader already loaded
             if (is_array($func) && $func[1] == 'autoloadEbayClasses') {
                 return;
             }
         }
     }
     // we want to be patient when talking to ebay
     if (!ini_get('safe_mode')) {
         @set_time_limit(600);
     }
     ini_set('mysql.connect_timeout', 600);
     ini_set('default_socket_timeout', 600);
     // add EbatNs folder to include path - required for SDK
     $incPath = WPLISTER_PATH . '/includes/EbatNs';
     set_include_path(get_include_path() . ':' . $incPath);
     // TODO: check if set_include_path() was successfull!
     // use autoloader to load EbatNs classes
     spl_autoload_register('WPL_Autoloader::autoloadEbayClasses');
 }
Exemple #20
0
 public static function register($base = false)
 {
     /* deprecated since 2.19.0
             if (defined('COMPILER_INCLUDE_PATH'))
             {
                 $paths = array();
                 $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
                 $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
                 #$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
                 #$paths[] = BP . DS . 'lib';
     
                 $appPath = implode(PS, $paths);
                 set_include_path($appPath . PS . get_include_path());
             }
             */
     $rewriter = new Aitoc_Aitsys_Model_Rewriter();
     $rewriter->preRegisterAutoloader($base);
     // unregistering all, and varien autoloaders to make our performing first
     $autoloaders = spl_autoload_functions();
     if ($autoloaders and is_array($autoloaders) && !empty($autoloaders)) {
         foreach ($autoloaders as $autoloader) {
             spl_autoload_unregister($autoloader);
         }
     }
     if (version_compare(Mage::getVersion(), '1.3.1', '>')) {
         spl_autoload_unregister(array(Varien_Autoload::instance(), 'autoload'));
     }
     spl_autoload_register(array(self::instance(), 'autoload'), false);
     if (version_compare(Mage::getVersion(), '1.3.1', '>')) {
         Varien_Autoload::register();
     } else {
         spl_autoload_register(array(self::instance(), 'performStandardAutoload'));
         #self::_loadOverwrittenClasses();
     }
 }
 /**
  * Tries to guess the full namespace for a given class name.
  *
  * By default, it looks for PSR-0 classes registered via a Symfony or a Composer
  * autoloader (that should cover all common cases).
  *
  * @param string $class A class name (without its namespace)
  *
  * @return array An array of possible fully qualified class names
  */
 private function getClassCandidates($class)
 {
     if (!is_array($functions = spl_autoload_functions())) {
         return array();
     }
     // find Symfony and Composer autoloaders
     $classes = array();
     foreach ($functions as $function) {
         if (!is_array($function)) {
             continue;
         }
         // get class loaders wrapped by DebugClassLoader
         if ($function[0] instanceof DebugClassLoader) {
             $function = $function[0]->getClassLoader();
             // Since 2.5, returning an object from DebugClassLoader::getClassLoader() is @deprecated
             if (is_object($function)) {
                 $function = array($function);
             }
             if (!is_array($function)) {
                 continue;
             }
         }
         if ($function[0] instanceof ComposerClassLoader || $function[0] instanceof SymfonyClassLoader || $function[0] instanceof SymfonyUniversalClassLoader) {
             foreach ($function[0]->getPrefixes() as $prefix => $paths) {
                 foreach ($paths as $path) {
                     $classes = array_merge($classes, $this->findClassInPath($path, $class, $prefix));
                 }
             }
         }
     }
     return array_unique($classes);
 }
Exemple #22
0
 /**
  * Tests that when registering that NIMBLES_PATH is made the first include path
  * @return void
  */
 public function testRegister()
 {
     $includepaths = explode(PATH_SEPARATOR, get_include_path());
     foreach ($includepaths as $index => $path) {
         if (NIMBLES_PATH === $path) {
             unset($includepaths[$index]);
             break;
         }
     }
     set_include_path(implode(PATH_SEPARATOR, $includepaths));
     $functions = spl_autoload_functions();
     if (is_array($functions) && 'Nimbles\\Core\\Loader' === $functions[0][0]) {
         spl_autoload_unregister('Nimbles\\Core\\Loader::autoload');
     }
     if (false === ($functions = spl_autoload_functions())) {
         $functions = array();
     }
     array_unshift($includepaths, NIMBLES_PATH);
     \Nimbles\Core\Loader::register();
     $this->assertSame($includepaths, explode(PATH_SEPARATOR, get_include_path()));
     if (function_exists('spl_autoload_case_sensitive')) {
         $autoload = 'spl_autoload';
     } else {
         $autoload = array('Nimbles\\Core\\Loader', 'autoload');
     }
     $registered = spl_autoload_functions();
     $this->assertContains($autoload, $registered);
 }
Exemple #23
0
 public function testCallingRegisterRegistersSelfAsSplAutoloaderFunction()
 {
     $loader = new \Mockery\Loader();
     $loader->register();
     $expected = array($loader, 'loadClass');
     $this->assertTrue(in_array($expected, spl_autoload_functions()));
 }
 /**
  * Reloads the autoloader.
  * 
  * @param  string $class
  * 
  * @return boolean
  */
 public function autoload($class)
 {
     // only reload once
     if ($this->reloaded) {
         return false;
     }
     $autoloads = spl_autoload_functions();
     // as of PHP 5.2.11, spl_autoload_functions() returns the object as the first element of the array instead of the class name
     if (version_compare(PHP_VERSION, '5.2.11', '>=')) {
         foreach ($autoloads as $position => $autoload) {
             if ($this === $autoload[0]) {
                 break;
             }
         }
     } else {
         $position = array_search(array(__CLASS__, 'autoload'), $autoloads, true);
     }
     if (isset($autoloads[$position + 1])) {
         $this->unregister();
         $this->register();
         // since we're rearranged things, call the chain again
         spl_autoload_call($class);
         return class_exists($class, false) || interface_exists($class, false);
     }
     $autoload = sfAutoload::getInstance();
     $autoload->reloadClasses(true);
     $this->reloaded = true;
     return $autoload->autoload($class);
 }
 /**
  * Tries to guess the full namespace for a given class name.
  *
  * By default, it looks for PSR-0 classes registered via a Symfony or a Composer
  * autoloader (that should cover all common cases).
  *
  * @param string $class A class name (without its namespace)
  *
  * @return array An array of possible fully qualified class names
  */
 private function getClassCandidates($class)
 {
     if (!is_array($functions = spl_autoload_functions())) {
         return array();
     }
     // find Symfony and Composer autoloaders
     $classes = array();
     foreach ($functions as $function) {
         if (!is_array($function)) {
             continue;
         }
         // get class loaders wrapped by DebugClassLoader
         if ($function[0] instanceof DebugClassLoader && method_exists($function[0], 'getClassLoader')) {
             $function[0] = $function[0]->getClassLoader();
         }
         if ($function[0] instanceof ComposerClassLoader || $function[0] instanceof SymfonyClassLoader) {
             foreach ($function[0]->getPrefixes() as $paths) {
                 foreach ($paths as $path) {
                     $classes = array_merge($classes, $this->findClassInPath($path, $class));
                 }
             }
         }
     }
     return $classes;
 }
 /**
  * @param string[] $classes
  *
  * @return array
  */
 protected static function buildSnapshot($classes)
 {
     $observations = array();
     // Test that all classes are available immediately at boot time.
     foreach ($classes as $class) {
         $observations['class_exists'][$class] = class_exists($class);
     }
     // Check variable_get().
     // @FIXME
     // // @FIXME
     // // The correct configuration object could not be determined. You'll need to
     // // rewrite this call manually.
     // $observations[XAUTOLOAD_VARNAME_CACHE_TYPES] = variable_get(XAUTOLOAD_VARNAME_CACHE_TYPES);
     // @FIXME
     // // @FIXME
     // // The correct configuration object could not be determined. You'll need to
     // // rewrite this call manually.
     // $observations[XAUTOLOAD_VARNAME_CACHE_LAZY] = variable_get(XAUTOLOAD_VARNAME_CACHE_LAZY);
     $observations['db_connection_info'] = \Database::getConnectionInfo();
     $spl_autoload_stack = array();
     foreach (spl_autoload_functions() as $callback) {
         $spl_autoload_stack[] = Util::callbackToString($callback);
     }
     $observations['spl_autoload_functions'] = $spl_autoload_stack;
     return $observations;
 }
Exemple #27
0
 public function view()
 {
     $applicationPrefixes = array();
     $packagePrefixes = array();
     $loaders = spl_autoload_functions();
     foreach ($loaders as $loader) {
         if (is_array($loader) && $loader[0] instanceof \Concrete\Core\Foundation\ModifiedPsr4ClassLoader) {
             $reflection = new \ReflectionClass($loader[0]);
             $property = $reflection->getProperty('prefixes');
             $property->setAccessible(true);
             $prefixes = $property->getValue($loader[0]);
             $property->setAccessible(false);
             foreach ($prefixes as $prefix) {
                 if (substr($prefix[0], 0, 12) == 'Application\\') {
                     $applicationPrefixes[$prefix[0]] = $prefix[1];
                 } elseif (preg_match('/^(Concrete\\\\Package\\\\)([A-Za-z_-]+)(\\\\.*)/', $prefix[0], $matches)) {
                     $dir = Core::make('helper/text')->uncamelcase($matches[2]);
                     $path = str_replace($dir, '<em>' . t('package_handle') . '</em>', $prefix[1]);
                     $packagePrefixes[$matches[1] . '<em>' . t('package_handle') . '</em>' . $matches[3]] = $path;
                 }
             }
         }
     }
     $this->set('applicationPrefixes', $applicationPrefixes);
     $this->set('packagePrefixes', $packagePrefixes);
 }
Exemple #28
0
 public function testCallingRegisterRegistersSelfAsSplAutoloaderFunction()
 {
     require_once 'Mutateme/Loader.php';
     $loader = new \Mutateme\Loader();
     $loader->register();
     $expected = array($loader, 'loadClass');
     $this->assertTrue(in_array($expected, spl_autoload_functions()));
 }
Exemple #29
0
 /**
  * @covers Cougar\Autoload\Autoload:;register
  * @depends testRegister
  */
 public function testRegisterMultipleCalls()
 {
     # Get the current count of spl_autoload functions
     $function_count = count(spl_autoload_functions());
     # Re-register; number should be the same
     Autoload::register(dirname(dirname(__DIR__)));
     $this->assertEquals($function_count, count(spl_autoload_functions()));
 }
Exemple #30
0
 public function test_configure_environment()
 {
     $this->assertNotContains(array('Functest_Tests', 'autoload'), spl_autoload_functions());
     Functest_Tests::enable_environment();
     $this->assertContains(array('Functest_Tests', 'autoload'), spl_autoload_functions());
     Functest_Tests::disable_environment();
     $this->assertNotContains(array('Functest_Tests', 'autoload'), spl_autoload_functions());
 }