Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / developer.php
Created January 19, 2023 10:27
Early Return Developer vs. OpenAI ChatGTP vs. PHPStorm PHP Inspections
<?php declare(strict_types=1);
final class DocumentFormatValidator
{
private function validatePrefix(Filename $filename, DocumentFormat $format): void
{
$detectedPrefix = $this->detectPrefix($filename);
if ($detectedPrefix === null) {
if (!$format->requiresPrefix()) {
@webdevilopers
webdevilopers / PayloadMessage.php
Created February 2, 2022 13:55
Automatically populate PHP object from Array
<?php declare(strict_types=1);
namespace Acme\Shared\Application\Service;
trait PayloadMessage
{
private function __construct()
{}
/**
@webdevilopers
webdevilopers / index.txt
Last active January 4, 2022 07:40
Migrating from MySQL to PostgreSQL: Grouping and Ordering
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 January 8, 2021 09:05
Attach upcaster to Prooph Event Store
<?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 October 29, 2020 10:43
Prooph Event Stream Projection from merged streams event ordering
<?php
@webdevilopers
webdevilopers / EmploymentContract.php
Last active August 30, 2020 17:20
Merge event-sourced aggregate roots (A+ES) by passing read model / decision model
<?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 July 25, 2020 08:09
How not allow extra fields in Command DTO using Symfony Messenger
<?php
use Webmozart\Assert\Assert;
final class Address
{
/** @var string|null $street */
private $street;
/** @var Postcode|null $postcode */
@webdevilopers
webdevilopers / FirstName.php
Last active July 23, 2020 12:47
Applying domain events to aggregate roots when deserializing payload of old events break current value object constraint changes
<?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 July 22, 2020 10:07
Symfony Validator Constraints Regex behaves differently to PHP preg_match condition
<?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 July 20, 2020 08:56
Prooph Event Store: Query event stream
<?php
final class Merger
{
// ...
private function getInitialEventFromStream(EmploymentContractId $contractId): EmploymentContractSigned
{
$query = $this->projectionManager->createQuery();
$query
->init(function (): array {