@@ 7-33 (lines=27) @@ | ||
4 | ||
5 | use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection; |
|
6 | ||
7 | final class CreateUserHandler extends UserHandler |
|
8 | { |
|
9 | /** |
|
10 | * @var UserRepositoryCollection |
|
11 | */ |
|
12 | private $userRepositoryCollection; |
|
13 | ||
14 | /** |
|
15 | * CreateUserHandler constructor. |
|
16 | * |
|
17 | * @param UserRepositoryCollection $userRepositoryCollection |
|
18 | */ |
|
19 | public function __construct(UserRepositoryCollection $userRepositoryCollection) |
|
20 | { |
|
21 | $this->userRepositoryCollection = $userRepositoryCollection; |
|
22 | } |
|
23 | ||
24 | /** |
|
25 | * @param CreateUser $command |
|
26 | */ |
|
27 | public function handle(CreateUser $command, $class) |
|
28 | { |
|
29 | $user = new $class($command->getUsername(), $command->getPassword(), $command->getDisplayName()); |
|
30 | $repository = $this->getUserRepositoryForUser($this->userRepositoryCollection, $user); |
|
31 | $repository->add($user); |
|
32 | } |
|
33 | } |
|
34 |
@@ 8-35 (lines=28) @@ | ||
5 | use SumoCoders\FrameworkMultiUserBundle\User\User; |
|
6 | use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection; |
|
7 | ||
8 | final class UpdateUserHandler extends UserHandler |
|
9 | { |
|
10 | /** |
|
11 | * @var UserRepositoryCollection |
|
12 | */ |
|
13 | private $userRepositoryCollection; |
|
14 | ||
15 | /** |
|
16 | * CreateUserHandler constructor. |
|
17 | * |
|
18 | * @param UserRepositoryCollection $userRepositoryCollection |
|
19 | */ |
|
20 | public function __construct(UserRepositoryCollection $userRepositoryCollection) |
|
21 | { |
|
22 | $this->userRepositoryCollection = $userRepositoryCollection; |
|
23 | } |
|
24 | ||
25 | /** |
|
26 | * @param UpdateUser $command |
|
27 | */ |
|
28 | public function handle(UpdateUser $command) |
|
29 | { |
|
30 | $updatingUser = $command->getUser(); |
|
31 | $user = new User($command->getUsername(), $command->getPassword(), $command->getDisplayName()); |
|
32 | $repository = $this->getUserRepositoryForUser($this->userRepositoryCollection, $updatingUser); |
|
33 | $repository->update($updatingUser, $user); |
|
34 | } |
|
35 | } |
|
36 |