This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
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
30 changed files
with
202 additions
and
93 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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace LiteCQRS\Bus; | ||
|
||
use LiteCQRS\DomainEvent; | ||
|
||
class EventName | ||
{ | ||
private $event; | ||
private $name; | ||
|
||
public function __construct($event) | ||
{ | ||
$this->event = $event; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
if ($this->name === null) { | ||
$this->name = $this->parseName(); | ||
} | ||
|
||
return $this->name; | ||
} | ||
|
||
private function parseName() | ||
{ | ||
if ($this->event instanceof DomainEvent) { | ||
return $this->event->getEventName(); | ||
} | ||
|
||
$class = get_class($this->event); | ||
|
||
if (substr($class, -5) === "Event") { | ||
$class = substr($class, 0, -5); | ||
} | ||
|
||
if (strpos($class, "\\") === false) { | ||
return $class; | ||
} | ||
|
||
$parts = explode("\\", $class); | ||
return end($parts); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace LiteCQRS\Bus; | ||
|
||
/** | ||
* Allows access to all events that commands have triggered. | ||
*/ | ||
interface EventQueue | ||
{ | ||
/** | ||
* Dequeue all events from the queue and return them in order. | ||
* | ||
* @return array<object> | ||
*/ | ||
public function dequeueAllEvents(); | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace LiteCQRS\Bus\IdentityMap; | ||
|
||
use LiteCQRS\Bus\EventQueue; | ||
|
||
/** | ||
* Returns all events from {@see EventProviderInterface} instances | ||
* that are saved in the identity map. | ||
*/ | ||
class EventProviderQueue implements EventQueue | ||
{ | ||
private $identityMap; | ||
|
||
public function __construct(IdentityMapInterface $identityMap) | ||
{ | ||
$this->identityMap = $identityMap; | ||
} | ||
|
||
public function dequeueAllEvents() | ||
{ | ||
$dequeueEvents = array(); | ||
|
||
foreach ($this->identityMap->all() as $aggregateRoot) { | ||
$id = $this->identityMap->getAggregateId($aggregateRoot); | ||
|
||
foreach ($aggregateRoot->dequeueAppliedEvents() as $event) { | ||
$header = $event->getMessageHeader(); | ||
$header->aggregateType = get_class($aggregateRoot); | ||
$header->aggregateId = $id; | ||
$header->setAggregate(null); | ||
|
||
$dequeueEvents[] = $event; | ||
} | ||
} | ||
|
||
return $dequeueEvents; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/LiteCQRS/Bus/IdentityMapInterface.php → .../Bus/IdentityMap/IdentityMapInterface.php
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,6 @@ | ||
<?php | ||
|
||
namespace LiteCQRS\Bus; | ||
namespace LiteCQRS\Bus\IdentityMap; | ||
|
||
use LiteCQRS\EventProviderInterface; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/LiteCQRS/Bus/SimpleIdentityMap.php → ...QRS/Bus/IdentityMap/SimpleIdentityMap.php
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,6 @@ | ||
<?php | ||
|
||
namespace LiteCQRS\Bus; | ||
namespace LiteCQRS\Bus\IdentityMap; | ||
|
||
use LiteCQRS\EventProviderInterface; | ||
|
||
|
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
Oops, something went wrong.