Skip to Content
Domain-Driven Design in PHP
book

Domain-Driven Design in PHP

by Keyvan Akbary, Carlos Buenosvinos, Christian Soronellas
June 2017
Intermediate to advanced
394 pages
8h 52m
English
Packt Publishing
Content preview from Domain-Driven Design in PHP

SQL Implementation

In a classic example, we could create a simple PDO implementation for our PostRepository just by using plain SQL queries:

namespace Infrastructure\Persistence\Sql;use Domain\Model\Body;use Domain\Model\Post;use Domain\Model\PostId;use Domain\Model\PostRepository;class SqlPostRepository implements PostRepository{    const DATE_FORMAT = 'Y-m-d H:i:s';    private $pdo;    public function __construct(\PDO $pdo)    {        $this->pdo = $pdo;    }    public function save(Post $aPost)    {        $sql ='INSERT INTO posts ' .            '(id, body, created_at) VALUES ' .            '(:id, :body, :created_at)';        $this->execute($sql, [            'id' => $aPost->id()->id(),            'body' => $aPost->body()->content(),            'created_at' => $aPost->createdAt()->format(                self::DATE_FORMAT            )        ]);    } private function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Web Services

PHP Web Services

Lorna Jane Mitchell
PHP Microservices

PHP Microservices

Pablo Solar Vilariño, Carlos Pérez Sánchez

Publisher Resources

ISBN: 9781787284944