The Yaf_Loader class

(Yaf >=1.0.0)

锟斤拷锟�

Yaf_Loader 锟斤拷为Yaf锟结供锟斤拷锟皆讹拷锟斤拷锟截癸拷锟杰碉拷全锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷

锟节碉拷一锟斤拷使锟矫碉拷时锟津,斤拷锟斤拷锟斤拷 Yaf_Application 锟斤拷实锟斤拷锟斤拷 Yaf_Loader 实锟斤拷锟剿碉拷锟斤拷模式锟斤拷锟斤拷使锟斤拷spl_autoload注锟斤拷锟斤拷锟皆硷拷锟斤拷 通锟斤拷 Yaf_Loader::getInstance() 锟斤拷锟斤拷锟斤拷锟斤拷实锟斤拷

Yaf_Loader 锟斤拷锟斤拷一锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷一锟轿o拷锟斤拷锟绞э拷锟斤拷耍锟� 锟斤拷锟斤拷牟锟斤拷锟斤拷锟饺★拷锟斤拷锟�yaf.use_spl_auload锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为On锟斤拷Yaf_Loader::autoload() 锟斤拷锟结返锟斤拷FALSE锟斤拷 锟接讹拷锟窖伙拷锟斤拷锟矫革拷锟斤拷锟斤拷锟斤拷锟皆讹拷锟斤拷锟截癸拷锟杰★拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为Off锟斤拷默锟较o拷锟斤拷 Yaf_Loader::autoload() 锟斤拷锟结返锟斤拷TRUE锟斤拷 锟斤拷锟斤拷要锟斤拷锟角斤拷锟斤拷锟阶筹拷一锟斤拷锟角筹拷锟斤拷锟矫的撅拷锟芥(锟斤拷锟斤拷锟揭筹拷一锟斤拷锟斤拷锟斤拷锟绞э拷芊浅锟斤拷锟斤拷茫锟斤拷锟�

Note:

锟诫保锟斤拷yaf.use_spl_autoload锟斤拷锟街关闭o拷锟斤拷锟斤拷锟斤拷一些library锟斤拷锟皆硷拷锟斤拷autoload锟斤拷锟狡o拷锟斤拷锟斤拷锟斤拷锟睫凤拷锟斤拷写锟侥★拷

默锟斤拷锟斤拷锟斤拷拢锟�Yaf_Loader 锟秸硷拷锟斤拷锟斤拷library(锟洁定锟斤拷慕疟锟�)锟斤拷锟斤拷锟斤拷锟� php.ini(yaf.library)锟斤拷锟斤拷锟�global library directory之锟叫★拷

锟斤拷锟斤拷锟斤拷锟绞癸拷锟� Yaf_Loader 锟斤拷锟斤拷锟斤拷锟斤拷锟洁(锟解)锟斤拷锟斤拷锟斤拷锟斤拷application.ini锟斤拷 默锟斤拷锟斤拷锟斤拷拢锟斤拷锟斤拷锟� application.directory . "/libraray"锟斤拷锟斤拷 锟斤拷锟斤拷要使锟斤拷 Yaf_Loader::registerLocalNameSpace() 注锟结本锟斤拷锟斤拷前缀锟斤拷

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一些锟斤拷锟接o拷锟斤拷锟斤拷 APPLICATION_PATH 锟斤拷 application.directory锟斤拷锟斤拷

Example #1 Config example

// Assuming the following configure in php.ini:
yaf.libraray = "/global_dir"

//Assuming the following configure in application.ini
application.libraray = APPLICATION_PATH "/library"
锟斤拷锟斤拷锟斤拷锟铰憋拷锟斤拷锟斤拷锟狡空硷拷锟窖憋拷注锟结:

Example #2 注锟结本锟斤拷锟斤拷锟斤拷锟秸硷拷

<?php
class Bootstrap extends Yaf_Bootstrap_Abstract{
     public function 
_initLoader($dispatcher) {
          
Yaf_Loader::getInstance()->registerLocalNameSpace(array("Foo""Bar"));
     }
?>
锟皆讹拷锟斤拷锟斤拷锟斤拷锟接o拷

Example #3 锟斤拷锟斤拷锟斤拷

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
锟斤拷PHP 5.3锟叫o拷锟斤拷锟斤拷锟绞癸拷锟斤拷锟斤拷锟斤拷占洌�

Example #4 锟斤拷锟斤拷锟斤拷锟斤拷锟秸硷拷锟斤拷

class \Foo\Bar\Dummy =>
   // APPLICATION_PATH/library/Foo/Bar/Dummy.php

class \FooBar\Bar\Dummy =>
   // /global_dir/FooBar/Bar/Dummy.php

锟斤拷锟斤拷芑锟阶拷獾斤拷锟斤拷锟斤拷募锟斤拷锟斤拷锟斤拷值锟斤拷锟斤拷锟侥革拷谴锟叫达拷模锟斤拷锟斤拷锟斤拷通锟斤拷锟斤拷php.ini锟斤拷锟斤拷锟斤拷 yaf.lowcase_path = On 锟斤拷锟斤拷锟斤拷锟斤拷小写锟斤拷

Yaf_Loader 也锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟組VC锟洁,锟斤拷应锟侥癸拷锟斤拷锟斤拷锟铰o拷

Example #5 MVC锟斤拷锟斤拷锟斤拷锟斤拷锟�

Controller Classes =>
// APPLICATION_PATH/controllers/

Model Classes =>
// APPLICATION_PATH/models/

Plugin Classes =>
// APPLICATION_PATH/plugins/
Yaf 通锟斤拷识锟斤拷一锟斤拷锟斤拷暮锟阶猴拷锟斤拷锟斤拷锟斤拷默锟较的o拷锟斤拷也锟斤拷锟斤拷通锟斤拷锟侥憋拷锟斤拷锟斤拷锟斤拷 yaf.name_suffix 锟斤拷锟斤拷锟斤拷锟斤拷为通锟斤拷前缀识锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟角凤拷锟斤拷一锟斤拷MVC锟洁:

Example #6 MVC 锟斤拷锟斤拷锟斤拷

Controller Classes =>
    // ***Controller

Model Classes =>
    // ***Model

Plugin Classes =>
    // ***Plugin
some examples:

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
锟斤拷目录锟斤拷锟斤拷 yaf.lowcase_path 锟斤拷影锟届。

锟斤拷摘要

Yaf_Loader {
/* 锟斤拷锟斤拷 */
protected $_local_ns ;
protected $_library ;
protected $_global_library ;
static $_instance ;
/* 锟斤拷锟斤拷 */
public autoload ( void ) : void
public clearLocalNamespace ( void ) : void
private __clone ( void ) : void
private__construct ( void )
public static getInstance ( void ) : void
public getLibraryPath ([ bool $is_global = false ] ) : Yaf_Loader
public getLocalNamespace ( void ) : void
public static import ( void ) : void
public isLocalName ( void ) : void
public registerLocalNamespace ([ mixed $prefix ] ) : void
public setLibraryPath ( string $directory [, bool $is_global = false ] ) : Yaf_Loader
private __sleep ( void ) : void
private __wakeup ( void ) : void
}

锟斤拷锟斤拷

_local_ns

_library

默锟斤拷锟斤拷锟斤拷拢锟斤拷锟斤拷锟街碉拷锟� application.directory . "/library"锟斤拷 锟斤拷锟斤拷锟酵拷锟斤拷薷锟絘pplication.ini(application.library)锟斤拷锟竭碉拷锟斤拷 Yaf_Loader::setLibraryPath() 锟侥憋拷锟斤拷锟斤拷

_global_library

_instance

Table of Contents