在Zend Framework中,Zend_Application对象有一个要引导或配置的引导对象组件。Bootstrap类又可以访问zend_application对象来访问配置参数
我的问题是,这是一种什么样的模式,还是因为循环依赖而产生的代码气味。
Zend Framework 1是膨胀的,这是肯定的
$_application
属性表示双向关系的原因是由于模块的独立引导文件。
我认为这很奇怪,因为在处理模块时,您将使用主引导程序而不是Zend_Aplication
集:
/**
* Set application/parent bootstrap
*
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
* @return Zend_Application_Bootstrap_BootstrapAbstract
*/
public function setApplication($application)
{
if (($application instanceof Zend_Application)
|| ($application instanceof Zend_Application_Bootstrap_Bootstrapper)
) {
if ($application === $this) {
throw new Zend_Application_Bootstrap_Exception('Cannot set application to same object; creates recursion');
}
$this->_application = $application;
} else {
throw new Zend_Application_Bootstrap_Exception('Invalid application provided to bootstrap constructor (received "' . get_class($application) . '" instance)');
}
return $this;
}
还有很多代码气味:
/**
* Constructor
*
* Sets application object, initializes options, and prepares list of
* initializer methods.
*
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
* @return void
* @throws Zend_Application_Bootstrap_Exception When invalid application is provided
*/
public function __construct($application)
{
$this->setApplication($application);
$options = $application->getOptions();
$this->setOptions($options);
}
boostrap文件需要选项,因此它不需要询问选项,而是希望Zend_Application随后获得选项:
$options = $application->getOptions();
$this->setOptions($options);
他们似乎只是忽略了setApplication()方法所期望的接口类型,它可以是以下类型之一:
- Zend_Application
- Zend_Application_Bootstrap_Bootstrapper
- Zend_Application_Bootstrap_SourceBootstrapper
不过,我会放弃尝试理解这种混乱,转而使用ZF 2;)