public function testUseIncludePath() { $loader = new UniversalClassLoader(); $this->assertFalse($loader->getUseIncludePath()); $this->assertNull($loader->findFile('Foo')); $includePath = get_include_path(); $loader->useIncludePath(true); $this->assertTrue($loader->getUseIncludePath()); set_include_path(__DIR__ . '/Fixtures/includepath' . PATH_SEPARATOR . $includePath); $this->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'includepath' . DIRECTORY_SEPARATOR . 'Foo.php', $loader->findFile('Foo')); set_include_path($includePath); }
/** * Finds the path to the file where the class is defined. * * @param string $class The name of the class * * @return string|null The path, if found */ public function findFile($class) { if ('\\' == $class[0]) { $class = substr($class, 1); } # Test if we have a namespace class name if (false === ($pos = strrpos($class, '\\'))) { # Use normal loading return parent::findFile($class); } # fetch the extension namespaces #find if any match the current namespace foreach ($this->getExtensionNamespace() as $ext_namespace => $ext_folder) { $pos = strrpos($class, '\\'); $namespace = substr($class, 0, $pos); $className = substr($class, $pos + 1); # check if the extension namespace found in the current class (at string 0) if (0 === strpos($namespace, $ext_namespace)) { # apply call back to filter the namespace Faker_components' if ($this->filter instanceof \Closure) { $filter = $this->filter; $namespace = $filter($namespace); } $normalizedClass = strtolower(str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'); $file = $ext_folder . DIRECTORY_SEPARATOR . $normalizedClass; if (is_file($file)) { return $file; } } } # Use normal loading return parent::findFile($class); }