php8.5
Home/ Manual/ yaf / yaf_loader/ Yaf_Loader::registerNamespace

Yaf_Loader::registerNamespace

PHP function Edit on GitHub ✎

(Yaf >=3.2.0)

Alias of registerLocalNamespace

Description

Yaf_Loader::registerNamespace(string|array $namespace, string $path = null): Yaf_Loader|false

Alias of Yaf_Loader::registerLocalNamespace.

Parameters

namespace

A namespace prefix string, or an array of prefix/path pairs (when the value is a path string) or prefix strings.

path

The 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::registerNamespace example

php
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initLoader()
    {
        /* registerNamespace() is an alias of registerLocalNamespace() */
        Yaf_Loader::getInstance()->registerNamespace(
            "Vendor",
            APPLICATION_PATH . "/library/Vendor"
        );
    }
}

/* new Vendor_Payment_Gateway() is now looked up in
 * APPLICATION_PATH/library/Vendor/Payment/Gateway.php */
?>

See Also

  • Yaf_Loader::registerLocalNamespace

Source: reference/yaf/yaf_loader/registernamespace.xml · from the official PHP manual (php/doc-en)