无法自动装配PasswordHasherInterface
P粉154228483
P粉154228483 2023-12-13 15:55:26
[PHP讨论组]

我正在尝试在Fixtures类中自动装配PasswordHasherInterface:

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();
    }
}

但是我得到了错误:

在 DefinitionErrorExceptionPass.php 第 54 行: !!

!!无法自动装配服务“AppDataFixturesUserFixture”:参数“$hasher”

!!方法“__construct()”引用接口“SymfonyComponentPasswordH

!! asherPasswordHasherInterface”,但不存在此类服务。您是否创建了

!!实现这个接口的类?

!!

我的文件 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 中散列纯密码? 为什么我会收到此错误?

P粉154228483
P粉154228483

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号