PHP code example of swag-industries / doctrine-domain-events

1. Go to this page and download the library: Download swag-industries/doctrine-domain-events library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swag-industries / doctrine-domain-events example snippets


class YourModel extends DomainModel
{
    public const CREATION = 'creation';
    public function __construct()
    {
        $this->dispatch(new DomainEvent($this), self::CREATION);
    }
}

class DomainRule implements DomainRuleInterface
{
    public function on()
    {
        return YourModel::CREATION;
    }
    
    public function execute(DomainEvent $event)
    {
        // Do Something on your model creation
    }
}

use Biig\Component\Domain\Model\Instantiator\Instantiator;
use Doctrine\ORM\EntityManager;

class SomeController
{
    public function index(Instantiator $instantiator, EntityManager $entityManager)
    {
        $model = $instantiator->instantiate(YourModel::class);
        $entityManager->persist($model);
        $entityManager->flush();
    }
}


// config/bundles.php

return [
    // ...
    Biig\Component\Domain\Integration\Symfony\DomainBundle::class => ['all' => true],
];