Yet Another FrameworkTable of Contents
The Yaf_Application classIntroductionYaf_Application provides a bootstrapping facility for applications which provides reusable resources, common- and module-based bootstrap classes and dependency checking.
Class synopsisYaf_Application
final
class Yaf_Application
{
/* Properties */
protected
$config
;
protected
$dispatcher
;
protected
static
$_app
;
protected
$_modules
;
protected
$_running
;
protected
$_environ
;
/* Methods */
public static void app
( void
)
public void bootstrap
([ Yaf_Bootstrap_Abstract
$bootstrap
] )
public Yaf_Application clearLastError
( void
)
private void __clone
( void
)
public __construct
( mixed
$config
[, string $envrion
] )
public void __destruct
( void
)
public void environ
( void
)
public void execute
( callable
$entry
, string $...
)
public Yaf_Application getAppDirectory
( void
)
public Yaf_Config_Abstract getConfig
( void
)
public Yaf_Dispatcher getDispatcher
( void
)
public string getLastErrorMsg
( void
)
public int getLastErrorNo
( void
)
public array getModules
( void
)
public void run
( void
)
public Yaf_Application setAppDirectory
( string
$directory
)
private void __sleep
( void
)
private void __wakeup
( void
)
}Properties
The Yaf_Bootstrap_Abstract classIntroductionBootstrap is a mechanism used to do some intial 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. ExamplesExample #1 Bootstrap example
<?php The above example will output something similar to: string(22) "Bootstrap::_initConfig" string(22) "Bootstrap::_initPlugin" Class synopsisYaf_Bootstrap_Abstract
abstract
class Yaf_Bootstrap_Abstract
{
/* Properties */
/* Methods */
}The Yaf_Dispatcher classIntroductionYaf_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. Class synopsisYaf_Dispatcher
final
class Yaf_Dispatcher
{
/* Properties */
protected
$_router
;
protected
$_view
;
protected
$_request
;
protected
$_plugins
;
protected
static
$_instance
;
protected
$_auto_render
;
protected
$_return_response
;
protected
$_instantly_flush
;
protected
$_default_module
;
protected
$_default_controller
;
protected
$_default_action
;
/* Methods */
public Yaf_Dispatcher autoRender
([ bool
$flag
] )
public Yaf_Dispatcher catchException
([ bool
$flag
] )
private void __clone
( void
)
public __construct
( void
)
public bool disableView
( void
)
public Yaf_Response_Abstract dispatch
( Yaf_Request_Abstract
$request
)
public Yaf_Dispatcher enableView
( void
)
public Yaf_Dispatcher flushInstantly
([ bool
$flag
] )
public Yaf_Application getApplication
( void
)
public static Yaf_Dispatcher getInstance
( void
)
public Yaf_Request_Abstract getRequest
( void
)
public Yaf_Router getRouter
( void
)
public Yaf_View_Interface initView
( string
$templates_dir
[, array $options
] )
public Yaf_Dispatcher registerPlugin
( Yaf_Plugin_Abstract
$plugin
)
public Yaf_Dispatcher returnResponse
( bool
$flag
)
public Yaf_Dispatcher setDefaultAction
( string
$action
)
public Yaf_Dispatcher setDefaultController
( string
$controller
)
public Yaf_Dispatcher setDefaultModule
( string
$module
)
public Yaf_Dispatcher setErrorHandler
( call
$callback
, int $error_types
)
public Yaf_Dispatcher setRequest
( Yaf_Request_Abstract
$request
)
public Yaf_Dispatcher setView
( Yaf_View_Interface
$view
)
private void __sleep
( void
)
public Yaf_Dispatcher throwException
([ bool
$flag
] )
private void __wakeup
( void
)
}Properties
The Yaf_Config_Abstract classIntroduction
Class synopsisYaf_Config_Abstract
abstract
class Yaf_Config_Abstract
{
/* Properties */
protected
$_config
;
protected
$_readonly
;
/* Methods */
abstract public mixed get
( string
$name
, mixed $value
)
abstract public bool readonly
( void
)
abstract public Yaf_Config_Abstract set
( void
)
abstract public array toArray
( void
)
}Properties
The Yaf_Config_Ini classIntroductionYaf_Config_Ini enables developers to store configuration data in a familiar INI format and read them in the application by using nested object property syntax. The INI format is specialized to provide both the ability to have a hierarchy of configuration data keys and inheritance between configuration data sections. Configuration data hierarchies are supported by separating the keys with the dot or period character ("."). A section may extend or inherit from another section by following the section name with a colon character (":") and the name of the section from which data are to be inherited.
Class synopsisYaf_Config_Ini
class Yaf_Config_Ini
extends
Yaf_Config_Abstract
implements
Iterator
,
ArrayAccess
,
Countable
{
/* Properties */
/* Methods */
public __construct
( string
$config_file
[, string $section
] )
public void count
( void
)
public void current
( void
)
public void __get
([ string
$name
] )
public void __isset
( string
$name
)
public void key
( void
)
public void next
( void
)
public void offsetExists
( string
$name
)
public void offsetGet
( string
$name
)
public void offsetSet
( string
$name
, string $value
)
public void offsetUnset
( string
$name
)
public void readonly
( void
)
public void rewind
( void
)
public void __set
( string
$name
, mixed $value
)
public array toArray
( void
)
public void valid
( void
)
/* Inherited methods */
abstract public mixed Yaf_Config_Abstract::get
( string
$name
, mixed $value
)
abstract public bool Yaf_Config_Abstract::readonly
( void
)
abstract public Yaf_Config_Abstract Yaf_Config_Abstract::set
( void
)
abstract public array Yaf_Config_Abstract::toArray
( void
)
}Properties
ExamplesExample #1 Yaf_Config_Iniexample This example illustrates a basic use of Yaf_Config_Ini for loading configuration data from an INI file. In this example there are configuration data for both a production system and for a staging system. Because the staging system configuration data are very similar to those for production, the staging section inherits from the production section. In this case, the decision is arbitrary and could have been written conversely, with the production section inheriting from the staging section, though this may not be the case for more complex situations. Suppose, then, that the following configuration data are contained in /path/to/config.ini: ; Production site configuration data [production] webhost = www.example.com database.adapter = pdo_mysql database.params.host = db.example.com database.params.username = dbuser database.params.password = secret database.params.dbname = dbname ; Staging site configuration data inherits from production and ; overrides values as necessary [staging : production] database.params.host = dev.example.com database.params.username = devuser database.params.password = devsecret
<?php The above example will output something similar to: string(15) "dev.example.com" string(6) "dbname" string(7) "devuser The Yaf_Config_Simple classIntroduction
Class synopsisYaf_Config_Simple
class Yaf_Config_Simple
extends
Yaf_Config_Abstract
implements
Iterator
,
ArrayAccess
,
Countable
{
/* Properties */
protected
$_readonly
;
/* Methods */
public __construct
( string
$config_file
[, string $section
] )
public void count
( void
)
public void current
( void
)
public void __get
([ string
$name
] )
public void __isset
( string
$name
)
public void key
( void
)
public void next
( void
)
public void offsetExists
( string
$name
)
public void offsetGet
( string
$name
)
public void offsetSet
( string
$name
, string $value
)
public void offsetUnset
( string
$name
)
public void readonly
( void
)
public void rewind
( void
)
public void __set
( string
$name
, string $value
)
public array toArray
( void
)
public void valid
( void
)
/* Inherited methods */
abstract public mixed Yaf_Config_Abstract::get
( string
$name
, mixed $value
)
abstract public bool Yaf_Config_Abstract::readonly
( void
)
abstract public Yaf_Config_Abstract Yaf_Config_Abstract::set
( void
)
abstract public array Yaf_Config_Abstract::toArray
( void
)
}Properties
The Yaf_Controller_Abstract classIntroductionYaf_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).
Class synopsisYaf_Controller_Abstract
abstract
class Yaf_Controller_Abstract
{
/* Properties */
public
$actions
;
protected
$_module
;
protected
$_name
;
protected
$_request
;
protected
$_response
;
protected
$_invoke_args
;
protected
$_view
;
/* Methods */
final private void __clone
( void
)
final private __construct
( void
)
protected bool display
( string
$tpl
[, array $parameters
] )
public void forward
( string
$action
[, array $paramters
] )
public void getInvokeArg
( string
$name
)
public void getInvokeArgs
( void
)
public string getModuleName
( void
)
public Yaf_Request_Abstract getRequest
( void
)
public Yaf_Response_Abstract getResponse
( void
)
public Yaf_View_Interface getView
( void
)
public void getViewpath
( void
)
public void init
( void
)
public void initView
([ array
$options
] )
public bool redirect
( string
$url
)
protected string render
( string
$tpl
[, array $parameters
] )
public void setViewpath
( string
}$view_directory
)Properties
The Yaf_Action_Abstract classIntroductionA 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. Class synopsisYaf_Action_Abstract
class Yaf_Action_Abstract
extends
Yaf_Controller_Abstract
{
/* Properties */
protected
$_controller
;
/* Methods */
abstract publicmixed execute
([ mixed
$arg
[, mixed $...
]] )
publicYaf_Controller_Abstract getController
( void
)
/* Inherited methods */
final private void Yaf_Controller_Abstract::__clone
( void
)
final private Yaf_Controller_Abstract::__construct
( void
)
protected bool Yaf_Controller_Abstract::display
( string
$tpl
[, array $parameters
] )
public void Yaf_Controller_Abstract::forward
( string
$action
[, array $paramters
] )
public void Yaf_Controller_Abstract::getInvokeArg
( string
$name
)
public void Yaf_Controller_Abstract::getInvokeArgs
( void
)
public string Yaf_Controller_Abstract::getModuleName
( void
)
public Yaf_Request_Abstract Yaf_Controller_Abstract::getRequest
( void
)
public Yaf_Response_Abstract Yaf_Controller_Abstract::getResponse
( void
)
public Yaf_View_Interface Yaf_Controller_Abstract::getView
( void
)
public void Yaf_Controller_Abstract::getViewpath
( void
)
public void Yaf_Controller_Abstract::init
( void
)
public void Yaf_Controller_Abstract::initView
([ array
$options
] )
public bool Yaf_Controller_Abstract::redirect
( string
$url
)
protected string Yaf_Controller_Abstract::render
( string
$tpl
[, array $parameters
] )
public void Yaf_Controller_Abstract::setViewpath
( string
}$view_directory
)Properties
The Yaf_View_Interface classIntroductionYaf provides a ability for developers to use coustom 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. Class synopsisYaf_View_Interface
class Yaf_View_Interface
{
/* Methods */
abstract public bool assign
( string
$name
[, string $value
] )
abstract public bool display
( string
$tpl
[, array $tpl_vars
] )
abstract public void getScriptPath
( void
)
abstract public string render
( string
$tpl
[, array $tpl_vars
] )
abstract public void setScriptPath
( string
}$template_dir
)The Yaf_View_Simple classIntroductionYaf_View_Simple is the built-in template engine in Yaf, it is a simple but fast template engine, and only support PHP script template. Class synopsisYaf_View_Simple
class Yaf_View_Simple
implements
Yaf_View_Interface
{
/* Properties */
protected
$_tpl_vars
;
protected
$_tpl_dir
;
/* Methods */
public bool assign
( string
$name
[, mixed $value
] )
public bool assignRef
( string
$name
, mixed &$value
)
public bool clear
([ string
$name
] )
final public __construct
( string
$template_dir
[, array $options
] )
public bool display
( string
$tpl
[, array $tpl_vars
] )
public string eval
( string
$tpl_content
[, array $tpl_vars
] )
public void __get
([ string
$name
] )
public string getScriptPath
( void
)
public void __isset
( string
$name
)
public string render
( string
$tpl
[, array $tpl_vars
] )
public void __set
( string
$name
, mixed $value
)
public bool setScriptPath
( string
}$template_dir
)Properties
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
<?php 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 wth 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 */
public void autoload
( void
)
public void clearLocalNamespace
( void
)
private void __clone
( void
)
private __construct
( void
)
public static void getInstance
( void
)
public Yaf_Loader getLibraryPath
([ bool
$is_global = false
] )
public void getLocalNamespace
( void
)
public static void import
( void
)
public void isLocalName
( void
)
public void registerLocalNamespace
( mixed
$prefix
)
public Yaf_Loader setLibraryPath
( string
$directory
[, bool $is_global = false
] )
private void __sleep
( void
)
private void __wakeup
( void
)
}Properties
The Yaf_Plugin_Abstract classIntroductionPlugins 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 registerd, All the methods which the plugin implemented according to this interface, will be called at the proper time. ExamplesExample #1 Plugin example
<?php The above example will output something similar to: string(13) "routerStartup" string(14) "routerShutdown" string(19) "dispatchLoopStartup" string(11) "preDispatch" string(12) "postDispatch" string(20) "dispatchLoopShutdown" Class synopsisYaf_Plugin_Abstract
class Yaf_Plugin_Abstract
{
/* Methods */
public void dispatchLoopShutdown
( Yaf_Request_Abstract
$request
, Yaf_Response_Abstract $response
)
public void dispatchLoopStartup
( Yaf_Request_Abstract
$request
, Yaf_Response_Abstract $response
)
public void postDispatch
( Yaf_Request_Abstract
$request
, Yaf_Response_Abstract $response
)
public void preDispatch
( Yaf_Request_Abstract
$request
, Yaf_Response_Abstract $response
)
public void preResponse
( Yaf_Request_Abstract
$request
, Yaf_Response_Abstract $response
)
public void routerShutdown
( Yaf_Request_Abstract
$request
, Yaf_Response_Abstract $response
)
public void routerStartup
( Yaf_Request_Abstract
}$request
, Yaf_Response_Abstract $response
)The Yaf_Registry classIntroductionAll methods of Yaf_Registry declared as static, making it unversally accessible. This provides the ability to get or set any custom data from anyway in your code as necessary. Class synopsisYaf_Registry
class Yaf_Registry
{
/* Properties */
static
$_instance
;
protected
$_entries
;
/* Methods */
private void __clone
( void
)
private __construct
( void
)
public static void del
( string
$name
)
public static mixed get
( string
$name
)
public static bool has
( string
$name
)
public static bool set
( string
}$name
, string $value
)Properties
The Yaf_Request_Abstract classIntroduction
Class synopsisYaf_Request_Abstract
class Yaf_Request_Abstract
{
/* Constants */
const
string
Yaf_Request_Abstract::SCHEME_HTTP
= http
;
const
string
Yaf_Request_Abstract::SCHEME_HTTPS
= https
;
/* Properties */
public
$module
;
public
$controller
;
public
$action
;
public
$method
;
protected
$params
;
protected
$language
;
protected
$_exception
;
protected
$_base_uri
;
protected
$uri
;
protected
$dispatched
;
protected
$routed
;
/* Methods */
public void getActionName
( void
)
public void getBaseUri
( void
)
public void getControllerName
( void
)
public void getEnv
( string
$name
[, string $default
] )
public void getException
( void
)
public void getLanguage
( void
)
public void getMethod
( void
)
public void getModuleName
( void
)
public void getParam
( string
$name
[, string $default
] )
public void getParams
( void
)
public void getRequestUri
( void
)
public void getServer
( string
$name
[, string $default
] )
public void isCli
( void
)
public void isDispatched
( void
)
public void isGet
( void
)
public void isHead
( void
)
public void isOptions
( void
)
public void isPost
( void
)
public void isPut
( void
)
public void isRouted
( void
)
public void isXmlHttpRequest
( void
)
public void setActionName
( string
$action
)
public bool setBaseUri
( string
$uir
)
public void setControllerName
( string
$controller
)
public void setDispatched
( void
)
public void setModuleName
( string
$module
)
public void setParam
( string
$name
[, string $value
] )
public void setRequestUri
( string
$uir
)
public void setRouted
([ string
}$flag
] )Properties
Predefined Constants
The Yaf_Request_Http classIntroductionAny request from client is initialized as a Yaf_Request_Http. you can get the rquest infomations like, uri query and post parameters via methods of this class.
Class synopsisYaf_Request_Http
class Yaf_Request_Http
extends
Yaf_Request_Abstract
{
/* Properties */
/* Methods */
private void __clone
( void
)
public __construct
([ string
$request_uri
[, string $base_uri
]] )
public mixed get
( string
$name
[, string $default
] )
public mixed getCookie
( string
$name
[, string $default
] )
public void getFiles
( void
)
public mixed getPost
( string
$name
[, string $default
] )
public mixed getQuery
( string
$name
[, string $default
] )
public void getRequest
( void
)
public bool isXmlHttpRequest
( void
)
/* Inherited methods */
public void Yaf_Request_Abstract::getActionName
( void
)
public void Yaf_Request_Abstract::getBaseUri
( void
)
public void Yaf_Request_Abstract::getControllerName
( void
)
public void Yaf_Request_Abstract::getEnv
( string
$name
[, string $default
] )
public void Yaf_Request_Abstract::getException
( void
)
public void Yaf_Request_Abstract::getLanguage
( void
)
public void Yaf_Request_Abstract::getMethod
( void
)
public void Yaf_Request_Abstract::getModuleName
( void
)
public void Yaf_Request_Abstract::getParam
( string
$name
[, string $default
] )
public void Yaf_Request_Abstract::getParams
( void
)
public void Yaf_Request_Abstract::getRequestUri
( void
)
public void Yaf_Request_Abstract::getServer
( string
$name
[, string $default
] )
public void Yaf_Request_Abstract::isCli
( void
)
public void Yaf_Request_Abstract::isDispatched
( void
)
public void Yaf_Request_Abstract::isGet
( void
)
public void Yaf_Request_Abstract::isHead
( void
)
public void Yaf_Request_Abstract::isOptions
( void
)
public void Yaf_Request_Abstract::isPost
( void
)
public void Yaf_Request_Abstract::isPut
( void
)
public void Yaf_Request_Abstract::isRouted
( void
)
public void Yaf_Request_Abstract::isXmlHttpRequest
( void
)
public void Yaf_Request_Abstract::setActionName
( string
$action
)
public bool Yaf_Request_Abstract::setBaseUri
( string
$uir
)
public void Yaf_Request_Abstract::setControllerName
( string
$controller
)
public void Yaf_Request_Abstract::setDispatched
( void
)
public void Yaf_Request_Abstract::setModuleName
( string
$module
)
public void Yaf_Request_Abstract::setParam
( string
$name
[, string $value
] )
public void Yaf_Request_Abstract::setRequestUri
( string
$uir
)
public void Yaf_Request_Abstract::setRouted
([ string
}$flag
] )Properties
The Yaf_Request_Simple classIntroductionYaf_Request_Simple is particularlly used for test puporse. ie. simulate some espacial request under CLI mode. Class synopsisYaf_Request_Simple
class Yaf_Request_Simple
extends
Yaf_Request_Abstract
{
/* Constants */
const
string
Yaf_Request_Simple::SCHEME_HTTP
= http
;
const
string
Yaf_Request_Simple::SCHEME_HTTPS
= https
;
/* Properties */
/* Methods */
private void __clone
( void
)
public __construct
([ string
$method
[, string $module
[, string $controller
[, string $action
[, array $params
]]]]] )
public void get
( void
)
public void getCookie
( void
)
public void getFiles
( void
)
public void getPost
( void
)
public void getQuery
( void
)
public void getRequest
( void
)
public void isXmlHttpRequest
( void
)
/* Inherited methods */
public void Yaf_Request_Abstract::getActionName
( void
)
public void Yaf_Request_Abstract::getBaseUri
( void
)
public void Yaf_Request_Abstract::getControllerName
( void
)
public void Yaf_Request_Abstract::getEnv
( string
$name
[, string $default
] )
public void Yaf_Request_Abstract::getException
( void
)
public void Yaf_Request_Abstract::getLanguage
( void
)
public void Yaf_Request_Abstract::getMethod
( void
)
public void Yaf_Request_Abstract::getModuleName
( void
)
public void Yaf_Request_Abstract::getParam
( string
$name
[, string $default
] )
public void Yaf_Request_Abstract::getParams
( void
)
public void Yaf_Request_Abstract::getRequestUri
( void
)
public void Yaf_Request_Abstract::getServer
( string
$name
[, string $default
] )
public void Yaf_Request_Abstract::isCli
( void
)
public void Yaf_Request_Abstract::isDispatched
( void
)
public void Yaf_Request_Abstract::isGet
( void
)
public void Yaf_Request_Abstract::isHead
( void
)
public void Yaf_Request_Abstract::isOptions
( void
)
public void Yaf_Request_Abstract::isPost
( void
)
public void Yaf_Request_Abstract::isPut
( void
)
public void Yaf_Request_Abstract::isRouted
( void
)
public void Yaf_Request_Abstract::isXmlHttpRequest
( void
)
public void Yaf_Request_Abstract::setActionName
( string
$action
)
public bool Yaf_Request_Abstract::setBaseUri
( string
$uir
)
public void Yaf_Request_Abstract::setControllerName
( string
$controller
)
public void Yaf_Request_Abstract::setDispatched
( void
)
public void Yaf_Request_Abstract::setModuleName
( string
$module
)
public void Yaf_Request_Abstract::setParam
( string
$name
[, string $value
] )
public void Yaf_Request_Abstract::setRequestUri
( string
$uir
)
public void Yaf_Request_Abstract::setRouted
([ string
}$flag
] )Properties
Predefined Constants
The Yaf_Response_Abstract classIntroduction
Class synopsisYaf_Response_Abstract
class Yaf_Response_Abstract
{
/* Constants */
const
string
Yaf_Response_Abstract::DEFAULT_BODY
= "content"
;
/* Properties */
protected
$_header
;
protected
$_body
;
protected
$_sendheader
;
/* Methods */
public bool appendBody
( string
$content
[, string $key
] )
public bool clearBody
([ string
$key
] )
public void clearHeaders
( void
)
private void __clone
( void
)
public __construct
( void
)
public void __destruct
( void
)
public mixed getBody
([ string
$key
] )
public void getHeader
( void
)
public bool prependBody
( string
$content
[, string $key
] )
public void response
( void
)
protected void setAllHeaders
( void
)
public bool setBody
( string
$content
[, string $key
] )
public void setHeader
( void
)
public void setRedirect
( void
)
private void __toString
( void
)
}Properties
The Yaf_Route_Interface classIntroductionYaf_Route_Interface used for developer defined their custom route. Class synopsisYaf_Route_Interface
class Yaf_Route_Interface
{
/* Methods */
abstract public string assemble
( array
$info
[, array $query
] )
abstract public bool route
( Yaf_Request_Abstract
}$request
)The Yaf_Route_Map classIntroductionYaf_Route_Map is a built-in route, it simply convert a URI endpoint (that part of the URI which comes after the base URI: see Yaf_Request_Abstract::setBaseUri) to a controller name or action name(depends on the paramter passed to Yaf_Route_Map::__construct) in following rule: A => controller A. A/B/C => controller A_B_C. A/B/C/D/E => controller A_B_C_D_E. If the second parameter of Yaf_Route_Map::__construct is specificed, then only the part before delimeter of URI will used to routing, the part after it is used to routing request parameters (see the example section of Yaf_Route_Map::__construct). Class synopsisYaf_Route_Map
class Yaf_Route_Map
implements
Yaf_Route_Interface
{
/* Properties */
protected
$_ctl_router
;
protected
$_delimeter
;
/* Methods */
public string assemble
( array
$info
[, array $query
] )
public __construct
([ string
$controller_prefer = false
[, string $delimiter = ""
]] )
public bool route
( Yaf_Request_Abstract
}$request
)Properties
The Yaf_Route_Regex classIntroductionYaf_Route_Regex is the most flexible route among the Yaf built-in routes. Class synopsisYaf_Route_Regex
class Yaf_Route_Regex
extends
Yaf_Route_Interface
implements
Yaf_Route_Interface
{
/* Properties */
protected
$_route
;
protected
$_default
;
protected
$_maps
;
protected
$_verify
;
/* Methods */
public string assemble
( array
$info
[, array $query
] )
public __construct
( string
$match
, array $route
[, array $map
[, array $verify
[, string $reverse
]]] )
public bool route
( Yaf_Request_Abstract
$request
)/* Inherited methods */
abstract public string Yaf_Route_Interface::assemble
( array
$info
[, array $query
] )
abstract public bool Yaf_Route_Interface::route
( Yaf_Request_Abstract
}$request
)Properties
The Yaf_Route_Rewrite classIntroductionFor usage, please see the example section of Yaf_Route_Rewrite::__construct Class synopsisYaf_Route_Rewrite
class Yaf_Route_Rewrite
extends
Yaf_Route_Interface
implements
Yaf_Route_Interface
{
/* Properties */
protected
$_route
;
protected
$_default
;
protected
$_verify
;
/* Methods */
public string assemble
( array
$info
[, array $query
] )
public __construct
( string
$match
, array $route
[, array $verify
] )
public bool route
( Yaf_Request_Abstract
$request
)/* Inherited methods */
abstract public string Yaf_Route_Interface::assemble
( array
$info
[, array $query
] )
abstract public bool Yaf_Route_Interface::route
( Yaf_Request_Abstract
}$request
)Properties
The Yaf_Router classIntroductionYaf_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. It is designed to work with a single Apache mod_rewrite rule (one of): Example #1 Rewrite rule for Apache RewriteEngine on RewriteRule !\.(js|ico|gif|jpg|png|css|html)$ index.php Example #2 Rewrite rule for Apache RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] Example #3 Rewrite rule for Lighttpd url.rewrite-once = ( ".*\?(.*)$" => "/index.php?$1", ".*\.(js|ico|gif|jpg|png|css|html)$" => "$0", "" => "/index.php" ) Example #4 Rewrite rule for Nginx server { listen ****; server_name yourdomain.com; root document_root; index index.php index.html; if (!-e $request_filename) { rewrite ^/(.*) /index.php/$1 last; } } Default routeYaf_Router comes preconfigured 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.
Some examples of how such routes are matched: Example #5 Yaf_Route_Static(default route)example // Assuming the following configure: $conf = array( "application" => array( "modules" => "Index,Blog", ), ); Controller only: http://example/news controller == news Action only(when defined yaf.action_prefer=1 in php.ini) action == news Invalid module maps to controller name: http://example/foo controller == foo Module + controller: http://example/blog/archive module == blog controller == archive Module + controller + action: http://example/blog/archive/list module == blog controller == archive action == list Module + controller + action + params: http://example/blog/archive/list/sort/alpha/date/desc module == blog controller == archive action == list sort == alpha date == desc Class synopsisYaf_Router
class Yaf_Router
{
/* Properties */
protected
$_routes
;
protected
$_current
;
/* Methods */
public bool addConfig
( Yaf_Config_Abstract
$config
)
public bool addRoute
( string
$name
, Yaf_Route_Abstract $route
)
public __construct
( void
)
public string getCurrentRoute
( void
)
public Yaf_Route_Interface getRoute
( string
$name
)
public mixed getRoutes
( void
)
public bool route
( Yaf_Request_Abstract
}$request
)Properties
The Yaf_Route_Simple classIntroductionYaf_Route_Simple will match the query string, and find the route info. all you need to do is tell Yaf_Route_Simple what key in the $_GET is module, what key is controller, and what key is action.
Yaf_Route_Simple::route will always return
Class synopsisYaf_Route_Simple
class Yaf_Route_Simple
implements
Yaf_Route_Interface
{
/* Properties */
protected
$controller
;
protected
$module
;
protected
$action
;
/* Methods */
public string assemble
( array
$info
[, array $query
] )
public __construct
( string
$module_name
, string $controller_name
, string $action_name
)
public bool route
( Yaf_Request_Abstract
}$request
)Properties
The Yaf_Route_Static classIntroductionDefaultly, Yaf_Router only have a Yaf_Route_Static as its default route. And Yaf_Route_Static is designed to handle the 80% requirement. please *NOTE* that it is unecessary to instance a Yaf_Route_Static, also unecesary 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. Class synopsisYaf_Route_Static
class Yaf_Route_Static
implements
Yaf_Router
{
/* Methods */
public string assemble
( array
$info
[, array $query
] )
public void match
( string
$uri
)
public bool route
( Yaf_Request_Abstract
}$request
)The Yaf_Route_Supervar classIntroduction
Class synopsisYaf_Route_Supervar
class Yaf_Route_Supervar
implements
Yaf_Route_Interface
{
/* Properties */
protected
$_var_name
;
/* Methods */
public string assemble
( array
$info
[, array $query
] )
public __construct
( string
$supervar_name
)
public bool route
( Yaf_Request_Abstract
}$request
)Properties
The Yaf_Session classIntroduction
Class synopsisYaf_Session
class Yaf_Session
implements
Iterator
,
ArrayAccess
,
Countable
{
/* Properties */
protected
static
$_instance
;
protected
$_session
;
protected
$_started
;
/* Methods */
private void __clone
( void
)
private __construct
( void
)
public void count
( void
)
public void current
( void
)
public void del
( string
$name
)
public void __get
( string
$name
)
public static void getInstance
( void
)
public void has
( string
$name
)
public void __isset
( string
$name
)
public void key
( void
)
public void next
( void
)
public void offsetExists
( string
$name
)
public void offsetGet
( string
$name
)
public void offsetSet
( string
$name
, string $value
)
public void offsetUnset
( string
$name
)
public void rewind
( void
)
public void __set
( string
$name
, string $value
)
private void __sleep
( void
)
public void start
( void
)
public void __unset
( string
$name
)
public void valid
( void
)
private void __wakeup
( void
)
}Properties
The Yaf_Exception classIntroduction
Class synopsisYaf_Exception
class Yaf_Exception
extends
Exception
{
/* Inherited properties */
protected
string
$message
;
protected
int
$code
;
protected
string
$file
;
protected
int
$line
;
/* Methods */
public __construct
( void
)
public void getPrevious
( void
)
/* Inherited methods */
final public string Exception::getMessage
( void
)
final public Throwable Exception::getPrevious
( void
)
final public mixed Exception::getCode
( void
)
final public string Exception::getFile
( void
)
final public int Exception::getLine
( void
)
final public array Exception::getTrace
( void
)
final public string Exception::getTraceAsString
( void
)
public string Exception::__toString
( void
)
final private void Exception::__clone
( void
)
}The Yaf_Exception_TypeError classIntroduction
Class synopsisYaf_Exception_TypeError
class Yaf_Exception_TypeError
extends
Yaf_Exception
{
/* Properties */
/* Methods */
/* Inherited methods */
public Yaf_Exception::__construct
( void
)
public void Yaf_Exception::getPrevious
( void
)
}The Yaf_Exception_StartupError classIntroduction
Class synopsisYaf_Exception_StartupError
class Yaf_Exception_StartupError
extends
Yaf_Exception
{
/* Properties */
/* Methods */
/* Inherited methods */
public Yaf_Exception::__construct
( void
)
public void Yaf_Exception::getPrevious
( void
)
}The Yaf_Exception_DispatchFailed classIntroduction
Class synopsisYaf_Exception_DispatchFailed
class Yaf_Exception_DispatchFailed
extends
Yaf_Exception
{
/* Properties */
/* Methods */
/* Inherited methods */
public Yaf_Exception::__construct
( void
)
public void Yaf_Exception::getPrevious
( void
)
}The Yaf_Exception_RouterFailed classIntroduction
Class synopsisYaf_Exception_RouterFailed
class Yaf_Exception_RouterFailed
extends
Yaf_Exception
{
/* Properties */
/* Methods */
/* Inherited methods */
public Yaf_Exception::__construct
( void
)
public void Yaf_Exception::getPrevious
( void
)
}The Yaf_Exception_LoadFailed classIntroduction
Class synopsisYaf_Exception_LoadFailed
class Yaf_Exception_LoadFailed
extends
Yaf_Exception
{
/* Properties */
/* Methods */
/* Inherited methods */
public Yaf_Exception::__construct
( void
)
public void Yaf_Exception::getPrevious
( void
)
}The Yaf_Exception_LoadFailed_Module classIntroduction
Class synopsisYaf_Exception_LoadFailed_Module
class Yaf_Exception_LoadFailed_Module
extends
Yaf_Exception_LoadFailed
{
/* Properties */
/* Methods */
/* Inherited methods */
public Yaf_Exception::__construct
( void
)
public void Yaf_Exception::getPrevious
( void
)
}The Yaf_Exception_LoadFailed_Controller classIntroduction
Class synopsisYaf_Exception_LoadFailed_Controller
class Yaf_Exception_LoadFailed_Controller
extends
Yaf_Exception_LoadFailed
{
/* Properties */
/* Methods */
/* Inherited methods */
public Yaf_Exception::__construct
( void
)
public void Yaf_Exception::getPrevious
( void
)
}The Yaf_Exception_LoadFailed_Action classIntroduction
Class synopsisYaf_Exception_LoadFailed_Action
class Yaf_Exception_LoadFailed_Action
extends
Yaf_Exception_LoadFailed
{
/* Properties */
/* Methods */
/* Inherited methods */
public Yaf_Exception::__construct
( void
)
public void Yaf_Exception::getPrevious
( void
)
}The Yaf_Exception_LoadFailed_View classIntroduction
Class synopsisYaf_Exception_LoadFailed_View
class Yaf_Exception_LoadFailed_View
extends
Yaf_Exception_LoadFailed
{
/* Properties */
/* Methods */
/* Inherited methods */
public Yaf_Exception::__construct
( void
)
public void Yaf_Exception::getPrevious
( void
)
} |