自从3.0更新到Symfony 3.4以来,我当前服务出现错误。
我有一个SwitchUserListener,它在其构造中接收了几个对象,但是即使我有Type-Hinted,也无法接收EntityManager。我还为我的服务添加了公钥
我收到一个FatalThrowableError,因为该类使用布尔值而不是EntityManager对象实例化。
错误消息
类型错误:传递给Dbm \ UserBundle \ Security \ SwitchUserListener :: __ construct()的参数10必须是Doctrine \ ORM \ EntityManager的实例,给定布尔值,在C:\ wamp64 \ www \ Portail \ var \ cache中调用第8行上的\ dev \ ContainerWyiblvw \ getSecurity_Authentication_SwitchuserListener_MainService.php
FatalThrowableError行
SwitchUserListener-> __ construct(object(TokenStorage),object(EmailUserProvider),object(UserChecker),'main',object(TraceableAccessDecisionManager),object(Logger),'_ switch_user','ROLE_ALLOWED_TO_SWITCH',object(TraceableEventDispatcher), false ,var \ cache \ dev \ ContainerWyiblvw \ getSecurity_Authentication_SwitchuserListener_MainService.php中的对象(AuthorizationChecker))
这是我现在所拥有的。
services.yml
services:
_defaults:
public: true
autowire: true
autoconfigure: true
security.authentication.switchuser_listener:
class: Dbm\UserBundle\Security\SwitchUserListener
arguments:
- '@security.token_storage'
- ~
- '@security.user_checker'
- ~
- '@security.access.decision_manager'
- '@logger'
- ''
- ''
- '@event_dispatcher'
- '@doctrine.orm.entity_manager'
- '@security.authorization_checker'
tags:
- { name: monolog.logger, channel: security }
SwitchUserListener.php
namespace Dbm\UserBundle\Security;
...
use Doctrine\ORM\EntityManager;
class SwitchUserListener implements ListenerInterface
{
private $tokenStorage;
private $provider;
private $userChecker;
private $providerKey;
private $accessDecisionManager;
private $usernameParameter;
private $role;
private $logger;
private $dispatcher;
private $em;
private $authCheck;
public function __construct(TokenStorageInterface $tokenStorage,
UserProviderInterface $provider,
UserCheckerInterface $userChecker,
$providerKey,
AccessDecisionManagerInterface $accessDecisionManager,
LoggerInterface $logger = null,
$usernameParameter = '_switch_user',
$role = 'ROLE_ALLOWED_TO_SWITCH',
EventDispatcherInterface $dispatcher = null,
EntityManager $em,
AuthorizationChecker $authCheck)
{
...
}
答案 0 :(得分:0)
编辑
最后找到我的错误。我覆盖了来自的switchuser_listener “ Symfony \ Bundle \ SecurityBundle \ Resources \ config \ securityListeners.xml” 使用我自己的服务,我想他们列表中的最后一个args(第10个hehe..heh ...)在我更新之前不存在,迫使我也将其包含在我的services.yml文件中
security_listeners.xml
<service id="security.authentication.switchuser_listener" class="Symfony\Component\Security\Http\Firewall\SwitchUserListener" abstract="true">
<tag name="monolog.logger" channel="security" />
<argument type="service" id="security.token_storage" />
<argument /> <!-- User Provider -->
<argument /> <!-- User Checker -->
<argument /> <!-- Provider Key -->
<argument type="service" id="security.access.decision_manager" />
<argument type="service" id="logger" on-invalid="null" />
<argument>_switch_user</argument>
<argument>ROLE_ALLOWED_TO_SWITCH</argument>
<argument type="service" id="event_dispatcher" on-invalid="null"/>
<argument>false</argument> <!-- Stateless -->
</service>
下面的文本仍然有效,它是该问题的正确答案。 但是原因是在此编辑中。
编辑结束
我可以通过将autowire设置为false来解决这个奇怪的问题,并且还添加了一个额外的参数,其中“ false”为(第10个参数)。
只有这样做,我才能“跳过”该问题。这样做很脏。但这有效。
dependencyInjection发送的参数不正确。 (至少我是这样认为的)
这是一种解决方法,我不会将其标记为已回答,因此,如果有人找到了此问题的实际答案,我会将其标记为正确答案
这是更改
services.yml 我只是在第10个位置添加了一个空的args
services:
_defaults:
public: true
autowire: true
autoconfigure: true
security.authentication.switchuser_listener:
class: Dbm\UserBundle\Security\SwitchUserListener
autowire: false
arguments:
- '@security.token_storage'
- ~
- '@security.user_checker'
- ''
- '@security.access.decision_manager'
- '@logger'
- ''
- ''
- '@event_dispatcher'
- ''
- '@doctrine.orm.entity_manager'
- '@security.authorization_checker'
tags:
- { name: monolog.logger, channel: security }
SwitchUserListener.php 我只是在第10位添加了一个额外的参数
public function __construct(TokenStorageInterface $tokenStorage,
UserProviderInterface $provider,
UserCheckerInterface $userChecker,
$providerKey,
AccessDecisionManagerInterface $accessDecisionManager,
LoggerInterface $logger = null,
$usernameParameter = '_switch_user',
$role = 'ROLE_ALLOWED_TO_SWITCH',
EventDispatcherInterface $dispatcher = null,
$buggyParam, //Not doing anything with this
EntityManagerInterface $em,
AuthorizationChecker $authCheck)
{