Tar*_*run 7 php zend-framework
在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;
}
Run Code Online (Sandbox Code Playgroud)
还有很多代码味道:
/**
* 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);
}
Run Code Online (Sandbox Code Playgroud)
boostrap 文件需要选项,因此它不要求 options,而是期望 Zend_Application 获取选项:
$options = $application->getOptions();
$this->setOptions($options);
Run Code Online (Sandbox Code Playgroud)
看起来他们只是忽略了 setApplication() 方法期望的接口类型,它可以是以下之一:
不过,我会放弃尝试理解这种混乱并切换到 ZF 2 ;)
| 归档时间: |
|
| 查看次数: |
149 次 |
| 最近记录: |