2016-12-07 19 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' 

希望这有助于有点...