资料参考:

Yaf是一个C语言编写的PHP框架,以php扩展的形式. 是 laruence(鸟哥)  的作品

laruence 是PHP 开发组成员, PECL 开发者. Yaf, Taint等Pecl扩展作者.

Yaf 相关文章 http://www.laruence.com/tag/yaf   在线手册

具体看 官方提供的例子

http://achun.iteye.com/blog/1473126

框架目录参考:

- .htaccess // Rewrite rules
+ public
| - index.php // Application entry
| + css
| + js
| + img
+ conf
| - application.ini // Configure
- application/
- Bootstrap.php // Bootstrap
+ controllers
- Index.php // Default controller
+ views
|+ index
- index.phtml // View template for default controller
- library
- models // Models
- plugins // Plugins

入口文件:

define ("APPLICATION_PATH", dirname(__FILE__) . "/application");
//var_dump(Yaf_Application::app());
$application = new Yaf_Application("conf/sample.ini");
//var_dump(Yaf_Application::app());exit; /* 如果打开flushIstantly, 则视图渲染结果会直接发送给请求端
* 而不会写入Response对象
*/
//$application->getDispatcher()->flushInstantly(TRUE); /* 如果没有关闭自动response(通过Yaf_Dispatcher::getInstance()->returnResponse(TRUE)),
* 则$response会被自动输出, 此处也不需要再次输出Response
*/
$response = $application
//->bootstrap()/*bootstrap是可选的调用*/
->run()/*执行*/;

application类实例化之后:

object(Yaf_Application)[]
protected 'config' =>
object(Yaf_Config_Ini)[]
protected '_config' =>
array (size=)
'yaf' =>
array (size=)
...
'smarty' =>
array (size=)
...
'routes' =>
array (size=)
...
'webroot' => string 'http://www.ap.com' (length=)
protected '_readonly' => boolean true
protected 'dispatcher' =>
object(Yaf_Dispatcher)[]
protected '_router' =>
object(Yaf_Router)[]
protected '_routes' =>
array (size=)
...
protected '_current' => null
protected '_view' => null
protected '_request' =>
object(Yaf_Request_Http)[]
public 'module' => null
public 'controller' => null
public 'action' => null
public 'method' => string 'GET' (length=)
protected 'params' =>
array (size=)
...
protected 'language' => null
protected '_exception' => null
protected '_base_uri' => string '' (length=)
protected 'uri' => string '/' (length=)
protected 'dispatched' => boolean false
protected 'routed' => boolean false
protected '_plugins' =>
array (size=)
empty
protected '_auto_render' => boolean true
protected '_return_response' => boolean false
protected '_instantly_flush' => boolean false
protected '_default_module' => string 'Index' (length=)
protected '_default_controller' => string 'Index' (length=)
protected '_default_action' => string 'index' (length=)
protected '_modules' =>
array (size=)
=> string 'Index' (length=)
protected '_running' => boolean false
protected '_environ' => string 'product' (length=)
protected '_err_no' => int
protected '_err_msg' => string '' (length=)

以上可以看出application里包含的属性主要有dispatch,config,modules,核心是dispatch,他包含了router,request,view,plugs等

以下说明下application的实例化过程:

.判断单例是否存在,self:app()方法返回单例
.通过实例化的第二个参数赋值$_environ
.通过_loadConfig()方法传入实例化的第一个参数,得到config对象,如果$_environ为null,就从php.ini获取配置,默认是product,得到的的config对象会根据这个参数进行筛选配置结果
通过parseOptions方法把配置信息转为数组存入_options变量,
.实例化Yaf_Request_Http对象new Yaf_Request_Http();
得到_requestUri,得到_baseUri,得到method
.获取单例Yaf_Dispatcher::getInstance();
设置默认的action,control,module,这些来字配置
实例化Yaf_Router,默认添加$this->addRoute('_default', new Yaf_Route_Static());
.通过$this->_dispatcher->setRequest($request);把Yaf_Request_Http对象注入Yaf_Dispatcher
.加载load单例,设置全局与项目lib路径,注册autoload方法
.根据throwException配置,注册错误处理方法

执行bootstrap,这个是可选的启动过程,以下是bootstrap的过程:

.根据配置获取bootstrap文件位置,默认在appDirectory下
.执行Yaf_Loader::import($bootstrap)方法,参数为bootstrap文件地址
该方法就是一个include的包装器,相当于include的bootstrap文件
.实例化bootstrap类,通过反射机制执行执行所有init开头的方法,参数为dispatch,这里一般执行初始化配置,添加插件,添加路由,添加模板机制

执行run:

.检查app是否已经在运行
.如果没有运行设置running = true,调用dispatch实例的dispatch方法return $this->_dispatcher->dispatch();

dispatch实例的dispatch方法:

