-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
466 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
services: | ||
domain_event.publisher: | ||
class: GpsLab\Bundle\DomainEvent\Event\Listener\DomainEventPublisher | ||
arguments: [ '@domain_event.bus', ~ ] | ||
arguments: [ '@domain_event.puller', '@domain_event.bus', ~ ] | ||
tags: | ||
- { name: doctrine.event_subscriber, connection: default } | ||
- { name: doctrine.event_subscriber } | ||
|
||
domain_event.puller: | ||
class: GpsLab\Bundle\DomainEvent\Service\EventPuller | ||
public: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* GpsLab component. | ||
* | ||
* @author Peter Gribanov <info@peter-gribanov.ru> | ||
* @copyright Copyright (c) 2011, Peter Gribanov | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace GpsLab\Bundle\DomainEvent\Service; | ||
|
||
use Doctrine\Common\Persistence\Proxy; | ||
use Doctrine\ORM\UnitOfWork; | ||
use GpsLab\Domain\Event\Aggregator\AggregateEvents; | ||
use GpsLab\Domain\Event\Event; | ||
|
||
class EventPuller | ||
{ | ||
/** | ||
* @param UnitOfWork $uow | ||
* | ||
* @return Event[] | ||
*/ | ||
public function pull(UnitOfWork $uow) | ||
{ | ||
$events = []; | ||
|
||
$events = array_merge($events, $this->pullFromEntities($uow->getScheduledEntityDeletions())); | ||
$events = array_merge($events, $this->pullFromEntities($uow->getScheduledEntityInsertions())); | ||
$events = array_merge($events, $this->pullFromEntities($uow->getScheduledEntityUpdates())); | ||
|
||
// other entities | ||
foreach ($uow->getIdentityMap() as $entities) { | ||
$events = array_merge($events, $this->pullFromEntities($entities)); | ||
} | ||
|
||
return $events; | ||
} | ||
|
||
/** | ||
* @param array $entities | ||
* | ||
* @return Event[] | ||
*/ | ||
private function pullFromEntities(array $entities) | ||
{ | ||
$events = []; | ||
foreach ($entities as $entity) { | ||
// ignore Doctrine proxy classes | ||
// proxy class can't have a domain events | ||
if (!($entity instanceof Proxy) && $entity instanceof AggregateEvents) { | ||
$events = array_merge($events, $entity->pullEvents()); | ||
} | ||
} | ||
|
||
return $events; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.