Yaf
Namespaces
Classes
A action can be defined in a separate file in Yaf(see \Yaf\Controller_Abstract). that is a action method can also be a \Yaf\Action_Abstract class.
Since there should be a entry point which can be called by Yaf (as of PHP 5.3, there is a new magic method __invoke, but Yaf is not only works with PHP 5.3+, Yaf choose another magic method execute), you must implement the abstract method \Yaf\Action_Abstract::execute() in your custom action class.
\Yaf\Application provides a bootstrapping facility for applications which provides reusable resources, common- and module-based bootstrap classes and dependency checking.
Bootstrap is a mechanism used to do some initial config before a Application run.
User may define their own Bootstrap class by inheriting \Yaf\Bootstrap_Abstract
Any method declared in Bootstrap class with leading "_init", will be called by \Yaf\Application::bootstrap() one by one according to their defined order
\Yaf\Controller_Abstract is the heart of Yaf's system. MVC stands for Model-View-Controller and is a design pattern targeted at separating application logic from display logic.
Every custom controller shall inherit \Yaf\Controller_Abstract.
You will find that you can not define __construct function for your custom controller, thus, \Yaf\Controller_Abstract provides a magic method: \Yaf\Controller_Abstract::init().
If you have defined a init() method in your custom controller, it will be called as long as the controller was instantiated.
Action may have arguments, when a request coming, if there are the same name variable in the request parameters(see \Yaf\Request_Abstract::getParam()) after routed, Yaf will pass them to the action method (see \Yaf\Action_Abstract::execute()).
Note:
These arguments are directly fetched without filtering, it should be carefully processed before use them.
\Yaf\Dispatcher purpose is to initialize the request environment, route the incoming request, and then dispatch any discovered actions; it aggregates any responses and returns them when the process is complete.
\Yaf\Dispatcher also implements the Singleton pattern, meaning only a single instance of it may be available at any given time. This allows it to also act as a registry on which the other objects in the dispatch process may draw.
\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()
Plugins allow for easy extensibility and customization of the framework.
Plugins are classes. The actual class definition will vary based on the component -- you may need to implement this interface, but the fact remains that the plugin is itself a class.
A plugin could be loaded into Yaf by using \Yaf\Dispatcher::registerPlugin(), after registered, All the methods which the plugin implemented according to this interface, will be called at the proper time.
All methods of \Yaf\Registry declared as static, making it universally accessible. This provides the ability to get or set any custom data from anyway in your code as necessary.
by default, \Yaf\Router only have a \Yaf\Route_Static as its default route.
\Yaf\Route_Static is designed to handle 80% of normal requirements.
Note:
it is unnecessary to instance a \Yaf\Route_Static, also unnecessary to add it into \Yaf\Router's routes stack, since there is always be one in \Yaf\Router's routes stack, and always be called at the last time.
\Yaf\Router is the standard framework router. Routing is the process of taking a URI endpoint (that part of the URI which comes after the base URI: see \Yaf\Request_Abstract::setBaseUri()) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request. This values of the module, controller, action and other parameters are packaged into a \Yaf\Request_Abstract object which is then processed by \Yaf\Dispatcher. Routing occurs only once: when the request is initially received and before the first controller is dispatched. \Yaf\Router is designed to allow for mod_rewrite-like functionality using pure PHP structures. It is very loosely based on Ruby on Rails routing and does not require any prior knowledge of webserver URL rewriting
Default Route
\Yaf\Router comes pre-configured with a default route \Yaf\Route_Static, which will match URIs in the shape of controller/action. Additionally, a module name may be specified as the first path element, allowing URIs of the form module/controller/action. Finally, it will also match any additional parameters appended to the URI by default - controller/action/var1/value1/var2/value2.
Note:
Module name must be defined in config, considering application.module="Index,Foo,Bar", in this case, only index, foo and bar can be considered as a module name. if doesn't config, there is only one module named "Index".
** See examples by opening the external documentation
Interfaces
\Yaf\Route_Interface used for developer defined their custom route.
Yaf provides a ability for developers to use custom view engine instead of build-in engine which is \Yaf\View\Simple. There is a example to explain how to do this, please see \Yaf\Dispatcher::setView()