F
F. Tomas
Пилю маленький проект на новой Symfony 6.1 Подключил фикстуры и появилась необходимость захешировать пароль. Покопался в доках, нашёл PasswordHasherInterface
Но получаю ошибку:
Мой файл services.yaml:
Как захешировать пароль в Symfony 6.1?
Code:
<?php
namespace App\DataFixtures;
use App\Model\User\Entity\User\Email;
use App\Model\User\Entity\User\Id;
use App\Model\User\Entity\User\Role;
use App\Model\User\Entity\User\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
class UserFixture extends Fixture
{
private PasswordHasherInterface $hasher;
public function __construct(PasswordHasherInterface $hasher)
{
$this->hasher = $hasher;
}
public function load(ObjectManager $manager): void
{
$hash = $this->hasher->hash("password");
$user = User::signUpByEmail(
Id::next(),
new \DateTimeImmutable(),
new Email("[email protected]"),
$hash,
"token"
);
$user->confirmSignUp();
$user->changeRole(Role::admin());
$manager->persist($user);
$manager->flush();
}
}
Но получаю ошибку:
Code:
In DefinitionErrorExceptionPass.php line 54:
!!
!! Cannot autowire service "App\DataFixtures\UserFixture": argument "$hasher"
!! of method "__construct()" references interface "Symfony\Component\PasswordH
!! asher\PasswordHasherInterface" but no such service exists. Did you create a
!! class that implements this interface?
!!
Мой файл services.yaml:
Code:
parameters:
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.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Model/User/Entity/'
- '../src/Kernel.php'
Как захешировать пароль в Symfony 6.1?