.设置request,通过request类型实例化response对象(http,cli)
.判断请求有没有被路由,如果已经路由过且各路由相关参数为空,设置dispatch请求属性,如果没有设置路由过,执行过程如下
运行所有注册了routerStartup的插件,参数为request,response
执行路由实例的route()方法;参数为request对象
查找所有注册的路由,从后向前匹配,如果匹配成功设置request已被路 由过,此时request参数已经有module,control,action,params参数
各路由相关参数为空,设置dispatch请求属性
运行所有运行了routerShutdown的插件参数为request,response
.实例化view对象,Yaf_View_Simple
.运行所有注册了dispatchLoopStartup的插件,参数为request,response
.从配置forward_limit获取最大分发次数,分发过程如下
如果被分发完成字段为false切没超过最大分发次数,执行如下
运行所有注册了preDispatch的插件,参数为request,response
执行$this->handle($request, $response, $view);
主要是查找control目录的类,执行action方法,或者查查action目录执行action方法,如果结果不是返回的false,可以根据_auto_render,_instantly_flush属性判断是否自动渲染或者自动展现
重设置设置dispatch请求属性
运行所有注册了postDispatch的插件,参数为request,response
如果分发完毕 运行所有注册了dispatchLoopShutdown的插件,参数为request,response
.根据配置返回response对象

上面第5项说的渲染或者展现是通过control类的rander和display方法实现的,预测是加载视图并输出。

实际的代码片段,例如配置路由,插件,获取请求参数,返回数据,以及一些功能扩展,例如数据库连接,缓存等下篇测试。

yaf框架流程一的更多相关文章

  1. Yaf框架下类的自动加载

    前面两篇博客分别讲述了PHP自带的类加载和composer中类的自动加载,其实Yaf框架也实现了基于PSR0和PSR4的类的自动加载.根据我对Yaf下类的自动加载方式的理解写下这篇博客.由于接触Yaf ...

  2. yaf框架学习笔记

    1.yaf框架支持简单的试图引擎,并且支持用户自定义视图引擎,比如smarty. 2.Yaf_Request_Http::getQuery  ,Yaf_Request_Http::getQuery ( ...

  3. 关于yaf 框架的win安装

    http://www.sunqinglin.cn/index.php/archives/329.html PHP windows下yaf框架的安装和配置 2014年10月28日 ⁄ PHP, 编程开发 ...

  4. windows环境下安装yaf框架

    windows环境下安装yaf框架 在windows下安装yaf框架 准备工作: php环境(过程略,wamp,xampp,phpstudy都行,php版本大于5.3) git工具(需要从github ...

  5. 如何在phpstorm中查看yaf框架源码

    1.到github下载yaf框架的doc 下载链接 https://github.com/elad-yosifon/php-yaf-doc/archive/master.zip 2.解压zip包 3. ...

  6. yaf框架安装配置

    YAF中文文档:http://www.laruence.com/manual/index.html 1 YAF框架是用C开发的,属于PHP的扩展框架: 2 YAF的性能相对于源生PHP,性能只降低不到 ...

  7. php的session获取不到问题之ie浏览器(yaf框架)

    最近在内网写代码的时候遇到一个很怪异的问题, 花了好长时间调试,在次记录一下问题和解决方法. 问题描述: 内网开发使用的yaf框架,在火狐,谷歌,创建的session和cookie都能获取的到,但是在 ...

  8. php 安装yaf扩展和yaf框架

    一.安装yaf扩展(windows安装) 1.查看你电脑安装的开发环境(phpinfo()的信息),查找 "Zend Extension Build"和"PHP Exte ...

  9. macOS 安装配置yaf框架 生成yaf项目

    macOS 安装配置yaf框架 Yaf只支持PHP5.2及以上的版本. 并支持最新的PHP5.3.3 Yaf需要SPL的支持. SPL在PHP5中是默认启用的扩展模块 Yaf需要PCRE的支持. PC ...

随机推荐

  1. java 格式化代码 不进行换行

    此处无声胜有声.

  2. iOS开发工具Xcode:Interface Builder

    简介: Interface Builder(IB)是Mac OS X平台下用于设计和测试用户界面(GUI)的应用程序(非开源).为了生成GUI,IB并不是必需的,实际上Mac OS X下所有的用户界面 ...

  3. linq lambda 分组后排序

    1.lamdba分组排序foodBusinessDistrict.                        GroupBy(x => new                        ...

  4. iOS 开发--Objective-C 反射机制

    了解反射机制 Objective-C语言中的OC对象,都继承自NSObject类.这个类为我们提供了一些基础的方法和协议,我们可以直接调用从这个类继承过来方法.当然,本篇文章中讲到的反射方法,就在NS ...

  5. 简单Ajax例子

    一.概述 1.程序执行流程: (1)点击id="testBtn"的按钮,触发validate(); (2)validate()中有调用request.open方法与server交互 ...

  6. apimonitor

    1.简介 由于Andorid更新很快,较之Droidbox这种通过hook系统动态分析APK行为的方法,APIMonitor这种通过在APK包中注入监控代码(监控API调用然后保存为日志)然后重打包A ...

  7. C编译器剖析PDF文档及UCC编译器162.3

    http://blog.csdn.net/sheisc/article/details/42387857 http://blog.csdn.net/sheisc/article/details/455 ...

  8. [软件]XAMPP错误解决

    // 错误1  (在运行安装包时候出现) // 错误2 1. 找到这个文件 这个文件  要将 config.inc.php 中 $cfg['Servers'][$i]['host'] = ’local ...

  9. How to configure Spring facet in IntelliJ IDEA

    遇到了这个问题,稀里糊涂的就给搞定了,在stackoverfolw上看到了相同的问题,直接拷贝下来吧 Spring Configuration Check Unmapped Spring config ...

  10. 299. Bulls and Cows

    题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...