-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add current user to certain messages
- Loading branch information
1 parent
c9d544f
commit 9c34601
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gems\Messenger; | ||
|
||
use Gems\Legacy\CurrentUserRepository; | ||
use Gems\Messenger\Message\CurrentUserMessage; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\Middleware\MiddlewareInterface; | ||
use Symfony\Component\Messenger\Middleware\StackInterface; | ||
|
||
class CurrentUserMiddleware implements MiddlewareInterface | ||
{ | ||
public function __construct( | ||
private readonly CurrentUserRepository $currentUserRepository, | ||
) | ||
{} | ||
|
||
public function handle(Envelope $envelope, StackInterface $stack): Envelope | ||
{ | ||
$message = $envelope->getMessage(); | ||
if ($message instanceof CurrentUserMessage && $this->currentUserRepository->getCurrentLoginName() === null) { | ||
$this->currentUserRepository->setCurrentUserCredentials($message->getUserName(), $message->getOrganizationId()); | ||
$this->currentUserRepository->getCurrentUser(); | ||
} | ||
|
||
return $stack->next()->handle($envelope, $stack); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gems\Messenger\Message; | ||
|
||
class CurrentUserMessage | ||
{ | ||
public function __construct( | ||
protected readonly string $userName, | ||
protected readonly int $organizationId | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUserName(): string | ||
{ | ||
return $this->userName; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getOrganizationId(): int | ||
{ | ||
return $this->organizationId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters