protected function registerEvent($payload, $metadata = null)
    {
        if ($payload instanceof AbstractDomainEvent && null === $payload->aggregateId) {
            $payload->setAggregateId($this->getId());
        }

        return $this->getEventContainer()
            ->addEvent($payload, $metadata);
    }
protected function registerEvent($payload, $metadata = null)
    {
        if ($payload instanceof AbstractDomainEvent && null === $payload->aggregateId) {
            $payload->setAggregateId($this->getId());
        }

        return $this->getEventContainer()
            ->addEvent($payload, $metadata);
    }
protected function registerEvent ( $ payload , $ metadata = null ) { if ( $ payload instanceof AbstractDomainEvent && null === $ payload -> aggregateId ) { $ payload -> setAggregateId ( $ this -> getId ( ) ) ; } return $ this -> getEventContainer ( ) -> addEvent ( $ payload , $ metadata ) ; }
Registers an event to be published when the aggregate is saved, containing the given payload and optional
metadata.

@param object $payload
@param Metadata|array $metadata
@return DomainEventMessageInterface
Registers an event to be published when the aggregate is saved containing the given payload and optional metadata .