Skip to content

Commit

Permalink
Merge pull request #27 from codeliner/feature/message-converter
Browse files Browse the repository at this point in the history
Add message converter
  • Loading branch information
codeliner committed Jul 26, 2015
2 parents 69b43e1 + 507b748 commit bb7a131
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Messaging/MessageConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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: 7/26/15 - 3:27 PM
*/

namespace Prooph\Common\Messaging;

/**
* Interface MessageConverter
*
* A message converter is able to convert a DomainMessage into an array
*
* @package Prooph\Common\Messaging
* @author Alexander Miertsch <[email protected]>
*/
interface MessageConverter
{
/**
* @param DomainMessage $domainMessage
* @return array
*/
public function convertToArray(DomainMessage $domainMessage);
}
35 changes: 35 additions & 0 deletions src/Messaging/NoOpMessageConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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: 7/26/15 - 3:30 PM
*/
namespace Prooph\Common\Messaging;

/**
* Class NoOpMessageConverter
*
* The NoOpMessageConverter does not perform any conversion logic.
* It simply returns DomainMessage::toArray.
* The converter acts as a default implementation but allows replacement
* with a custom converter using some special logic.
*
* @package Prooph\Common\Messaging
* @author Alexander Miertsch <[email protected]>
*/
final class NoOpMessageConverter implements MessageConverter
{

/**
* @param DomainMessage $domainMessage
* @return array
*/
public function convertToArray(DomainMessage $domainMessage)
{
return $domainMessage->toArray();
}
}

0 comments on commit bb7a131

Please sign in to comment.