资料参考:

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. C# JSON字符串序列化与反序列化

    JSON与c#对象转换http://hi.baidu.com/donick/item/4d741338870c91fe97f88d33 C# JSON字符串序列化与反序列化 – http://www. ...

  2. hdu 4027 Can you answer these queries? 线段树

    线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...

  3. Linux多线程之同步3

    需求 客户端将需要解决的task发送给服务器,服务器调用线程来解决客户端发送的task,解决完由线程负责将其发送回客户端.(用管道实现通信) 思路 1. server维护两个列表.一是客户端列表.二是 ...

  4. MFC中错误知识总结(一)

    1.在继承与派生中,单目:表示派生,双目::表示继承,例如 class A { public: void c(); }; class B: public A {}; //类B继承类A void A:: ...

  5. eclipse下python的selenium自动化环境的搭建

    前提:安装python,我用的2.7.8版本,并在环境变量path里设置;E:\Python1.解压setuptools(Python包管理工具),cmd到目录执行python setup.py in ...

  6. 指定IE浏览器渲染方式

    <meta http-equiv="X-UA-Compatible" content="IE=7" />以上代码告诉IE浏览器,无论是否用DTD声明 ...

  7. Data Flow ->> Import Column & Export Column

    这两个transformation的作用是把DT_TEXT, DT_NTEXT, DT_IMAGE类型的数据在文件系统和数据库间导出或者导入.比如把某个数据库表的image类型的字段导出到文件系统成为 ...

  8. Web Server 使用WebClient 发送https请求 The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

    使用WebClient 发送https请求 使用WebClient发送请求时,并且是以https协议: WebClient webClient = new WebClient(); string re ...

  9. JUnit + Spring + Hibernate 集成测试,无法通过的问题

    使用JUnit测试DAO层.由于不能破坏数据现场,故所有的测试类都继承了Spring测试框架下的 org.springframework.test.AbstractTransactionalDataS ...

  10. git提交代码步骤

    01:首先git status一下查看当前目录下修改的文件,当然编译生成的文件也在其中,我们只看自己修改的: 02:git add ****** //(文件名) 将上述查找到自己修改的文件添加到git ...