这是我的代码示例
/**
* @Route("/two/factor", name="google-authenticator")
*/
public function twoFactorAction(Request $request)
{
$user = $this->getUser();
$secret = $this->container->get("scheb_two_factor.security.google_authenticator")->generateSecret();
$user->setGoogleAuthenticatorSecret($secret);
$url = null;
if(!empty($user->getGoogleAuthenticatorSecret())){
$url = $this->container->get("scheb_two_factor.security.google_authenticator")->getUrl($user);
}这是错误
在编译容器时,"scheb_two_factor.security.google_authenticator“服务或别名已被删除或内联。要么将其公开,要么停止直接使用容器,转而使用依赖项注入。
效果很好。但是在从symfony 3.4更新到4.1之后,我得到了这个错误。请让我知道如何才能迅速修复它,尊敬。
发布于 2018-10-27 20:15:23
如前所述,Symfony 4.1允许您将自动配置的服务注入到控制器操作和其他地方。但是,您使用的是scheb/two-factor库的旧版本(2.x),它不定义自动配置的服务。
由于您不能升级到此库的4.x,所以您的选项在某种程度上受到限制。但是,应该可以添加一个编译器传递来根据您的需要修改scheb/two-factor库的配置。
简而言之,编译器Pass应该允许您通过这样的操作将此服务重新定义为公共的:
$container
->getDefinition('scheb_two_factor.security.google_authenticator')
->setPublic(true);您必须参考文档来学习如何实现将编译器传递到应用程序中。
发布于 2018-10-27 19:28:44
您不能再使用from容器,因为访问修饰符。试着用自动装配。
您可以使用此接口GoogleAuthenticatorInterface。
它来自您当前使用的包: Scheb,并具有以下名称空间:
Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;您的方法如下所示:
public function index(GoogleAuthenticatorInterface $twoFactor)
{
// ...
$secret = $twoFactor->generateSecret();
}如果我不清楚的话,我希望这一页能帮助你更多一点。生成秘密
https://stackoverflow.com/questions/53025269
复制相似问题