本周没什么工作,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 流程详解的更多相关文章

  1. C++的性能C#的产能?! - .Net Native 系列《二》:.NET Native开发流程详解

    之前一文<c++的性能, c#的产能?!鱼和熊掌可以兼得,.NET NATIVE初窥> 获得很多朋友支持和鼓励,也更让我坚定做这项技术的推广者,希望能让更多的朋友了解这项技术,于是先从官方 ...

  2. [nRF51822] 5、 霸屏了——详解nRF51 SDK中的GPIOTE(从GPIO电平变化到产生中断事件的流程详解)

    :由于在大多数情况下GPIO的状态变化都会触发应用程序执行一些动作.为了方便nRF51官方把该流程封装成了GPIOTE,全称:The GPIO Tasks and Events (GPIOTE) . ...

  3. 迅为4412开发板Linux驱动教程——总线_设备_驱动注册流程详解

    本文转自:http://www.topeetboard.com 视频下载地址: 驱动注册:http://pan.baidu.com/s/1i34HcDB 设备注册:http://pan.baidu.c ...

  4. Linux启动流程详解【转载】

    在BIOS阶段,计算机的行为基本上被写死了,可以做的事情并不多:一般就是通电.BIOS.主引导记录.操作系统这四步.所以我们一般认为加载内核是linux启动流程的第一步. 第一步.加载内核 操作系统接 ...

  5. iOS 组件化流程详解(git创建流程)

    [链接]组件化流程详解(一)https://www.jianshu.com/p/2deca619ff7e

  6. git概念及工作流程详解

    git概念及工作流程详解 既然我们已经把gitlab安装完毕[当然这是非必要条件],我们就可以使用git来管理自己的项目了,前文也多多少少提及到git的基本命令,本文就先简单对比下SVN与git的区别 ...

  7. Lucene系列六:Lucene搜索详解(Lucene搜索流程详解、搜索核心API详解、基本查询详解、QueryParser详解)

    一.搜索流程详解 1. 先看一下Lucene的架构图 由图可知搜索的过程如下: 用户输入搜索的关键字.对关键字进行分词.根据分词结果去索引库里面找到对应的文章id.根据文章id找到对应的文章 2. L ...

  8. JPEG图像压缩算法流程详解

    JPEG图像压缩算法流程详解 JPEG代表Joint Photographic Experts Group(联合图像专家小组).此团队创立于1986年,1992年发布了JPEG的标准而在1994年获得 ...

  9. unity3d-配置Android环境,打包发布Apk流程详解

    31:unity3d-配置Android环境,打包发布Apk流程详解 作者 阿西纳尼 关注 2016.08.28 22:52 字数 498 阅读 1806评论 0喜欢 5 Unity配置Android ...

随机推荐

  1. 代码规范 for node.js with 'npm-coding-style'

    npm-coding-style npm's "funny" coding style Description npm's coding style is a bit unconv ...

  2. node使用JsonWebToken 生成token,完成用户登录、登录检测

    最近在用node做后台的登录,检测登录功能.在本地使用session可以成功,但是放服务器后发现session失效了,每次请求session都会变化,着了很久原因.原来,自己项目是前后端分离的,前端调 ...

  3. Java 字符串拼接 StringBuilder() StringBuffer

            字符串拼接 普通方式 public class StringDemo2 { public static void main(String[] args) { // 表示获取从1970- ...

  4. [转]Java IDE 之 IntelliJ IDEA 2017

    参考链接1:http://blog.csdn.net/u012364631/article/details/47682011 IDEA Community(社区版) 使用Maven创建Web工程 并部 ...

  5. 阿里云VPS(win系统)装ROS教程

    以下方法是VPS下的WIN系统下安装ROS的方法,LINUX暂时没有 VPS系统装2003或2008 ,建议2008 启动快,安全,但以下内容是在2003上测试的, 2003系统,2003设置开机自动 ...

  6. Android图片高斯模糊的一些方法

    高斯模糊 高斯模糊就是将指定像素变换为其与周边像素加权平均后的值,权重就是高斯分布函数计算出来的值. 一种实现 点击打开链接<-这里是一片关于高斯模糊算法的介绍,我们需要首先根据高斯分布函数计算 ...

  7. servlet笔记1

    Myeclipse关于Servlet项目文件的组织方面,如下: WEB-INF:这个目录名称和位置是固定的,放置在该目录下的文件或目录,对外界来说的封闭的,也就是客户端无法用http的任何方式访问到其 ...

  8. 14 并发编程-(协程)-greenlet模块&gevent模块

    1.实现多个任务之间进行切换,yield.greenlet都没有实现检测I/O,greenlet在实现多任务切换下更简单 from greenlet import greenlet def eat(n ...

  9. ArrayList原理(一)

    需要使用到动态数组的时候用的最多的就是ArrayList了,底层其实是Object数组,以下demo基于JDK1.8: List<Integer> list  = new ArrayLis ...

  10. ansible debug

    <demoredis_redis_1> ESTABLISH DOCKER CONNECTION FOR USER: ?<demoredis_redis_1> EXEC ['/u ...