PHP Conference Ehime 2026

Yaf_Loader::registerLocalNamespace

(Yaf >=1.0.0)

Yaf_Loader::registerLocalNamespaceRegister local namespace

Beschreibung

public function Yaf_Loader::registerLocalNamespace(string|array $namespace, string $path = null): Yaf_Loader|false

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).

Parameter-Liste

namespace

A 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 Models makes Models_User and Models itself local, but not ModelsUser. A leading backslash is ignored, and a class name written with backslashes is looked up as if they were underscores.

path

The directory to look up the namespace in. If not given, the local library directory is used.

Rückgabewerte

Returns the loader instance itself on success, or false if an invalid parameter is provided.

Beispiele

Beispiel #1 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",
        ));
    }
}
?>

Siehe auch

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top