Я пытаюсь следовать этой документации, но конфигурация yaml выдает некоторые ошибки. Я недостаточно знаю Symfony, чтобы понять, что я делаю не так. https://github.com/scheb/2fa/blob/5.x/doc/providers/email.md
services.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%"
scheb_2fa.yaml:
# 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: [email protected]
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
Приложение \ Сервис \ CodeGeneratorService.php:
<?php
declare(strict_types=1);
namespace App\Service;
use Scheb\TwoFactorBundle\Model\PersisterInterface;
use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface;
use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Email\Generator\CodeGeneratorInterface;
class CodeGeneratorService implements CodeGeneratorInterface
{
/**
* @var PersisterInterface
*/
private $persister;
/**
* @var AuthCodeMailerInterface
*/
private $mailer;
/**
* @var int
*/
private $digits;
public function __construct(PersisterInterface $persister, AuthCodeMailerInterface $mailer, int $digits)
{
$this->persister = $persister;
$this->mailer = $mailer;
$this->digits = $digits;
}
public function generateAndSend(TwoFactorInterface $user): void
{
$min = 10 ** ($this->digits - 1);
$max = 10 ** $this->digits - 1;
$code = $this->generateCode($min, $max);
$user->setEmailAuthCode((string) $code);
$this->persister->persist($user);
$this->mailer->sendAuthCode($user);
}
public function reSend(TwoFactorInterface $user): void
{
$this->mailer->sendAuthCode($user);
}
protected function generateCode(int $min, int $max): string
{
return substr(md5(rand()), $min, $max);
}
}
Я получаю различные сообщения об ошибках:
Не удается выполнить автоматическое подключение службы code_generator_service: аргумент $ mailer метода App \ Service \ CodeGeneratorService :: __ construct () ссылается на интерфейс 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?
Аргумент 2, переданный в App \ Service \ CodeGeneratorService :: __ construct (), должен реализовывать интерфейс Scheb \ TwoFactorBundle \ Mailer \ AuthCodeMailerInterface, заданная строка, вызываемая в D: \ Dev \ meet_team \ var \ cache \ dev \ Container0FXY0Rx \ srcApp_Kerptainer line. 621