YAF 0 Basic Learning Summary 5-yaf class automatic loading
An important function of the framework is the automatic loading of classes, in the first demo we agreed to the directory structure of our project, the framework based on this directory structure to automatically load the required class files.
YAF registers an own autoloader with SPL at startup, and for performance reasons, the YAF autoloader only attempts to use directory mappings for framework-related MVC classes.
the specific directory mapping rules are as follows:
For controller controllers, the default module is {Project path}/controllers/, otherwise {Project path}/modules/{module name}/controllers such as Indexcontroller, which automatically loads the file {project directory}/ controllers/index.php
For model load path {project directory}/models/like Usermodel automatically loads {project directory}/models/user.php
Other rules, like Actions,plugin, are similar.
For non-framework MVC-related classes, YAF supports two load modes for global classes and their own classes, and YAF supports case-sensitive and insensitive methods to handle file paths.
Global class and Self class (local class)
Yaf to facilitate the sharing of company-level shared libraries between different products deployed on a single server, support for global classes and native class two loading methods.
A global class is a class that is shared among all products, and the path of these class libraries is through Ap.library in php.ini (of course, if PHP supports with-config-file-scan-dir when compiling, it can also be written in a separate ap.ini)
While local classes refer to the product's own class libraries, the paths of these class libraries are configured through Ap.library in the product's configuration file. In Yaf, by invoking the Registerlocalnamespace method of Yaf_loader, the class prefix is declared to be a local class, Can.
Note: In the case of Use_spl_autoload shutdown, the YAF Autoloader will return immediately if it is not found at one time and deprive the subsequent autoloader of the execution opportunity.
loading rules for classes in Yaf
The load rules for a class are the same: YAF specifies that the class name must contain the path information, which is the directory information that is divided by the underscore "_". YAF will complete the automatic loading according to the directory information in the class name. In the case of the following example, in the absence of a declaration of a local class:
An example of a mapping Zend_dummy_foo
YAF will look for class Foo_dummy_bar in the following path
{The class library path (ap.library specified in php.ini)}/foo/dummy/bar.php
And, if Registerlocalnamespace is called by the following: Register local class
[PHP]View Plaincopy
- Declares that any class that starts with Foo and local is a local class
- $loader = Yaf_loader::getignstance ();
- $loader->registerlocalnamespace (Array ("Foo", "Local");
So for the example just now, we'll look for Foo_dummy_bar in the following path
YAF will look for class Foo_dummy_bar in the following path
{The class library path (ap.library specified in Conf/application.ini)}/foo/dummy/bar.php
With this example, you should know the loading rules for the Yaf class, as well as the ability to distinguish between global classes and local classes.
Reference Source:
YAF 0 Basic Learning Summary 5-yaf class automatic loading
Http://www.lai18.com/content/407152.html
YAF 0 Basic Learning Summary 5-yaf class automatic loading