-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUserRepository.php
46 lines (37 loc) · 1.13 KB
/
UserRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace App\Repository;
use App\Entity\User;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
/**
* @author Martin PAUCOT <contact@martin-paucot.fr>
*/
class UserRepository extends EntityRepository
{
/**
* Create a new user.
*
* @param string $firstname
* @param string $lastname
* @param string $email
* @param string $password
* @param UserPasswordEncoderInterface $passwordEncoder
*
* @return User
*
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function createUser(string $firstname, string $lastname, string $email, string $password, UserPasswordEncoderInterface $passwordEncoder): User {
$user = new User();
$user->setFirstname($firstname);
$user->setLastname($lastname);
$user->setEmail($email);
$user->setPassword(
$passwordEncoder->encodePassword($user, $password)
);
$this->getEntityManager()->persist($user);
$this->getEntityManager()->flush();
return $user;
}
}