| @@ 25-61 (lines=37) @@ | ||
| 22 | * |
|
| 23 | * @author Beñat Espiña <[email protected]> |
|
| 24 | */ |
|
| 25 | class GrantUserRoleHandler |
|
| 26 | { |
|
| 27 | /** |
|
| 28 | * The user repository. |
|
| 29 | * |
|
| 30 | * @var UserRepository |
|
| 31 | */ |
|
| 32 | private $repository; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Constructor. |
|
| 36 | * |
|
| 37 | * @param UserRepository $aRepository The user repository |
|
| 38 | */ |
|
| 39 | public function __construct(UserRepository $aRepository) |
|
| 40 | { |
|
| 41 | $this->repository = $aRepository; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Handles the given command. |
|
| 46 | * |
|
| 47 | * @param GrantUserRoleCommand $aCommand The command |
|
| 48 | * |
|
| 49 | * @throws UserDoesNotExistException when user does not exist |
|
| 50 | */ |
|
| 51 | public function __invoke(GrantUserRoleCommand $aCommand) |
|
| 52 | { |
|
| 53 | $user = $this->repository->userOfId(new UserId($aCommand->id())); |
|
| 54 | if (null === $user) { |
|
| 55 | throw new UserDoesNotExistException(); |
|
| 56 | } |
|
| 57 | $user->grant(new UserRole($aCommand->role())); |
|
| 58 | ||
| 59 | $this->repository->persist($user); |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||
| @@ 25-61 (lines=37) @@ | ||
| 22 | * @author Beñat Espiña <[email protected]> |
|
| 23 | * @author Gorka Laucirica <[email protected]> |
|
| 24 | */ |
|
| 25 | class LogOutUserHandler |
|
| 26 | { |
|
| 27 | /** |
|
| 28 | * The user repository. |
|
| 29 | * |
|
| 30 | * @var UserRepository |
|
| 31 | */ |
|
| 32 | private $repository; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Constructor. |
|
| 36 | * |
|
| 37 | * @param UserRepository $aRepository The user repository |
|
| 38 | */ |
|
| 39 | public function __construct(UserRepository $aRepository) |
|
| 40 | { |
|
| 41 | $this->repository = $aRepository; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Handles the given command. |
|
| 46 | * |
|
| 47 | * @param LogOutUserCommand $aCommand The command |
|
| 48 | * |
|
| 49 | * @throws UserDoesNotExistException when the user does not exist |
|
| 50 | */ |
|
| 51 | public function __invoke(LogOutUserCommand $aCommand) |
|
| 52 | { |
|
| 53 | $user = $this->repository->userOfId(new UserId($aCommand->id())); |
|
| 54 | if (null === $user) { |
|
| 55 | throw new UserDoesNotExistException(); |
|
| 56 | } |
|
| 57 | $user->logout(); |
|
| 58 | ||
| 59 | $this->repository->persist($user); |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||
| @@ 25-61 (lines=37) @@ | ||
| 22 | * |
|
| 23 | * @author Beñat Espiña <[email protected]> |
|
| 24 | */ |
|
| 25 | class RevokeUserRoleHandler |
|
| 26 | { |
|
| 27 | /** |
|
| 28 | * The user repository. |
|
| 29 | * |
|
| 30 | * @var UserRepository |
|
| 31 | */ |
|
| 32 | private $repository; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Constructor. |
|
| 36 | * |
|
| 37 | * @param UserRepository $aRepository The user repository |
|
| 38 | */ |
|
| 39 | public function __construct(UserRepository $aRepository) |
|
| 40 | { |
|
| 41 | $this->repository = $aRepository; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Handles the given command. |
|
| 46 | * |
|
| 47 | * @param RevokeUserRoleCommand $aCommand The command |
|
| 48 | * |
|
| 49 | * @throws UserDoesNotExistException when the user does not exist |
|
| 50 | */ |
|
| 51 | public function __invoke(RevokeUserRoleCommand $aCommand) |
|
| 52 | { |
|
| 53 | $user = $this->repository->userOfId(new UserId($aCommand->id())); |
|
| 54 | if (null === $user) { |
|
| 55 | throw new UserDoesNotExistException(); |
|
| 56 | } |
|
| 57 | $user->revoke(new UserRole($aCommand->role())); |
|
| 58 | ||
| 59 | $this->repository->persist($user); |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||