Skip to content

Commit

Permalink
Extract "mark aggregate as deleted" feature into trait
Browse files Browse the repository at this point in the history
  • Loading branch information
pauci committed Nov 24, 2017
1 parent 1c3e11b commit 7b69aea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
23 changes: 2 additions & 21 deletions src/Domain/Model/AbstractAggregateRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@
*/
abstract class AbstractAggregateRoot implements AggregateRootInterface
{
use DeletableTrait;

/**
* @var EventContainer
*/
private $eventContainer;

/**
* @var bool
*/
private $deleted = false;

/**
* @ORM\Column(type="integer", options={"unsigned"=true})
* @var int
Expand Down Expand Up @@ -103,22 +100,6 @@ public function commitEvents()
}
}

/**
* Marks this aggregate as deleted, instructing a Repository to remove that aggregate at an appropriate time
*/
protected function markAsDeleted()
{
$this->deleted = true;
}

/**
* @return bool
*/
public function isDeleted()
{
return $this->deleted;
}

/**
* @return int
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Model/AggregateRootInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ public function getVersion();
*
* @return bool
*/
public function isDeleted();
public function isDeleted(): bool;
}
25 changes: 25 additions & 0 deletions src/Domain/Model/DeletableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);

namespace CQRS\Domain\Model;

trait DeletableTrait
{
/**
* @var bool
*/
private $deleted = false;

/**
* Marks this aggregate as deleted, instructing a Repository to remove that aggregate at an appropriate time
*/
protected function markAsDeleted(): void
{
$this->deleted = true;
}

public function isDeleted(): bool
{
return $this->deleted;
}
}

0 comments on commit 7b69aea

Please sign in to comment.