我在我的项目中使用 Symfony Service Configurator 在实例化(Docs)后配置服务,在 Configure 方法中我需要当前用户登录,所以我注入容器并尝试获取令牌表单 Security.context 服务但我得到了始终为 NULL。我还尝试在我的 Configurator 构造中只注入 Security.context 但我得到了相同的结果。
任何想法请
谢谢。
类 MyConfigurator
{
私人$容器;
公共函数 __construct(ContainerInterface $container)
{
$this->container = $container;
}
公共功能配置()
{
$user = $this->container->get('security.context')->getToken();
var_dump($user); // = 空
}
}