2012-08-31 94 views
7

在Zend Framework中,Zend_Application對象具有引導程序對象以引導或配置組件.Bootstrap類又可以訪問zend_application對象來訪問配置參數。
我的問題是,這是什麼樣的模式,或者它是一個代碼氣味,因爲循環依賴。具有彼此知識的對象

回答

2

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); 
} 

的自舉文件需要的選項,所以不是asking for the options,它預計Zend_Application來再拿到選項:

$options = $application->getOptions(); 
$this->setOptions($options); 

好像他們簡單地忽略接口的由setApplication()方法期望的類型,它可以是以下之一:

  • Zend_Application
  • Zend_Application_Bootstrap_Bootstrapper
  • Zend_Application_Bootstrap_ResourceBootstrapper

我會放棄試圖理解這個混亂,並切換到ZF 2,雖然;)

+0

我不會這麼急,尤其是要知道ZF2與ZF1相比的表現如何(臃腫與否)。 –

+0

@ WebnetMobile.com這個想法是,研究ZF2源代碼比ZF1更好。由於OP沒有提到任何錯誤,只想知道是否有代碼味道。答案是:**是** –