Call UserPasswordEncoderInterface encodePassword in DoctrineMigrations

I am trying to encode a password with the encodePassword function from SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface; inside my migration here is my code
I tried with implements UserPasswordEncoderInterface but i did not manage to use this method encodePassword

The error is

Call to a member function encodePassword() on null

<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;
use DoctrineDBALSchemaSchema;
use DoctrineMigrationsAbstractMigration;
use RamseyUuidUuid;
use AppEntityUser;


/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20201112164728 extends AbstractMigration
{
    /**
     * @var UserPasswordEncoderInterface
     */
    private $encoder;


    public function getPassword($password)
    {
        $user = new User();
        return $this->encoder->encodePassword($user,$password);
    }


    public function getDescription(): string
    {
        return '';
    }


    public function up(Schema $schema): void
    {
       
    }

    public function postUp(Schema $schema): void
    {
        $this->connection->insert('users', [
            'id'         => Uuid::uuid4(),
            'email'      => '[email protected]',
            'password'   => $this->getPassword('foo'),
   
        ]);
    }

    public function down(Schema $schema): void
    {


    }

}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *