Zend_Application 流程详解
本周没什么工作,zend 系统性的东西渐渐忘记,抽时间整理一下代码!Zend_Application 负责加载配置以及初始化资源,所以index.php 会有这行代码
/** Zend_Application */
require_once 'Zend/Application.php'; // Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
); $application->bootstrap()
->run();
Zend_application 如何初始化流程,下面是一个类图
上面大致画了一下Zend_Application 的类图的关系,Zend_Application 与 bootStrap 是聚合的关系,爱的死去活来,爱的只要你无怨,他也无悔。zend_Application 的主要工作就是加载配置文件application.ini 以及命名空间。其他的工作会代理给bootstrap类处理。
bootstrap主要负责加载两类资源,分别对应最上面的两个接口。
1.Zend_Application_Bootstrap_Bootstrapper 是 bootstrap 类的接口,Zend_Application_Bootstrap_BootstrapAbstract 实现Zend_Application_Bootstrap_Bootstrapper 的getClassResources 方法的代码
if (null === $this->_classResources) {
if (version_compare(PHP_VERSION, '5.2.6') === -1) {
$class = new ReflectionObject($this);
$classMethods = $class->getMethods();
$methodNames = array();
foreach ($classMethods as $method) {
$methodNames[] = $method->getName();
}
} else {
$methodNames = get_class_methods($this);
}
$this->_classResources = array();
foreach ($methodNames as $method) {
if (5 < strlen($method) && '_init' === substr($method, 0, 5)) {
$this->_classResources[strtolower(substr($method, 5))] = $method;
}
}
}
所谓的classResource 就是在bootstrap 以_init 开头定义的方法 比如
1.class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
2.{
3. protected function _initView()
4. {
5. // Initialize view
6. $view = new Zend_View();
7. $view->doctype('XHTML1_STRICT');
8. $view->headTitle('My First Zend Framework Application');
9.
10. // Add it to the ViewRenderer
11. $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
12. 'ViewRenderer'
13. );
14. $viewRenderer->setView($view);
15.
16. // Return it, so that it can be stored by the bootstrap
17. return $view;
18. }
19.}
2.Zend_Application_Bootstrap_ResourceBootstrapper 定义是加载资源的接口,就是我们在application.ini 以resource开头定义的资源比如
resources.db.adapter ="MYSQLI"
resources.db.params.host ="localhost"
resources.db.params.username ="root"
resources.db.params.password ="123456"
resources.db.params.dbname ="test"
资源的加载流程,通过zend_Application 加载配置,通过Zend_Loader_PluginLoader 进行加载文件,并在Zend_Application_Bootstrap_BootstrapAbstract的 loadPluginResource方法进行初始化资源类。
加载两类资源的入口在Zend_Application_Bootstrap_BootstrapAbstract的 _bootstrap 方法
protected function _bootstrap($resource = null)
{
if (null === $resource) {
foreach ($this->getClassResourceNames() as $resource) {
$this->_executeResource($resource);
} foreach ($this->getPluginResourceNames() as $resource) {
$this->_executeResource($resource);
}
} elseif (is_string($resource)) {
$this->_executeResource($resource);
} elseif (is_array($resource)) {
foreach ($resource as $r) {
$this->_executeResource($r);
}
} else {
throw new Zend_Application_Bootstrap_Exception('Invalid argument passed to ' . __METHOD__);
}
}
分别加载calssResource 和 配置的 resource
注意 : 以上是zend framwork 1 而非 2。
--EOF--
Zend_Application 流程详解的更多相关文章
- C++的性能C#的产能?! - .Net Native 系列《二》:.NET Native开发流程详解
之前一文<c++的性能, c#的产能?!鱼和熊掌可以兼得,.NET NATIVE初窥> 获得很多朋友支持和鼓励,也更让我坚定做这项技术的推广者,希望能让更多的朋友了解这项技术,于是先从官方 ...
- [nRF51822] 5、 霸屏了——详解nRF51 SDK中的GPIOTE(从GPIO电平变化到产生中断事件的流程详解)
:由于在大多数情况下GPIO的状态变化都会触发应用程序执行一些动作.为了方便nRF51官方把该流程封装成了GPIOTE,全称:The GPIO Tasks and Events (GPIOTE) . ...
- 迅为4412开发板Linux驱动教程——总线_设备_驱动注册流程详解
本文转自:http://www.topeetboard.com 视频下载地址: 驱动注册:http://pan.baidu.com/s/1i34HcDB 设备注册:http://pan.baidu.c ...
- Linux启动流程详解【转载】
在BIOS阶段,计算机的行为基本上被写死了,可以做的事情并不多:一般就是通电.BIOS.主引导记录.操作系统这四步.所以我们一般认为加载内核是linux启动流程的第一步. 第一步.加载内核 操作系统接 ...
- iOS 组件化流程详解(git创建流程)
[链接]组件化流程详解(一)https://www.jianshu.com/p/2deca619ff7e
- git概念及工作流程详解
git概念及工作流程详解 既然我们已经把gitlab安装完毕[当然这是非必要条件],我们就可以使用git来管理自己的项目了,前文也多多少少提及到git的基本命令,本文就先简单对比下SVN与git的区别 ...
- Lucene系列六:Lucene搜索详解(Lucene搜索流程详解、搜索核心API详解、基本查询详解、QueryParser详解)
一.搜索流程详解 1. 先看一下Lucene的架构图 由图可知搜索的过程如下: 用户输入搜索的关键字.对关键字进行分词.根据分词结果去索引库里面找到对应的文章id.根据文章id找到对应的文章 2. L ...
- JPEG图像压缩算法流程详解
JPEG图像压缩算法流程详解 JPEG代表Joint Photographic Experts Group(联合图像专家小组).此团队创立于1986年,1992年发布了JPEG的标准而在1994年获得 ...
- unity3d-配置Android环境,打包发布Apk流程详解
31:unity3d-配置Android环境,打包发布Apk流程详解 作者 阿西纳尼 关注 2016.08.28 22:52 字数 498 阅读 1806评论 0喜欢 5 Unity配置Android ...
随机推荐
- 爬取爱奇艺电视剧url
----因为需要顺序,所有就用串行了---- import requests from requests.exceptions import RequestException import re im ...
- 转转转!!Spring MVC控制器用@ResponseBody声明返回json数据报406的问题
本打算今天早点下班,结果下午测试调试程序发现一个问题纠结到晚上才解决,现在写一篇博客来总结下. 是这样的,本人在Spring mvc控制层用到了@ResponseBody标注,以便返回的数据为json ...
- Windows常用内容渗透命令
假设现在已经拥有一台内网[域]机器,取名X-007. 1-1.内网[域]信息收集 A.本机X-007信息收集. [+]------用户列表[Windows用户列表/邮件用户/...] ----> ...
- CentOS 6.7 编译PHP7 make时出现错误:undefined reference to `libiconv_close’
编辑Makefile文件,找到变量EXTRA_LIBS,并在末尾添上-liconv EXTRA_LIBS = -lcrypt -lz -lexslt -lcrypt -lrt -lmcrypt -ll ...
- 372. Super Pow.txt
▶ 指数取模运算 ab % m ▶ 参考维基 https://en.wikipedia.org/wiki/Modular_exponentiation,给了几种计算方法:暴力计算法,保存中间结果法(分 ...
- 关于eclipse open call hierarchy功能的一个细节
这个功能对应的快捷键是ctrl alt H,大家应该都很熟悉了.默认是查找这个方法的被调用堆栈.90%的人应该也是习惯这个默认的功能的,也基本无视它的另一个功能. 昨天重启eclipe之后,我的ecl ...
- Python 测试题目-1
l1 = [11,22,33]l2 = [22,33,44] # 1.获取内容相同的两个元素# 2.获取l1中有l2没有的元素# 3.获取l2中有l1中没有的元素# 4.获取l1 l2中内容都不通的元 ...
- FireMoneky 画图 Point 赋值
VCL 的 Canvas.Pen 对应FMX: Canvas.Stroke;VCL到 Canvas.Brush 对应FMX: Canvas.Fill. TCircle 圆形控件 Inkscape 0. ...
- Windows下python3安装pip管理包(转贴)
方法有两种: 请参考:http://www.pip-installer.org/en/latest/installing.html#prerequisites 1.通过setuptools安装 安装s ...
- asp.net 初级程序员面试题【待续】
C# 常见的排序方式 冒泡排序(Bubble sort) 堆排序(Heap sort) 插入排序(Insertion sort) 归并排序(Merge sort) 快速排序(Quick sort) ...