如何解决Symfony 4.4 + scheb / 2fa:自定义代码生成器和邮件程序
我正在尝试遵循本文档,但是yaml配置会引发一些错误。 我对Symfony的了解还不足以了解我在做什么错。 https://github.com/scheb/2fa/blob/5.x/doc/providers/email.md
services.yaml:
removerImg(){
console.log('Removiendo..');
let im = document.getElementById('preview').setAttribute('src','../../../../../assets/img/no-image.jpg');
}
scheb_2fa.yaml:
https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
uploads_path: '/uploads/files/'
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands,event subscribers,etc.
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
App\Controller\:
resource: '../src/Controller/'
tags: ['controller.service_arguments']
# App\Service\CodeGeneratorService:
# arguments: ['@markdown.parser','@doctrine_cache.providers.my_markdown_cache']
auth_mailer:
# class: Scheb\TwoFactorBundle\Mailer\SymfonyAuthCodeMailer
class: App\Mailer\MyAuthCodeMailer
code_generator_service:
class: App\Service\CodeGeneratorService
# public: true
arguments:
# $mailer: "%scheb_two_factor.security.email.symfony_auth_code_mailer%"
# $mailer: "%scheb_two_factor.security.email.swift_auth_code_mailer%"
# $mailer: App\Mailer\MyAuthCodeMailer
# $mailer: Scheb\TwoFactorBundle\Mailer\SymfonyAuthCodeMailer
# $mailer: Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface
# $mailer: App\service\CodeGeneratorService
# $mailer: "%scheb_two_factor.email.mailer%"
$digits: "%scheb_two_factor.email.digits%"
App \ Service \ CodeGeneratorService.php:
# See the configuration reference at https://github.com/scheb/2fa/blob/master/doc/configuration.md
scheb_two_factor:
security_tokens:
- Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken
email:
enabled: true
sender_email: quezako35@gmail.com
sender_name: Quezako # Optional
digits: 12
code_generator: code_generator_service # Use alternative service to generate authentication code
mailer: auth_mailer # Use alternative service to send the authentication code
我收到的各种错误消息:
无法自动装配服务“ code_generator_service”:方法“ App \ Service \ CodeGeneratorService :: __ construct()”的参数“ $ mailer”引用接口“ Scheb \ TwoFactorBundle \ Mailer \ AuthCodeMailerInterface”,但不存在此类服务。您也许应该将此接口别名为以下现有服务之一:“ App \ Mailer \ MyAuthCodeMailer”,“ auth_mailer”,“ scheb_two_factor.security.email.swift_auth_code_mailer”,“ scheb_two_factor.security.email.symfony_auth_code_mailer”。
您已请求一个不存在的参数“ scheb_two_factor.email.mailer”。您是说其中之一吗:“ scheb_two_factor.email.sender_name”,“ scheb_two_factor.email.template”,“ scheb_two_factor.email.digits”?
传递给App \ Service \ CodeGeneratorService :: __ construct()的参数2必须实现接口Scheb \ TwoFactorBundle \ Mailer \ AuthCodeMailerInterface,给定的字符串,在D:\ Dev \ meet_the_team \ var \ cache \ dev \ Container0FXY0Rx \ srcApp_KernelDevDebugContainer中调用。 621行上的php
解决方法
作者Christian Scheb给了我答案。
您必须配置服务并使用@批注引用该服务,以告知Symfony使用该服务实例。 https://github.com/scheb/2fa/issues/22
services:
# ...
auth_mailer:
class: App\Mailer\MyAuthCodeMailer
code_generator_service:
class: App\Service\CodeGeneratorService
arguments:
$mailer: "@auth_mailer"
$digits: "%scheb_two_factor.email.digits%"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。