Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / PersonListProjection.php
Created Oct 29, 2020
Prooph Event Stream Projection from merged streams event ordering
@webdevilopers
webdevilopers / EmploymentContract.php
Last active Aug 30, 2020
Merge event-sourced aggregate roots (A+ES) by passing read model / decision model
View EmploymentContract.php
<?php
final class EmploymentContract extends AggregateRoot
{
/**
* @param Details $contractToMerge
* This contract is always the initial contract and the oldest one.
* Since the contract to merge is always newer it always overwrites the current state.
*/
public function mergeWith(Details $contractToMerge): void
@webdevilopers
webdevilopers / Address.php
Last active Jul 25, 2020
How not allow extra fields in Command DTO using Symfony Messenger
View Address.php
<?php
use Webmozart\Assert\Assert;
final class Address
{
/** @var string|null $street */
private $street;
/** @var Postcode|null $postcode */
@webdevilopers
webdevilopers / FirstName.php
Last active Jul 23, 2020
Applying domain events to aggregate roots when deserializing payload of old events break current value object constraint changes
View FirstName.php
<?php
/**
* All characater were allowed in the initial value object.
*/
final class FirstName_V1
{
/** @var string $name */
private $name;
@webdevilopers
webdevilopers / ChangeName.php
Last active Jul 22, 2020
Symfony Validator Constraints Regex behaves differently to PHP preg_match condition
View ChangeName.php
<?php
namespace Acme\PersonnelManagement\Application\Service\Person;
use Acme\Common\Domain\Model\FirstName;
use Symfony\Component\Validator\Constraints as Assert;
final class ChangeName
{
/**
@webdevilopers
webdevilopers / Merger.php
Created Jul 20, 2020
Prooph Event Store: Query event stream
View Merger.php
<?php
final class Merger
{
// ...
private function getInitialEventFromStream(EmploymentContractId $contractId): EmploymentContractSigned
{
$query = $this->projectionManager->createQuery();
$query
->init(function (): array {
@webdevilopers
webdevilopers / EmploymentContract.php
Last active Jul 15, 2020
Creating event-sourced aggregate roots through CQRS read models
View EmploymentContract.php
<?php
namespace AcmersonnelManagement\Domain\Model\EmploymentContract;
final class EmploymentContract extends AggregateRoot
{
/** @var EmploymentContractId $employmentContractId */
private $id;
/** @var PersonId $personId */
@webdevilopers
webdevilopers / AgencyPublisher.php
Created Jun 6, 2020
Symfony Messenger - Subscribing multiple Handlers to Messages
View AgencyPublisher.php
<?php
namespace Acme\TemporaryWork\Infrastructure\ProcessManager;
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
use Prooph\EventSourcing\AggregateChanged;
use Acme\TemporaryWork\Domain\Model\Agency\Event\AgencyHired;
use Acme\TemporaryWork\Domain\Model\Agency\Event\AgencyModified;
use Acme\PersonnelManagement\Infrastructure\RabbitMq\Producer;
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
@webdevilopers
webdevilopers / EventPublisher.php
Created Jun 4, 2020
Replacing Prooph Service Event Bus with Symfony Messenger using custom Event Publisher
View EventPublisher.php
<?php
namespace Acme\Context\Infrastructure\Prooph;
use Prooph\Common\Event\ActionEvent;
use Prooph\EventStore\ActionEventEmitterEventStore;
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Plugin\AbstractPlugin;
use Prooph\EventStore\TransactionalActionEventEmitterEventStore;
use Symfony\Component\Messenger\MessageBusInterface;
@webdevilopers
webdevilopers / AbstractControllerTest.php
Last active May 8, 2020
Functional Testing Symfony Controllers with JWT and Symfony Messenger
View AbstractControllerTest.php
<?php
namespace Tests\Acme\PersonnelManagement\Infrastructure\Symfony\AcmePersonnelManagementBundle\Controller;
use Lexik\Bundle\JWTAuthenticationBundle\Encoder\JWTEncoderInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
abstract class AbstractControllerTest extends WebTestCase
{
You can’t perform that action at this time.