|
The Yaf_Loader classIntroductionYaf_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_auload, if this
config is On Yaf_Loader::autoload will return
By default, Yaf_Loader assume all library (class defined script) store in the global library directory, which is defined in the php.ini(yaf.library). 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 Let's see some examples(assuming APPLICATION_PATH is application.directory): Example #1 Config example // Assuming the following configure in php.ini: yaf.library = "/global_dir" //Assuming the following configure in application.ini application.library = APPLICATION_PATH "/library" Example #2 Register localnamespace
Example #3 Load class example class Foo_Bar_Test => // APPLICATION_PATH/library/Foo/Bar/Test.php class GLO_Name => // /global_dir/Glo/Name.php class BarNon_Test // /global_dir/Barnon/Test.php Example #4 Load namespace class example class \Foo\Bar\Dummy => // APPLICATION_PATH/library/Foo/Bar/Dummy.php class \FooBar\Bar\Dummy => // /global_dir/FooBar/Bar/Dummy.php You may noticed that all the folder with the first letter capitalized, you can make them lowercase by set yaf.lowcase_path = On in php.ini Yaf_Loader is also designed to load the MVC classes, and the rule is: Example #5 MVC class loading example Controller Classes => // APPLICATION_PATH/controllers/ Model Classes => // APPLICATION_PATH/models/ Plugin Classes => // APPLICATION_PATH/plugins/ Example #6 MVC class distinctions Controller Classes => // ***Controller Model Classes => // ***Model Plugin Classes => // ***Plugin Example #7 MVC loading example class IndexController // APPLICATION_PATH/controllers/Index.php class DataModel => // APPLICATION_PATH/models/Data.php class DummyPlugin => // APPLICATION_PATH/plugins/Dummy.php class A_B_TestModel => // APPLICATION_PATH/models/A/B/Test.php also, the directory will be affected by yaf.lowcase_path. Class synopsisYaf_Loader
class Yaf_Loader
{
/* Properties */
protected
$_local_ns;
protected
$_library;
protected
$_global_library;
static
$_instance;
/* Methods */
private __construct()
public void autoload()
public void clearLocalNamespace()
public static void getInstance()
public Yaf_Loader getLibraryPath(bool
$is_global = false )public void getLocalNamespace()
public string getNamespacePath(string
$namespaces )public array getNamespaces()
public static void import()
public void isLocalName()
public void registerLocalNamespace(mixed
$prefix )public bool registerNamespace(stringarray
$namespaces , string $path = ?)public Yaf_Loader setLibraryPath(string
}$directory , bool $is_global = false )Properties
|