国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

無(wú)法自動(dòng)組裝PasswordHasherInterface
P粉154228483
P粉154228483 2023-12-13 15:55:26
0
1
641

我正在嘗試在Fixtures類(lèi)別中自動(dòng)組裝PasswordHasherInterface:

<?php
namespace AppDataFixtures;

use AppModelUserEntityUserEmail;
use AppModelUserEntityUserId;
use AppModelUserEntityUserRole;
use AppModelUserEntityUserUser;
use DoctrineBundleFixturesBundleFixture;
use DoctrinePersistenceObjectManager;
use SymfonyComponentPasswordHasherPasswordHasherInterface;

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("admin@app.test"),
            $hash,
            "token"
        );

        $user->confirmSignUp();

        $user->changeRole(Role::admin());

        $manager->persist($user);
        $manager->flush();
    }
}

但是我得到了錯(cuò)誤:

在 DefinitionErrorExceptionPass.php 第 54 行: ! !

!!無(wú)法自動(dòng)組裝服務(wù)「AppDataFixturesUserFixture」:參數(shù)「$hasher」

# !!方法「__construct()」引用介面「SymfonyComponentPasswordH

# !! asherPasswordHasherInterface”,但不存在此類(lèi)服務(wù)。您是否創(chuàng)建了

# !!實(shí)作這個(gè)介面的類(lèi)別?

! !

我的檔案 services.yaml:

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 中散列純密碼? 為什麼我會(huì)收到此錯(cuò)誤?

P粉154228483
P粉154228483

全部回覆(1)
P粉787820396

沒(méi)有通用的PasswordHasher。

您:

  • 使用工廠產(chǎn)生一個(gè)特定的:例如Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface
  • 或您使用專(zhuān)用的密碼雜湊器類(lèi)別:例如Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface 對(duì)於使用者*。

使用工廠,您的程式碼將如下所示:(未經(jīng)測(cè)試)

//...
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;


class UserFixture extends Fixture
{
    private PasswordHasherFactoryInterface $passwordHasherFactory;

    public function __construct(PasswordHasherFactoryInterface $hasherFactory)
    {
      $this->passwordHasherFactory = $passwordHasherFactory;
    }
    
    public function load(ObjectManager $manager): void
    {
        $passwordHasher = $this->passwordHasherFactory->getPasswordHasher(User::class);
        $hash = $passwordHasher->hash("password");

        $user = User::signUpByEmail(
            Id::next(),
            new \DateTimeImmutable(),
            new Email("admin@app.test"),
            $hash,
            "token"
        );

        $user->confirmSignUp();

        $user->changeRole(Role::admin());

        $manager->persist($user);
        $manager->flush();
    }

重申一下,步驟是:

  1. 安裝軟體套件:composer require symfony/password-hasher
  2. #配置哈希器李>
  3. #載入哈希器
    • 載入UserPasswordHasherInterface
    • 載入PasswordHasherFactoryInterface(請(qǐng)參閱範(fàn)例)並取得PasswordHasher

*:修正程式的 UserPasswordHasherInterface 範(fàn)例位於 此處。

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板