Skip to content

Commit

Permalink
Align classes according to prooph/common integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Miertsch committed May 1, 2015
1 parent 3e6c860 commit e83d533
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 348 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: php

php:
- 5.4
- 5.5
- 5.6


before_script:
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
"zf2"
],
"require": {
"php": ">=5.4",
"php": ">=5.5",
"rhumsaa/uuid" : "~2.5",
"codeliner/array-reader": "~1.1",
"beberlei/assert": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"prooph/event-store" : "~2.0",
"prooph/event-store" : "dev-master",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
Expand Down
125 changes: 9 additions & 116 deletions src/Prooph/EventSourcing/AggregateChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,121 +9,42 @@
namespace Prooph\EventSourcing;

use Assert\Assertion;
use Codeliner\ArrayReader\ArrayReader;
use Rhumsaa\Uuid\Uuid;
use Prooph\Common\Messaging\DomainEvent;

/**
* AggregateChanged
*
* @author Alexander Miertsch <[email protected]>
* @package Prooph\EventSourcing
*/
class AggregateChanged implements DomainEvent
class AggregateChanged extends DomainEvent
{
/**
* @var Uuid
*/
protected $uuid;

/**
* @var mixed
* @var string
*/
protected $aggregateId;

/**
* This property is injected via Reflection
*
* @var int
*/
protected $version;

/**
* @var array
*/
protected $payload;

/**
* @var \DateTime
*/
protected $occurredOn;

/**
* @var ArrayReader
*/
private $payloadReader;

/**
* @param string $aggregateId
* @param array $payload
* @return static
*/
public static function occur($aggregateId, array $payload)
{
return new static($aggregateId, $payload);
}

/**
* @param string $aggregateId
* @param array $payload
* @param Uuid $uuid
* @param \DateTime $occurredOn
* @param $version
* @return static
*/
public static function reconstitute($aggregateId, array $payload, Uuid $uuid, \DateTime $occurredOn, $version)
{
return new static($aggregateId, $payload, $uuid, $occurredOn, $version);
}

/**
* @param string $aggregateId
* @param array $payload
* @param Uuid $uuid
* @param \DateTime $occurredOn
* @param null|int $version
*/
protected function __construct($aggregateId, array $payload, Uuid $uuid = null, \DateTime $occurredOn = null, $version = null)
{
if (is_null($uuid)) {
$uuid = Uuid::uuid4();
}

if (is_null($occurredOn)) {
$occurredOn = new \DateTime();
}
$instance = new static(__CLASS__, $payload, 1, null, null, ['aggregate_id' => $aggregateId]);

$this->setAggregateId($aggregateId);
$this->payload = $payload;
$this->uuid = $uuid;
$this->occurredOn = $occurredOn;
//We reset version here, because the AggregateTranslator will inject the version of the aggregate via method trackVersion
$instance->version = null;

if (! is_null($version)) {
$this->setVersion($version);
}
return $instance;
}

/**
* @return string
*/
public function aggregateId()
{
return $this->aggregateId;
}

/**
* @return Uuid
*/
public function uuid()
{
return $this->uuid;
}

/**
* @return int
*/
public function version()
{
return $this->version;
return $this->metadata['aggregate_id'];
}

/**
Expand Down Expand Up @@ -155,34 +76,6 @@ protected function setVersion($version)
$this->version = $version;
}

/**
* @return \DateTime
*/
public function occurredOn()
{
return $this->occurredOn;
}

/**
* @return array
*/
public function payload()
{
return $this->payload;
}

/**
* @return ArrayReader
*/
public function toPayloadReader()
{
if (is_null($this->payloadReader)) {
$this->payloadReader = new ArrayReader($this->payload());
}

return $this->payloadReader;
}

/**
* @param string $aggregateId
*/
Expand All @@ -191,6 +84,6 @@ protected function setAggregateId($aggregateId)
Assertion::string($aggregateId);
Assertion::notEmpty($aggregateId);

$this->aggregateId = $aggregateId;
$this->metadata['aggregate_id'] = $aggregateId;
}
}
33 changes: 0 additions & 33 deletions src/Prooph/EventSourcing/DomainEvent.php

This file was deleted.

This file was deleted.

Loading

0 comments on commit e83d533

Please sign in to comment.