Skip to content

Commit

Permalink
Merge pull request #32 from codeliner/feature/message-interface
Browse files Browse the repository at this point in the history
Add a message interface to reduce coupling
  • Loading branch information
codeliner committed Aug 12, 2015
2 parents 9c31589 + 5e6664c commit b38f62e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 20 deletions.
17 changes: 3 additions & 14 deletions src/Messaging/DomainMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -176,7 +165,7 @@ public function metadata()
}

/**
* Returns an array copy of this command
* Returns an array copy of this message
*
* @return array
*/
Expand Down
83 changes: 83 additions & 0 deletions src/Messaging/Message.php
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);
}
10 changes: 6 additions & 4 deletions src/Messaging/MessageConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/Messaging/MessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface MessageFactory
*
* @param string $messageName
* @param array $messageData
* @return DomainMessage
* @return Message
*/
public function createMessageFromArray($messageName, array $messageData);
}
}

0 comments on commit b38f62e

Please sign in to comment.