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 ...
随机推荐
- 在Linux中安装Oracle(较详细图解)
原创 http://www.cnblogs.com/nucdy/p/5603998.html 参考视屏:链接: https://pan.baidu.com/s/1kViEZQZ 密码: z7ha ( ...
- Oracle中的一些语句
添加字段的语法:alter table tablename add (column datatype [default value][null/not null],….); 修改字段的语法:alter ...
- MPEG2-TS音视频同步原理
一.引言MPEG2系统用于视音频同步以及系统时钟恢复的时间标签分别在ES,PES和TS这3个层次中. 在TS 层, TS头信息包含了节目时钟参考PCR(Program Clock Reference ...
- nginx 点播mp4方法
1.配置文件 配置文件中rmtp部分: application vod { play html; } 配置文件中http部分: location ~ .mp4$ { root html; mp4; l ...
- C++ 构造函数_拷贝构造函数
拷贝构造函数
- Appium使用ID进行定位
1 使用uiautomatorviewer地获取元素ID 路径:sdk\tools\uiautomatorviewer.bat 2 脚本中增加点击事件 driver.find_element_by ...
- Mongodb第一步资料
学习的时候收集了部分好文章,这个文章主要收集的是下载,安装的基本资料 官方http://docs.mongodb.org/manual/tutorial/install-mongodb-on-wind ...
- Linux知识温习
进程间通信(IPC)介绍 mmap - 用户空间与内核空间 linux 进程地址空间的一步步探究 mmap 还是 shmget ? linux C/C++服务器后台开发面试题总结 Trie树详解及其应 ...
- Python之单元测试框架unittest
创建class继承unittest,每一个测试用例是以test开头的函数,先执行setup,然后用例按照字母的顺序执行,然后执行teardown import unittest class demo( ...
- IntelliJ Idea 常用快捷键列表 (需整理下) https://blog.csdn.net/dc_726/article/details/42784275
[常规] https://blog.csdn.net/dc_726/article/details/42784275https://jingyan.baidu.com/article/59a015e3 ...