Skip to content

Instantly share code, notes, and snippets.

View dgafka's full-sized avatar

Dariusz Gafka dgafka

View GitHub Profile
class ChangeEmailAddressCommand
{
public function __construct(private string $userId, private string $email) {}
public function getUserId(): string
{
return $this->userId;
}
public function getEmail(): string
class UserService
{
#[CommandHandler]
public function changeEmail(ChangeEmailAddressCommand $command) : void
{
// retrieve user and change the email
}
}
<?php
class PersonController
{
public function __construct(private CommandBus $commandBus) {}
public function changeEmailAddress(Request $request)
{
$userId = $request->get('userId');
$email = $request->get('email');
<?php
class GetUserShippingAddressQuery
{
public function __construct(private string $userId) {}
public function getUserId(): string
{
return $this->userId;
}
}
<?php
class UserService
{
#[QueryHandler]
public function getPersonDetails(GetUserShippingAddressQuery $query)
{
$shippingAddress = // use query to get the shipping address;
return $shippingAddress;
}
<?php
class PersonController
{
public function __construct(private QueryBus $queryBus) {}
public function getShippingAddress(Request $request)
{
$userId = $request->get('userId');
@dgafka
dgafka / handlings-events-php-01.php
Last active August 17, 2021 14:12
handlings-events-php-01
<?php
class PersonWasRegistered
{
public function __construct(private string $personId) {}
public function getPersonId(): string
{
return $this->personId;
}
}
@dgafka
dgafka / handlings-events-php-02.php
Last active August 7, 2021 16:19
handlings-events-php-02
<?php
class PersonRegistrationEventSubscriber
{
#[EventHandler]
public function sendWelcomeEmail(PersonWasRegistered $event, EmailSender $emailSender): void
{
$person = $this->userRepository->getById($event->getPersonId());
$emailSender->sendWelcomeTo($person);
}
@dgafka
dgafka / handlings-events-php-03.php
Created August 7, 2021 15:40
handlings-events-php-03
<?php
use Ecotone\Modelling\EventBus;
class PersonRegistrationService
{
public function __construct(private UserRepository $userRepository, private EventBus $event) {}
public function registerUser($registerPersonData)
{
@dgafka
dgafka / handlings-events-php-00.php
Last active August 8, 2021 05:34
handlings-events-php-00
<?php
class PersonRegistrationService
{
public function __construct(private UserRepository $userRepository, private EmailSender $emailSender, private LogRepository $logRepository, private ExternalIntegratedService $externalService) {}
public function registerUser($registerPersonData)
{
$person = new Person($registerPersonData);
$this->userRepository->save($person);