Yaf_Loader::registerLocalNamespace
(Yaf >=1.0.0)
Register local namespace
Description
Register a local namespace. Classes whose prefix belongs to a local namespace are looked up under the given path (or the local library directory when no path is given) instead of the global one.
This lets you place your own classes into the local library directory, while shared classes live in the global library directory (see the yaf.library ini setting).
Parameters
namespaceA namespace prefix string, or an array of prefix/path pairs (when the value is a path string) or prefix strings.
A prefix only matches at an underscore or backslash boundary: registering
ModelsmakesModels_UserandModelsitself local, but notModelsUser. A leading backslash is ignored, and a class name written with backslashes is looked up as if they were underscores.pathThe directory to look up the namespace in. If not given, the local library directory is used.
Return Values
Returns the loader instance itself on success, or false if an invalid parameter is provided.
Examples
Yaf_Loader::registerLocalNamespace example
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
public function _initLoader()
{
$loader = Yaf_Loader::getInstance();
/* Models_User is now looked up in
* APPLICATION_PATH/library/Models/User.php */
$loader->registerLocalNamespace("Models");
/* register several prefixes at once, each with its
* own lookup directory */
$loader->registerLocalNamespace(array(
"Services" => APPLICATION_PATH . "/services",
"Vendor" => APPLICATION_PATH . "/vendor",
));
}
}
?>See Also
Yaf_Loader::getLocalNamespaceYaf_Loader::clearLocalNamespaceYaf_Loader::isLocalName