<?php 安装 phpize ./configure --with-php-config=/usr/local/php/bin/php-config 路由类 final Yaf_Router { protected array _routes ; protected string _current_route ; public Yaf_Router addRoute ( string $name路由协议的名字 , Yaf_Route_Interface $route ); /* 例如:添加一个路由 class Bootstrap extends Yaf_Bootstrap_Abstract{ public function _initRoute(Yaf_Dispatcher $dispatcher) { $route = new Yaf_Route_Rewrite( "/product/list/:id/", array( "controller" => "product", "action" => "info", ) ); $router->addRoute('dummy', $route); } */ public boolean addConfig ( Yaf_Config_Abstract $routes_config ); /* 例如:给路由器通过配置增加一簇路由协议 class Bootstrap extends Yaf_Bootstrap_Abstract{ public function _initRoute(Yaf_Dispatcher $dispatcher) { $router = Yaf_Dispatcher::getInstance()->getRouter(); $router->addConfig(Yaf_Registry::get("config")->routes); */ public array getRoutes ( void );// 获取当前路由器中的所有路由协议 例 $routes = Yaf_Dispatcher::getInstance()->getRouter()->getRoutes(); public array getRoute ( string $name );//获取当前路由器的路由协议栈中名为$name的协议 public string getCurrentRoute ( void );//在路由结束以后, 获取路由匹配成功, 路由生效的路由协议名 public boolean route ( Yaf_Request_Abstract $request );//Yaf_Dispatcher::dispatch会自动调用本方法 public boolean isModuleName ( string $name );//判断一个Module名, 是否是申明存在的Module } 控制器类 abstract Yaf_Controller_Abstract { protected array actions ; protected Yaf_Request_Abstract _request ; protected Yaf_Response_Abstract _response ; protected Yaf_View_Interface _view ; protected string _script_path ; private void __construct ( void ); public void init ( void ); //默认最开始执行 public string getModuleName ( void ); public Yaf_Request_Abstract getRequest ( void ); public Yaf_Response_Abstract getResponse ( void ); public Yaf_View_Interface getView ( void ); public Yaf_View_Interface initView ( void );//初始化视图引擎,因为Yaf采用延迟实例化视图引擎的策略, 所以只有在使用前调用此方法, 视图引擎才会被实例化 public boolean setViewPath ( string $view_directory ); public string getViewPath ( void ); public Yaf_Response_Abstract render ( string $action_name ,array $tpl_vars = NULL );//渲染视图模板, 得到渲染结果 public boolean display ( string $action_name ,array $tpl_vars = NULL ); public boolean forward ( string $action ,array $invoke_args = NULL ); public boolean forward ( string $controller ,string $action ,array $invoke_args = NULL ); public boolean forward ( string $module ,string $controller ,string $action ,array $invoke_args = NULL ); public boolean redirect ( string $url ); } Yaf_View_Simple extends Yaf_View_Interface { protected array _tpl_vars ; protected string _script_path ; public string render ( string $view_path ,array $tpl_vars = NULL ); //渲染一个视图模板, 得到结果 echo $this->getView()->render($this->_script_path . "/test.phtml"); public boolean display ( string $view_path ,array $tpl_vars = NULL );//渲染一个视图模板, 并直接输出给请求端 public boolean setScriptPath ( string $view_directory );//设置模板的基目录, 默认的Yaf_Dispatcher会设置此目录为APPLICATION_PATH . "/views". public string getScriptPath ( void ); public boolean assign ( string $name ,mixed $value ); //变量分配到了 _tpl_vars属性 public boolean __set ( string $name ,mixed $value = NULL ); public mixed __get ( string $name ); } 请求类 abstract Yaf_Request_Abstract { protected string _method ; protected string _module ; protected string _controller ; protected string _action ; protected array _params ; protected string _language ; protected string _base_uri ; protected string _request_uri ; protected boolean _dispatched ; protected boolean _routed ; public string getModuleName ( void ); public string getControllerName ( void ); public string getActionName ( void ); public boolean setModuleName ( string $name ); public boolean setControllerName ( string $name ); public boolean setActionName ( string $name ); public Exception getException ( void ); public mixed getParams ( void ); public mixed getParam ( string $name ,mixed $dafault = NULL ); public mixed setParam ( string $name ,mixed $value ); public mixed getMethod ( void ); abstract public mixed getLanguage ( void ); abstract public mixed getQuery ( string $name = NULL ); abstract public mixed getPost ( string $name = NULL ); abstract public mixed getEnv ( string $name = NULL ); abstract public mixed getServer ( string $name = NULL ); abstract public mixed getCookie ( string $name = NULL ); abstract public mixed getFiles ( string $name = NULL ); abstract public bool isGet ( void ); abstract public bool isPost ( void ); abstract public bool isHead ( void ); abstract public bool isXmlHttpRequest ( void ); abstract public bool isPut ( void ); abstract public bool isDelete ( void ); abstract public bool isOption ( void ); abstract public bool isCli ( void ); public bool isDispatched ( void ); public bool setDispatched ( void ); public bool isRouted ( void ); public bool setRouted ( void ); } Array ( [0] => getQuery [1] => getRequest [2] => getPost [3] => getCookie [4] => getFiles [5] => get [6] => isXmlHttpRequest [7] => __construct [8] => isGet [9] => isPost [10] => isPut [11] => isHead [12] => isOptions [13] => isCli [14] => getServer [15] => getEnv [16] => setParam [17] => getParam [18] => getParams [19] => getException [20] => getModuleName [21] => getControllerName [22] => getActionName [23] => setModuleName [24] => setControllerName [25] => setActionName [26] => getMethod [27] => getLanguage [28] => setBaseUri [29] => getBaseUri [30] => getRequestUri [31] => setRequestUri [32] => isDispatched [33] => setDispatched [34] => isRouted [35] => setRouted ) Array ( [module] => [controller] => [action] => [method] => ) ///主类/// final Yaf_Application { protected Yaf_Config _config ; protected Yaf_Dispatcher _dispatcher ; protected static Yaf_Application _app ; protected boolean _run = FALSE ; protected string _environ ; protected string _modules ; public void __construct ( mixed $config ,string $section = ap.environ ); public Yaf_Application bootstrap ( void ); public Yaf_Response_Abstract run ( void ); public Yaf_Dispatcher getDispatcher ( void ); public Yaf_Config_Abstract getConfig ( void ); public string environ ( void ); public string geModules ( void ); public static Yaf_Application app ( void ); public mixed execute ( callback $funcion ,mixed $parameter = NULL ,mixed $... = NULL ); } //分发类 final Yaf_Dispatcher { protected static Yaf_Dispatcher _instance ; protected Yaf_Router_Interface _router ; protected Yaf_View_Abstract _view ; protected Yaf_Request_Abstract _request ; protected array _plugins ; protected boolean _render ; protected boolean _return_response = FALSE ; protected boolean _instantly_flush = FALSE ; protected string _default_module ; protected string _default_controller ; protected string _default_action ; public static Yaf_Dispatcher getInstance ( void ); public Yaf_Dispatcher disableView ( void ); public Yaf_Dispatcher enableView ( void ); public boolean autoRender ( bool $flag ); public Yaf_Dispatcher returnResponse ( boolean $flag ); public Yaf_Dispatcher flushInstantly ( boolean $flag ); public Yaf_Dispatcher setErrorHandler ( mixed $callback ,int $error_type = E_ALL | E_STRICT ); public Yaf_Application getApplication ( void ); public Yaf_Request_Abstract getRequest ( void ); public Yaf_Router_Interface getRouter ( void ); public Yaf_Dispatcher registerPlugin ( Yaf_Plugin_Abstract $plugin ); public Boolean setAppDirectory ( string $directory ); public Yaf_Dispatcher setRequest ( Yaf_Request_Abstract $request ); public Yaf_View_Interface initView ( void ); public Yaf_Dispatcher setView ( Yaf_View_Interface $view ); public Yaf_Dispatcher setDefaultModule ( string $default_module_name ); public Yaf_Dispatcher setDefaultController ( string $default_controller_name ); public Yaf_Dispatcher setDefaultAction ( string $default_action_name ); public Yaf_Dispatcher throwException ( boolean $switch = FALSE ); public Yaf_Dispatcher catchException ( boolean $switch = FALSE ); public Yaf_Response_Abstract dispatch ( Yaf_Request_Abstract $request ); } abstract Yaf_Response_Abstract { protected array _body ; protected array _header ; public boolean setBody ( string $body ,string $name = NULL ); 如: $this->getResponse()->setBody("Hello World");要响应的字符串, 一般是一段HTML, 或者是一段JSON(返回给Ajax请求) public boolean prependBody ( string $body ,string $name = NULL ); 往已有的响应body前插入新的内容, public boolean appendBody ( string $body , string $name = NULL );往已有的响应body后附加新的内容 public boolean clearBody ( void ); public string getBody ( void ); 获取已经设置的响应body public boolean response ( void ); public boolean setRedirect ( string $url ); public string __toString ( void ); }