2016-12-07 63 views
1

我收到錯誤無效參數鍵「articleBuilder」,當我從symfony3啓動一個控制檯命令。無效的參數鍵「nameOfTheArgument」找到symfony3(擴展抽象服務)

我已經擴展了一個抽象服務,並且包含了我已經使用的配置和類代碼。

鑑於我的父類服務的配置:

app.service.user.access_controller: 
     abstract: true 
     class: '%app.service.user.access_controller.class%' 
     arguments: 
      currentUser: "@=service('security.token_storage').getToken().getUser()" 
      userRoleProvider: '@app.repository.user.user_role_repository' 

如果這是父服務類:

<?php 

    namespace AppBundle\Service\User; 


    use AppBundle\Exception\User\AccessControlException; 
    use AppBundle\ModelInterface\User\OwnableInterface; 
    use AppBundle\ModelInterface\User\UserInterface; 
    use AppBundle\ServiceInterface\User\UserRoleProviderInterface; 

    /** 
    * Class AccessController 
    * @package AppBundle\Service\User 
    */ 
    abstract class AccessController 
    { 
     /** @var UserInterface */ 
     protected $currentUser; 

     /** @var UserRoleProviderInterface */ 
     protected $userRoleProvider; 

     /** 
     * AccessControlledService constructor. 
     * @param UserInterface $currentUser 
     * @param UserRoleProviderInterface $userRoleProvider 
     */ 
     public function __construct(UserInterface $currentUser, UserRoleProviderInterface $userRoleProvider) 
     { 
      $this->currentUser = $currentUser; 
      $this->userRoleProvider = $userRoleProvider; 
     } 

在哪裏,這是我的孩子服務定義:

app.controller.article.article_json_api_controller: 
      class: '%app.controller.article.article_json_api_controller.class%' 
      parent: 'app.service.user.access_controller' 
      arguments: 
       articleBuilder: '@app.service.article.doctrine_orm.article_entity.builder' 
       articlePersister: '@app.service.article.doctrine_orm.article_entity.persister' 
       articleProvider: '@app.repository.article.article_repository' 
       articleUpdater: '@app.service.article.updater' 
       articleDestroyer: '@app.service.article.doctrine_orm.article_entity.destroyer' 
       languageProvider: '@app.repository.language.language_repository' 
       sectionBuilder: '@app.service.article.doctrine_orm.article_section_entity.builder' 
       sectionUpdater: '@app.service.article.article_section.updater' 

這是我的孩子服務班:

class ArticleJsonApiController extends AccessController 
{ 
    /** @var UserInterface */ 
    private $currentUser; 

    /** @var ArticleBuilderInterface */ 
    private $articleBuilder; 

    /** @var ArticlePeristerInterface */ 
    private $articlePersister; 

    /** @var ArticleProviderInterface */ 
    private $articleProvider; 

    /** @var ArticleUpdaterInterface */ 
    private $articleUpdater; 

    /** @var ArticleDestroyerInterface */ 
    private $articleDestroyer; 

    /** @var LanguageProviderInterface */ 
    private $languageProvider; 

    /** @var ArticleSectionBuilderInterface */ 
    private $sectionBuilder; 

    /** @var ArticleSectionUpdaterInterface */ 
    private $sectionUpdater; 

    /** 
    * ArticleJsonApiController constructor. 
    * 
    * @param UserInterface $currentUser 
    * @param UserRoleProviderInterface $userRoleProvider 
    * @param ArticleBuilderInterface $articleBuilder 
    * @param ArticlePeristerInterface $articlePersister 
    * @param ArticleProviderInterface $articleProvider 
    * @param ArticleUpdaterInterface $articleUpdater 
    * @param ArticleDestroyerInterface $articleDestroyer 
    * @param LanguageProviderInterface $languageProvider 
    * @param ArticleSectionBuilderInterface $sectionBuilder 
    * @param ArticleSectionUpdaterInterface $sectionUpdater 
    */ 
    public function __construct(
     UserInterface $currentUser, 
     UserRoleProviderInterface $userRoleProvider, 
     ArticleBuilderInterface $articleBuilder, 
     ArticlePeristerInterface $articlePersister, 
     ArticleProviderInterface $articleProvider, 
     ArticleUpdaterInterface $articleUpdater, 
     ArticleDestroyerInterface $articleDestroyer, 
     LanguageProviderInterface $languageProvider, 
     ArticleSectionBuilderInterface $sectionBuilder, 
     ArticleSectionUpdaterInterface $sectionUpdater 
    ) { 
      parent::__construct($currentUser, $userRoleProvider); 

回答

2

我認爲這個問題並不在於articleBuilder本身,而是你打算將參數定義爲關聯數組。

如果我沒有弄錯,在處理parent服務時,您可以使用特殊的index_N鍵來覆蓋已在您的父服務中定義的一些參數的值。爲此,我認爲,你需要確定你的論點的方式,看起來像這樣:

app.controller.article.article_json_api_controller: 
    class: '%app.controller.article.article_json_api_controller.class%' 
    parent: 'app.service.user.access_controller' 
    arguments: 
     - '@app.service.article.doctrine_orm.article_entity.builder' 
     - '@app.service.article.doctrine_orm.article_entity.persister' 
     - '@app.repository.article.article_repository' 
     - '@app.service.article.updater' 
     - '@app.service.article.doctrine_orm.article_entity.destroyer' 
     - '@app.repository.language.language_repository' 
     - '@app.service.article.doctrine_orm.article_section_entity.builder' 
     - '@app.service.article.article_section.updater' 

希望這有助於有點...