Yaf_Dispatcher

简介

dispatcher在router之后,负责调用控制器,返回响应数据

Yaf_Dispatcher对象

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 );
}

1. 模板类

1.1 disableView,关闭自动加载模板(默认开启),开启状态,每个action结束会根据action名加载模板文件
Yaf_Dispatcher::getInstance()->disableView();
1.2 enableView,开启自动加载模板(默认开启)
Yaf_Dispatcher::getInstance()->disableView();
1.3 autoRender,disableView与enableView合体版
Yaf_Dispatcher::getInstance()->autoRender(TRUE);//同enableView
Yaf_Dispatcher::getInstance()->autoRender(FALSE);//同disableView
1.4 flushInstantly,是否自动响应,在enableView下开启,会调用Yaf_Controller_Abstract::display方法。直接输出响应给请求端
/* 立即输出响应 */
Yaf_Dispatcher::getInstance()->flushInstantly(TRUE);
/* 此时会调用Yaf_Controller_Abstract::display方法 */
$application->run();
1.5 initView,初始化模板引擎,自定义模板引擎要先setView在initView
1.6 setView,设置模板引擎

2.异常类

2.1 setErrorHandler,自定义错误处理函数,throwException关闭时,产生的错误会调用
Yaf_Dispatcher::getInstance()->setErrorHandler("myErrorHandler");
2.2 throwException,设置yaf出错是否抛出异常
//不抛出异常
Yaf_Dispatcher::getInstance()->throwException(FALSE);
2.3 catchException,是否捕获异常
Yaf_Dispatcher::getInstance()->catchException(TRUE);

3.响应类

3.1 returnResponse,不自动返回response对象。默认自动返回
/* 关闭自动响应, 交给rd自己输出*/
$response =
$application->getDispatcher()->returnResponse(TRUE)->getApplication()->run();

/** 输出响应*/
$response->response();

4.请求类

4.1 getRequest,获取请求实例
Yaf_Dispatcher::getInstance()->getRequest();
4.2 setRequest,设置请求,??不知道用处
$request = new Yaf_Request_Simple("Index", "Index", "index");
Yaf_Dispatcher::getInstance()->setRequest($request);

5.应用类

5.1 getApplication,获取应用实例
$application = Yaf_Dispatcher::getInstance()->getApplication();
//效果同上,明显更短
$application = Application::app();
5.2 setAppDirectory,新版本好像没了

6.其他

6.1 getRouter,获取路由实例
Yaf_Dispatcher::getInstance()->getRouter();
6.2 registerPlugin,注册自定义插件类
Yaf_Dispatcher::getInstance()->registerPlugin(Yaf_Plugin_Abstract $user);
6.3 dispatch,启动分发,Yaf_Application::run时调用
6.4 setDefaultModule
6.5 setDefaultController
6.6 setDefaultAction
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 快速开始 典型的目录结构 入口文件 所有请求的入口, 一般都借助于rewrite规则, 把所有的请求都重定向到这个...
    零一间阅读 9,208评论 0 8
  • 国家电网公司企业标准(Q/GDW)- 面向对象的用电信息数据交换协议 - 报批稿:20170802 前言: 排版 ...
    庭说阅读 14,023评论 6 13
  • Getting Started Burp Suite 是用于攻击web 应用程序的集成平台。它包含了许多工具,并为...
    Eva_chenx阅读 29,118评论 0 14
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,887评论 1 32
  • 16. Web MVC 框架 16.1 Spring Web MVC 框架介绍 Spring Web 模型-视图-...
    此鱼不得水阅读 4,726评论 0 4

友情链接更多精彩内容