Created
November 19, 2015 23:32
-
-
Save pocky/9f4f458dd866f11548d8 to your computer and use it in GitHub Desktop.
DDD => CQRS
This file contains hidden or 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
<?php | |
namespace Infrastructure\Website\Persistence; | |
use Domain\Website\Entity\Website; | |
use Domain\Website\ValueObject\WebsiteId; | |
use Domain\Website\Repository\WebsiteRepository; | |
class InMemoryRepository implements WebsiteRepository | |
{ | |
protected $website; | |
public function __construct() | |
{ | |
$this->website = []; | |
} | |
public function findAll() | |
{ | |
return $this->website; | |
} | |
public function add(Website $website) | |
{ | |
if (!isset($this->website[$website->getWebsiteId()])) { | |
$this->website[$website->getWebsiteId()] = $website; | |
} | |
} | |
public function find(WebsiteId $id) | |
{ | |
if (isset($this->website[$id->getValue()])) { | |
return $this->website[$id->getvalue()]; | |
} | |
} | |
public function remove(WebsiteId $id) | |
{ | |
unset($this->website[$id->getValue()]); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace Infrastructure\Website\Persistence\CQRS; | |
use Domain\Website\Repository\WebsiteRepository; | |
use Domain\Website\ValueObject\WebsiteId; | |
class ReadRepository | |
{ | |
protected $repository; | |
public function __construct(WebsiteRepository $repository) | |
{ | |
$this->repository = $repository; | |
} | |
public function find(WebsiteId $id) | |
{ | |
return $this->repository->find($id); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace Domain\Website\Repository; | |
use Domain\Website\Entity\Website; | |
use Domain\Website\ValueObject\WebsiteId; | |
/** | |
* Class WebsiteRepository | |
*/ | |
interface WebsiteRepository | |
{ | |
public function findAll(); | |
public function find(WebsiteId $id); | |
public function add(Website $website); | |
public function remove(WebsiteId $id); | |
} |
This file contains hidden or 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
<?php | |
namespace Infrastructure\Website\Persistence\CQRS; | |
use Domain\Website\Entity\Website; | |
use Domain\Website\Repository\WebsiteRepository; | |
class WriteRepository | |
{ | |
protected $repository; | |
public function __construct(WebsiteRepository $repository) | |
{ | |
$this->repository = $repository; | |
} | |
public function add(Website $website) | |
{ | |
$this->repository->add($website); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment