-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from codeliner/feature/message-interface
Add a message interface to reduce coupling
- Loading branch information
Showing
4 changed files
with
94 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,17 +16,13 @@ | |
/** | ||
* Class DomainMessage | ||
* | ||
* Base class for commands and domain events. Both are messages but differ in their intention. | ||
* Base class for commands, domain events and queries. All are messages but differ in their intention. | ||
* | ||
* @package Prooph\Common\Messaging | ||
* @author Alexander Miertsch <[email protected]> | ||
*/ | ||
abstract class DomainMessage implements HasMessageName | ||
abstract class DomainMessage implements Message | ||
{ | ||
const TYPE_COMMAND = 'command'; | ||
const TYPE_EVENT = 'event'; | ||
const TYPE_QUERY = 'query'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
|
@@ -59,13 +55,6 @@ abstract class DomainMessage implements HasMessageName | |
*/ | ||
protected $dateTimeFormat = \DateTime::ISO8601; | ||
|
||
/** | ||
* Should be either DomainMessage::TYPE_COMMAND or DomainMessage::TYPE_EVENT or DomainMessage::TYPE_QUERY | ||
* | ||
* @return string | ||
*/ | ||
abstract public function messageType(); | ||
|
||
/** | ||
* Return message payload as array | ||
* | ||
|
@@ -176,7 +165,7 @@ public function metadata() | |
} | ||
|
||
/** | ||
* Returns an array copy of this command | ||
* Returns an array copy of this message | ||
* | ||
* @return array | ||
*/ | ||
|
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,83 @@ | ||
<?php | ||
/* | ||
* This file is part of the prooph/common. | ||
* (c) 2014-2015 prooph software GmbH <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* Date: 8/11/15 - 10:04 PM | ||
*/ | ||
|
||
namespace Prooph\Common\Messaging; | ||
|
||
use Rhumsaa\Uuid\Uuid; | ||
|
||
/** | ||
* Interface Message | ||
* | ||
* @package Prooph\Common\Messaging | ||
* @author Alexander Miertsch <[email protected]> | ||
*/ | ||
interface Message extends HasMessageName | ||
{ | ||
const TYPE_COMMAND = 'command'; | ||
const TYPE_EVENT = 'event'; | ||
const TYPE_QUERY = 'query'; | ||
|
||
/** | ||
* Should be one of Message::TYPE_COMMAND, Message::TYPE_EVENT or Message::TYPE_QUERY | ||
* | ||
* @return string | ||
*/ | ||
public function messageType(); | ||
|
||
/** | ||
* @return Uuid | ||
*/ | ||
public function uuid(); | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function version(); | ||
|
||
/** | ||
* @return \DateTimeImmutable | ||
*/ | ||
public function createdAt(); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function metadata(); | ||
|
||
/** | ||
* Returns a new instance of the message with given version | ||
* | ||
* @param int $version | ||
* @return Message | ||
*/ | ||
public function withVersion($version); | ||
|
||
/** | ||
* Returns a new instance of the message with given metadata | ||
* | ||
* Metadata must be given as a hash table containing only scalar values | ||
* | ||
* @param array $metadata | ||
* @return Message | ||
*/ | ||
public function withMetadata(array $metadata); | ||
|
||
/** | ||
* Returns new instance of message with $key => $value added to metadata | ||
* | ||
* Given value must have a scalar type. | ||
* | ||
* @param string $key | ||
* @param mixed $value | ||
* @return Message | ||
*/ | ||
public function withAddedMetadata($key, $value); | ||
} |
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 |
---|---|---|
|
@@ -14,16 +14,18 @@ | |
/** | ||
* Interface MessageConverter | ||
* | ||
* A message converter is able to convert a DomainMessage into an array | ||
* A message converter is able to convert a Message into an array | ||
* | ||
* @package Prooph\Common\Messaging | ||
* @author Alexander Miertsch <[email protected]> | ||
*/ | ||
interface MessageConverter | ||
{ | ||
/** | ||
* @param DomainMessage $domainMessage | ||
* | ||
* | ||
* @param Message $domainMessage | ||
* @return array | ||
*/ | ||
public function convertToArray(DomainMessage $domainMessage); | ||
} | ||
public function convertToArray(Message $domainMessage); | ||
} |
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