class Yaf_Loader (View source)

Yaf_Loader introduces a comprehensive autoloading solution for Yaf.


The first time an instance of Yaf_Application is retrieved, Yaf_Loader will instance a singleton, and registers itself with spl_autoload. You retrieve an instance using the Yaf_Loader::getInstance()


Yaf_Loader attempt to load a class only one shot, if failed, depend on yaf.use_spl_autoload, if this config is On Yaf_Loader::autoload() will return FALSE, thus give the chance to other autoload function. if it is Off (by default), Yaf_Loader::autoload() will return TRUE, and more important is that a very useful warning will be triggered (very useful to find out why a class could not be loaded).


Note:

Please keep yaf.use_spl_autoload Off unless there is some library have their own autoload mechanism and impossible to rewrite it.


If you want Yaf_Loader search some classes(libraries) in the local class directory(which is defined in application.ini, and by default, it is application.directory . "/library"), you should register the class prefix using the Yaf_Loader::registerLocalNameSpace()

Properties

protected string $_local_ns
protected string $_library

By default, this value is application.directory . "/library", you can change this either in the application.ini(application.library) or call to Yaf_Loader::setLibraryPath()

protected string $_global_library
static protected Yaf_Loader $_instance

Methods

bool
autoload(string $class_name)

No description

static Yaf_Loader
getInstance(string $local_library_path = null, string $global_library_path = null)

No description

bool
registerLocalNamespace(string|string[] $namespace, string $path = '')

Register local class prefix name, Yaf_Loader search classes in two library directories, the one is configured via application.library.directory(in application.ini) which is called local library directory; the other is configured via yaf.library (in php.ini) which is called global library directory, since it can be shared by many applications in the same server.


When an autoloading is triggered, Yaf_Loader will determine which library directory should be searched in by examining the prefix name of the missed classname. If the prefix name is registered as a local namespace then look for it in local library directory, otherwise look for it in global library directory.


Note:

If yaf.library is not configured, then the global library directory is assumed to be the local library directory. in that case, all autoloading will look for local library directory. But if you want your Yaf application be strong, then always register your own classes as local classes.

string
getLocalNamespace()

No description

string
getNamespaces()

No description

bool
clearLocalNamespace()

No description

bool
isLocalName(string $class_name)

No description

static bool
import(string $file)

No description

setLibraryPath(string $library_path, bool $is_global = false)

No description

string
getLibraryPath(bool $is_global = false)

No description

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

No description

string
getNamespacePath(string $class_name)

No description

Details

bool autoload(string $class_name)

No description

Parameters

string $class_name

Return Value

bool

static Yaf_Loader getInstance(string $local_library_path = null, string $global_library_path = null)

No description

Parameters

string $local_library_path
string $global_library_path

Return Value

Yaf_Loader

bool registerLocalNamespace(string|string[] $namespace, string $path = '')

Register local class prefix name, Yaf_Loader search classes in two library directories, the one is configured via application.library.directory(in application.ini) which is called local library directory; the other is configured via yaf.library (in php.ini) which is called global library directory, since it can be shared by many applications in the same server.


When an autoloading is triggered, Yaf_Loader will determine which library directory should be searched in by examining the prefix name of the missed classname. If the prefix name is registered as a local namespace then look for it in local library directory, otherwise look for it in global library directory.


Note:

If yaf.library is not configured, then the global library directory is assumed to be the local library directory. in that case, all autoloading will look for local library directory. But if you want your Yaf application be strong, then always register your own classes as local classes.

Parameters

string|string[] $namespace

a string or a array of class name prefix. all class prefix with these prefix will be loaded in local library path.

string $path

Return Value

bool

string getLocalNamespace()

No description

Return Value

string

string getNamespaces()

No description

Return Value

string

bool clearLocalNamespace()

No description

Return Value

bool

bool isLocalName(string $class_name)

No description

Parameters

string $class_name

Return Value

bool

static bool import(string $file)

No description

Parameters

string $file

Return Value

bool

Yaf_Loader setLibraryPath(string $library_path, bool $is_global = false)

Since: 2.1.4

No description

Parameters

string $library_path
bool $is_global

Return Value

Yaf_Loader

string getLibraryPath(bool $is_global = false)

Since: 2.1.4

No description

Parameters

bool $is_global

Return Value

string

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

No description

Parameters

string|array $namespace
string $path

Return Value

Yaf_Loader|null|false

string getNamespacePath(string $class_name)

No description

Parameters

string $class_name

Return Value

string