我最近将我的Symony应用程序从3.3版升级到3.4版 .

在我的遗留代码中,我有一个完全覆盖的SwitchUserListener类(用于模拟) . 运行cache clear命令时,抛出了以下异常 .

[Symfony\Component\DependencyInjection\Exception\OutOfBoundsException] 
Service "security.authentication.switchuser_listener.main": The index "9" is not in the range [0, 8].

这是因为一些DI逻辑和一个新参数已被添加到3.4中的基本SwitchUserListener的构造函数中,从而破坏了BC . (文件:https://github.com/symfony/security-http/blob/3.4/Firewall/SwitchUserListener.php#L54,提交:https://github.com/symfony/security-http/commit/f1720c6dd0844450cd134e2a5fc8319f492d56f1#diff-3eea7218d9978bdd41e254e67047ca92

你怎么处理这个BC休息的情况?因为基础SwitchUserListener类中的所有内容都是私有的,所以我没有其他想法,只能创建自己的类而不是覆盖默认类 .

现在,我将更新我的课程,但我想知道将来如何避免类似的情况 . 有任何想法吗?

这是我 class 的一个例子:

class SwitchUserListener implements ListenerInterface
{
    private $tokenStorage;
    private $provider;
    private $userChecker;
    private $providerKey;
    private $accessDecisionManager;
    private $resourceMapper;
    private $usernameParameter;
    private $role;
    private $apiScheme;

    /**
     * @var ClientManager
     */
    private $clientManager;

    public function __construct(
        TokenStorageInterface $tokenStorage,
        UserProviderInterface $provider,
        UserCheckerInterface $userChecker,
        $providerKey,
        AccessDecisionManagerInterface $accessDecisionManager,
        ResourceMapper $resourceMapper,
        $usernameParameter = '_switch_user',
        $role = 'ROLE_ALLOWED_TO_SWITCH',
        $apiScheme = 'http'
    ) {
        if (empty($providerKey)) {
            throw new \InvalidArgumentException('$providerKey must not be empty.');
        }

        $this->tokenStorage = $tokenStorage;
        $this->provider = $provider;
        $this->userChecker = $userChecker;
        $this->providerKey = $providerKey;
        $this->accessDecisionManager = $accessDecisionManager;
        $this->resourceMapper = $resourceMapper;
        $this->usernameParameter = $usernameParameter;
        $this->role = $role;
        $this->apiScheme = $apiScheme;
    }

    public function setClientManager(ClientManager $clientManager)
    {
        $this->clientManager = $clientManager;
    }

/** My own logic here, using private attributes **/
}

谢谢 .

编辑:

这是使BC破裂的路线 . https://github.com/symfony/symfony/blob/3.4/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php#L723