for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the BenGorUser package.
*
* (c) Beñat Espiña <[email protected]>
* (c) Gorka Laucirica <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace BenGorUser\User\Domain\Model;
use BenGorUser\User\Domain\Model\Event\UserEvent;
/**
* User aggregate root class.
* @author Beñat Espiña <[email protected]>
abstract class UserAggregateRoot
{
* Array which contains the domain events.
* @var array
private $events = [];
* Clears the events container.
public function eraseEvents()
$this->events = [];
}
* Gets the recorded domain events.
* @return array
public function events()
return $this->events;
* Publishes the domain event.
* If the solution needs a singleton based event system,
* this methods will be overwritten.
* The recommend way is to record events domains in the aggregate root
* so, by default, this method calls to the "record" method.
* @param UserEvent $anEvent The domain event
protected function publish(UserEvent $anEvent)
$this->record($anEvent);
* Saves the given domain event inside event container.
private function record(UserEvent $anEvent)
$this->events[] = $anEvent;