AccountableObject.php 633 Bytes
Newer Older
Julien Jorry committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php

namespace App\Flux;

use App\Utils\AccountUtils;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\MappedSuperclass
 * @ORM\HasLifecycleCallbacks
 */
abstract class AccountableObject
{
    /**
     * @ORM\PostPersist
     *
     * @param LifecycleEventArgs $event
     */
    public function postPersist(LifecycleEventArgs $event): void
    {
        $object = $event->getEntity();
        $accountUtils = new AccountUtils($event->getEntityManager());
        // Create account related to entity if needed !
        $accountUtils->createAccountForEntity($object);
    }
}