yaf学习

摘要:
<?PHP安装phpize/Configure--使用PHP config=/usr/local/PHP/bin/PHP config路由类finalYaf_Router{protectedarray_routes;protectedstring_current_route;publicYaf_RoadaddRoute(路由协议的字符串$name名称,Yaf_Rroute_I
<?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 );
} 

免责声明:文章转载自《yaf学习》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇CentOS 7安装Samba 4.6 版本步骤及错误解决方法软件需求分析—消息管理下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

java--枚举

前言   java中enum其实也是一种class类型,他和一般的class不同的是    1.全局只有一个实例    2.不能拥有public构造函数    3.无法继承和被继承 枚举案例 public enum HttpCode { SUCCESS(200, "操作成功"),//每定义一个枚举项,就相当通过构造函数HttpCode(int co...

java-response-乱码解决

(1)响应体设置文本 PrintWriter getWriter() 获得字符流,通过字符流的write(String s)方法可以将字符串设置到response 缓冲区中,随后Tomcat会将response缓冲区中的内容组装成Http响应返回给浏览   器端。 关于设置中文的乱码问题 原因:response缓冲区的默认编码是iso8859-1,此码表中...

Java 的设计模式之一装饰者模式

刚开始接触装饰者的设计模式,感觉挺难理解的,不够后来花了一个晚上的时间,终于有头绪了 装饰者设计模式:如果想对已经存在的对象进行装饰,那么就定义一个类,在类中对已经有的对象进行功能的增强或添加另外的行为,这个类就叫装饰者类。被修饰的类叫被装饰者类,是已经存在有的功能。在装饰者类之间又可以互相装饰 特点:          1.装饰类通过构造方法来接收被装饰...

和小猪一起搞微信公众号开发—二维码创建使用流程(需要授权)

使用该接口可以获得多个带不同场景值的二维码,用户扫描后,公众号可以接收到事件推送。 目前有2种类型的二维码,分别是临时二维码和永久二维码,前者有过期时间,最大为1800秒,但能够生成较多数量,后者无过期时间,数量较少(目前参数只支持1--1000)。两种二维码分别适用于帐号绑定、用户来源统计等场景。 用户扫描带场景值二维码时,可能推送以下两种事件: 如果...

转:Delphi中使用比较少的一些语法

http://www.cnblogs.com/Murphieston/p/5577836.html本文是为了加强记忆而写,这里写的大多数内容都是在编程的日常工作中使用频率不高的东西,但是又十分重要。 ---Murphy 1,构造和析构函数: a,构造函数: 一般基于TComponent组件的派生类,都应该使用overload关键字进行继承,Delp...

C# 把字符串(String)格式转换为DateTime类型的三种方法

方式一:Convert.ToDateTime(string) Convert.ToDateTime(string) 注意:string格式有要求,必须是yyyy-MM-dd hh:mm:ss 方式二:Convert.ToDateTime(string, IFormatProvider) 1 DateTimeFormatInfo dtFormat = new...