当我从symfony3启动控制台命令时,我收到错误无效参数键“articleBuilder”。
我已经扩展了一个抽象服务,并且我包含了我使用过的配置和类代码。
作为我父类服务的配置:
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);
答案 0 :(得分:2)
我认为问题不在于-> (apply convert (getData "num.txt"))
本身,而在于您打算将参数定义为关联数组。
如果我没有弄错,在处理articleBuilder
服务时,您可以使用一个特殊的parent
密钥,该密钥用于覆盖已在父服务中定义的某个参数的值。因此,我认为,你需要以这样的方式定义你的论点:
index_N
希望这有点帮助...
答案 1 :(得分:1)
我认为您误解了parent
服务是什么。 AFAIK您试图将父抽象类1对1映射为抽象服务,但在Symfony中使用不同的父服务,即管理多个类的公共依赖项。
参考:How to Manage Common Dependencies with Parent Services - Symfony docs