Yaf_Loader::registerNamespace
(Yaf >=3.2.0)
Yaf_Loader::registerNamespace — registerLocalNamespace 的别名
说明
public function Yaf_Loader::registerNamespace(string|array
$name_prefix, string $path = null): Yaf_Loader|false|null参数
name_prefix
命名空间前缀字符串,或者前缀/路径对(当值为路径字符串时)或前缀字符串组成的数组。
path
查找该命名空间的目录。如果未提供,则使用本地库目录。
返回值
成功时返回加载器实例自身,如果提供了无效参数则返回 false。
示例
示例 #1 Yaf_Loader::registerNamespace() 示例
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
public function _initLoader()
{
/* registerNamespace() 是 registerLocalNamespace() 的别名 */
Yaf_Loader::getInstance()->registerNamespace(
"Vendor",
APPLICATION_PATH . "/library/Vendor"
);
}
}
/* new Vendor_Payment_Gateway() 现在会在
* APPLICATION_PATH/library/Vendor/Payment/Gateway.php 中查找 */
?>参见
- Yaf_Loader::registerLocalNamespace() - 注册本地命名空间
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
