Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / PayloadMessage.php
Created Feb 2, 2022
Automatically populate PHP object from Array
View PayloadMessage.php
<?php declare(strict_types=1);
namespace Acme\Shared\Application\Service;
trait PayloadMessage
{
private function __construct()
{}
/**
@webdevilopers
webdevilopers / index.txt
Last active Jan 4, 2022
Migrating from MySQL to PostgreSQL: Grouping and Ordering
View index.txt
Table structure:
test_id place_id
9b949b1a-414b-43f0-8940-9b821f1e2098 a3358c22-af08-485f-933e-f4d6ce900882
5177ab63-5ecd-4241-913e-36fb9d917efd a3358c22-af08-485f-933e-f4d6ce900882
c16ac09c-8ccf-45b9-8593-7ffceb4d5d9e a3358c22-af08-485f-933e-f4d6ce900882
MySQL: SELECT test_id, place_id FROM transmissions GROUP BY place_id
Result (CORRECT):
@webdevilopers
webdevilopers / Upcaster.php
Last active Jan 8, 2021
Attach upcaster to Prooph Event Store
View Upcaster.php
<?php
namespace Acme\Common\Infrastructure\Prooph\EventStore;
use Prooph\Common\Messaging\Message;
use Prooph\EventStore\Upcasting\SingleEventUpcaster;
final class Upcaster extends SingleEventUpcaster
{
public function upcast(Message $message): array
@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 */