Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / RecordResultForm.php
Last active December 26, 2021 09:15
Dynamically add Elements to Symfony Form Collection without Data
<?php
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
final class RecordResult extends AbstractType
@webdevilopers
webdevilopers / Customer.php
Last active August 17, 2021 01:38
Using event subscriber to get MongoDB ODM Documents related to ORM Entity in Doctrine
<?php
/**
* @ORM\Entity()
* @ORM\EntityListeners({"Acme\AppBundle\Event\CustomerListener"})
*/
class Customer()
{
}
@webdevilopers
webdevilopers / RecentContractsBlockService.php
Last active June 3, 2021 08:34
Sonata Admin - Include custom block / list view in edit template
<?php
namespace Plusquam\Bundle\ContractBundle\Block;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
@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 / AbstractDormerPriceQuote.php
Last active October 2, 2020 10:49
Symfony Assert Annotations using external Class constants
<?php
namespace Sps\Bundle\PriceQuoteBundle\Entity;
abstract class AbstractDormerPriceQuote
extends PriceQuoteRequest
{
const MIN_ROOF_PITCH = 10;
const MAX_ROOF_PITCH = 55;
}
@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 / 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 {
@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;