| @@ 9-34 (lines=26) @@ | ||
| 6 | use SumoCoders\FrameworkMultiUserBundle\User\BaseUserRepositoryCollection; |
|
| 7 | use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; |
|
| 8 | ||
| 9 | final class CreateUserHandler extends AbstractUserHandler |
|
| 10 | { |
|
| 11 | /** @var BaseUserRepositoryCollection */ |
|
| 12 | private $userRepositoryCollection; |
|
| 13 | ||
| 14 | /** @var EncoderFactoryInterface */ |
|
| 15 | private $encoderFactory; |
|
| 16 | ||
| 17 | public function __construct( |
|
| 18 | EncoderFactoryInterface $encoderFactory, |
|
| 19 | BaseUserRepositoryCollection $userRepositoryCollection |
|
| 20 | ) { |
|
| 21 | $this->userRepositoryCollection = $userRepositoryCollection; |
|
| 22 | $this->encoderFactory = $encoderFactory; |
|
| 23 | } |
|
| 24 | ||
| 25 | public function handle(UserDataTransferObject $userDataTransferObject): void |
|
| 26 | { |
|
| 27 | $newUser = $userDataTransferObject->getEntity(); |
|
| 28 | ||
| 29 | $newUser->encodePassword($this->encoderFactory->getEncoder($newUser)); |
|
| 30 | ||
| 31 | $repository = $this->getUserRepositoryForUser($this->userRepositoryCollection, $newUser); |
|
| 32 | $repository->add($newUser); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| @@ 9-33 (lines=25) @@ | ||
| 6 | use SumoCoders\FrameworkMultiUserBundle\User\BaseUserRepositoryCollection; |
|
| 7 | use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; |
|
| 8 | ||
| 9 | final class UpdateUserHandler extends AbstractUserHandler |
|
| 10 | { |
|
| 11 | /** @var BaseUserRepositoryCollection */ |
|
| 12 | private $userRepositoryCollection; |
|
| 13 | ||
| 14 | /** @var EncoderFactoryInterface */ |
|
| 15 | private $encoderFactory; |
|
| 16 | ||
| 17 | public function __construct( |
|
| 18 | EncoderFactoryInterface $encoderFactory, |
|
| 19 | BaseUserRepositoryCollection $userRepositoryCollection |
|
| 20 | ) { |
|
| 21 | $this->userRepositoryCollection = $userRepositoryCollection; |
|
| 22 | $this->encoderFactory = $encoderFactory; |
|
| 23 | } |
|
| 24 | ||
| 25 | public function handle(UserDataTransferObject $userDataTransferObject): void |
|
| 26 | { |
|
| 27 | $userEntity = $userDataTransferObject->getEntity(); |
|
| 28 | ||
| 29 | $userEntity->encodePassword($this->encoderFactory->getEncoder($userEntity)); |
|
| 30 | $repository = $this->getUserRepositoryForUser($this->userRepositoryCollection, $userEntity); |
|
| 31 | $repository->save($userEntity); |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||