2012-07-29 69 views
0

我有以下YAML定義Symfony的DI 2.1抽象/父定義

services: 
    App_Model_Base: 
    class: App_Model_Base 
    abstract: true 
    calls: 
     - [setBaseValue, ['base']] 
    App_Model_A: 
    class: App_Model_A 
    parent: App_Model_Base 

但是通過symfony中產生的容器類具有以下定義

/** 
* Gets the 'app_model_a' service. 
* 
* This service is shared. 
* This method always returns the same instance of the service. 
* 
* @return App_Model_A A App_Model_A instance. 
*/ 
protected function getAppModelAService() 
{ 
    return $this->services['app_model_a'] = new \App_Model_A(); 
} 

/** 
* Gets the 'app_model_base' service. 
* 
* This service is shared. 
* This method always returns the same instance of the service. 
* 
* @return App_Model_Base A App_Model_Base instance. 
*/ 
protected function getAppModelBaseService() 
{ 
    $this->services['app_model_base'] = $instance = new \App_Model_Base(); 

    $instance->setBaseValue('base'); 

    return $instance; 
} 

App_Model_Base是抽象類和App_Model_A延伸App_Model_Base。根據這Managing Common Dependencies with Parent Services這應該工作得很好,但它沒有。如果我得到App_Model_A,該$baseValue是空在那裏我希望它是「基地」

+0

另一個討論會在這裏http://forum.symfony-project.org/ viewtopic.php?f = 23&t = 44343&p = 137256#p137256 – Optimus 2012-08-01 07:22:53

回答