本文整理汇总了PHP中Composer\Autoload\ClassLoader::registerPrefix方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader::registerPrefix方法的具体用法?PHP ClassLoader::registerPrefix怎么用?PHP ClassLoader::registerPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Autoload\ClassLoader
的用法示例。
在下文中一共展示了ClassLoader::registerPrefix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerNamespace
/**
* @param string $ns Namespace's description
* @param string $path Namespace's path
* @throws Exception
*/
public static function registerNamespace($ns, $path)
{
switch (true) {
case self::$loader instanceof \Composer\Autoload\ClassLoader:
self::$loader->add($ns, $path);
break;
case self::$loader instanceof \Zend\Loader\SplAutoloader:
self::$loader->registerPrefix($ns, $path . '/' . $ns);
break;
// @TODO: This hasn't been tested nor confirmed. Must test & check if OK.
// @TODO: This hasn't been tested nor confirmed. Must test & check if OK.
case self::$loader instanceof \Symfony\Component\ClassLoader\UniversalClassLoader:
self::$loader->registerNamespace($ns, $path);
break;
default:
throw new \Exception('No Loader detected!');
}
}
示例2: registerNamespace
/**
* Class Prefix (Namespace) Register
*
* @param string $prefix
* @param string $path
* @throws \Exception
*/
public function registerNamespace($prefix, $path)
{
switch (true) {
// Zend Loader
case self::$loader instanceof \Zend\Loader\SplAutoloader:
self::$loader->registerPrefix($prefix, $path . '/' . str_replace('\\', '/', $prefix));
break;
// Composer Loader
// Composer Loader
case self::$loader instanceof \Composer\Autoload\ClassLoader:
self::$loader->add($prefix, $path);
break;
// Symphony Loader
// @TODO: Wonder if we should implement this as well or not
// Throw exception for not finding a suported loader
// Symphony Loader
// @TODO: Wonder if we should implement this as well or not
// Throw exception for not finding a suported loader
default:
throw new Exception\UndefinedClassLoaderException(sprintf('Unexpected ClassLoader type: \'%s\'', get_class(self::$loader)));
}
return $this;
}