June 2017
Intermediate to advanced
394 pages
8h 52m
English
As an example, if we wanted to replicate the latestPosts query method in our PostRepository by using a Specification for an in-memory implementation, it would look like this:
namespace Infrastructure\Persistence\InMemory;use Domain\Model\Post;interface InMemoryPostSpecification{ /** * @return boolean */ public function specifies(Post $aPost);}
The in-memory implementation for the latestPosts behavior could look like this:
namespace Infrastructure\Persistence\InMemory;use Domain\Model\Post;class InMemoryLatestPostSpecification implements InMemoryPostSpecification{ private $since; public function __construct(\DateTimeImmutable $since) { $this->since = $since; } public function specifies(Post $aPost) { return $aPost->createdAt() ...