Zend框架:关于引导和应用程序类


Zend framework: about bootstrape and application class

有什么区别:

$application = new Zend_Application(...);
$application->bootstrap()->run();
$application = new Zend_Application(...);
$application->run();

为什么我们需要调用 ->bootstrape 然后调用 ->run? 为什么不直接调用应用程序>运行?

来自 Zend Sources class:Zend_Application, file:application.php

public function bootstrap($resource = null)
{
    $this->getBootstrap()->bootstrap($resource);
    return $this;
}
public function run()
{
    $this->getBootstrap()->run();
}

第一个样本

$application = new Zend_Application(...);
$application->bootstrap()->run();

调用Zend_Application_Bootstrap_Bootstrap::bootstrap方法,最终加载所有资源。
然后它调用实际调度请求的Zend_Application_Bootstrap_Bootstrap::run()

第二个样本

$application = new Zend_Application(...);
$application->run();

根据上面的代码跳过第一步,因此它将尝试运行(调度请求)而不实际加载资源。 这就是 Zend 描述引导和资源的方式。