资料参考:

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. netaddr 0.7.12

    Pythonic manipulation of IPv4, IPv6, CIDR, EUI and MAC network addresses https://pypi.python.org/pyp ...

  2. HDU5568/BestCoder Round #63 (div.2) B.sequence2 dp+高精度

    sequence2 Problem Description Given an integer array bi with a length of n, please tell me how many ...

  3. openvswitch 修改dpid(datapath id)

    版本: $ sudo ovs-vsctl -Vovs-vsctl (Open vSwitch) 2.0.2Compiled May 13 2015 18:49:53 $ sudo ovs-vsctl ...

  4. c# 委托 和 事件

    当初学C#的时候,没有完全吃透的,只能现在继续了...  欠老账.... http://www.cnblogs.com/chengxingliang/archive/2013/05/21/305191 ...

  5. 基于RPC原理的dubbo

    在校期间大家都写过不少程序,比如写个hello world服务类,然后本地调用下,如下所示.这些程序的特点是服务消费方和服务提供方是本地调用关系. 而一旦踏入公司尤其是大型互联网公司就会发现,公司的系 ...

  6. Shell脚本基础II

    1.shell算术运算 1)加法 r=`expr 4 + 5`(注意! '4' '+' '5' 这三者之间要有空白) r=$[ 4 + 5 ] r=$(( 4 + 5 )) echo $r 2)乘法 ...

  7. LinuxMint使用中文输入法

    自从转战linux系统以来,最痛苦的事情就是没有一款能让我满意的中文输入法了 不过今天我终于发现了一个让我比较满意的输入法(小小输入法),真的很不错 我试过不少输入法,但是还是小小输入法最适合我: 搜 ...

  8. Linux之守护进程

    一.守护进程概述 在linux或者unix操作系统中在系统的引导的时候会开启很多服务,这些服务就叫做守护进 程.为了增加灵活性,root可以选择系统开启的模式,这些模式叫做运行级别,每一种运行级别以一 ...

  9. Json工具类 - JsonUtils.java

    Json工具类,提供Json与对象之间的转换. 源码如下:(点击下载 - JsonUtils.java . gson-2.2.4.jar ) import java.lang.reflect.Type ...

  10. 第十一篇 Material Status设置与测试,制药业案例一则

    详见,http://bbs.erp100.com/thread-273173-1-1.htmlMaterial Status不同于Item Status.Item Status用于统一控制Item的s ...