本文整理汇总了PHP中Symfony\Component\ClassLoader\UniversalClassLoader::findFile方法的典型用法代码示例。如果您正苦于以下问题:PHP UniversalClassLoader::findFile方法的具体用法?PHP UniversalClassLoader::findFile怎么用?PHP UniversalClassLoader::findFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\ClassLoader\UniversalClassLoader
的用法示例。
在下文中一共展示了UniversalClassLoader::findFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUseIncludePath
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);
}
示例2: findFile
/**
* 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);
}