我最近将 Symony 应用程序从 3.3 版升级到了 3.4 版。
在我的遗留代码中,我有一个完全覆盖的 SwitchUserListener 类(用于模拟)。运行缓存清除命令时,抛出了以下异常。
[Symfony\Component\DependencyInjection\Exception\OutOfBoundsException]
Service "security.authentication.switchuser_listener.main": The index "9" is not in the range [0, 8].
这是因为在 3.4 的基础 SwitchUserListener 的构造函数中添加了一些 DI 逻辑和一个新参数,从而破坏了 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 **/
}
谢谢。
编辑 :