BC Break Symfony 3.3到3.4?

时间:2018-02-15 15:17:01

标签: symfony symfony-3.3 symfony-3.4

我最近将我的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 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

0 个答案:

没有答案