2021-03-24 12:27:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Core\Factory;
|
|
|
|
|
|
|
|
use App\Entity\User;
|
|
|
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
|
|
|
use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class UserFactory.
|
|
|
|
*
|
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
|
|
*/
|
2021-05-12 10:17:39 +02:00
|
|
|
class UserFactory implements FactoryInterface
|
2021-03-24 12:27:07 +01:00
|
|
|
{
|
|
|
|
protected TokenGeneratorInterface $tokenGenerator;
|
|
|
|
protected UserPasswordEncoderInterface $encoder;
|
|
|
|
|
2022-02-28 09:35:54 +01:00
|
|
|
public function __construct(UserPasswordEncoderInterface $encoder)
|
2021-03-24 12:27:07 +01:00
|
|
|
{
|
|
|
|
$this->encoder = $encoder;
|
|
|
|
}
|
|
|
|
|
2021-04-30 09:36:48 +02:00
|
|
|
public function create(?string $email = null, ?string $password = null): User
|
2021-03-24 12:27:07 +01:00
|
|
|
{
|
|
|
|
$entity = new User();
|
|
|
|
|
2022-02-28 09:35:54 +01:00
|
|
|
if (null !== $email) {
|
2021-04-30 09:36:48 +02:00
|
|
|
$entity->setEmail($email);
|
|
|
|
}
|
|
|
|
|
2022-03-06 22:08:42 +01:00
|
|
|
if (null !== $password) {
|
2022-02-28 09:35:54 +01:00
|
|
|
$entity->setPassword($this->encoder->encodePassword($entity, $password));
|
|
|
|
}
|
2021-03-24 12:27:07 +01:00
|
|
|
|
|
|
|
return $entity;
|
|
|
|
}
|
|
|
|
}
|