Created
August 22, 2018 15:27
-
-
Save hgraca/96e9f0b3d22626c50a94ade772e62654 to your computer and use it in GitHub Desktop.
ADR - Action-Domain-Responder
This file contains 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 | |
// Source: https://github.com/pmjones/adr-example/blob/master/src/Web/Blog/Add/BlogAddAction.php | |
namespace Pmjones\Adr\Web\Blog\Add; | |
use Pmjones\Adr\Domain\Blog\BlogService; | |
use Psr\Http\Message\ResponseInterface as Response; | |
use Psr\Http\Message\ServerRequestInterface as Request; | |
class BlogAddAction | |
{ | |
protected $domain; | |
protected $responder; | |
public function __construct( | |
BlogService $domain, | |
BlogAddResponder $responder | |
) { | |
$this->domain = $domain; | |
$this->responder = $responder; | |
} | |
public function __invoke(Request $request) : Response | |
{ | |
$payload = $this->domain->newPost(); | |
return $this->responder->__invoke($request, $payload); | |
} | |
} |
This file contains 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 | |
// Source: https://github.com/pmjones/adr-example/blob/master/src/Web/Blog/Add/BlogAddResponder.php | |
namespace Pmjones\Adr\Web\Blog\Add; | |
use Pmjones\Adr\Web\Blog\BlogResponder; | |
class BlogAddResponder extends BlogResponder | |
{ | |
protected function new() : void | |
{ | |
$this->renderTemplate('add'); | |
} | |
} |
This file contains 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 | |
// Source: https://github.com/pmjones/adr-example/blob/master/src/Domain/Blog/BlogService.php | |
namespace Pmjones\Adr\Domain\Blog; | |
use Pmjones\Adr\DataSource\Blog\BlogMapper; | |
use Pmjones\Adr\Domain\ApplicationService; | |
use Pmjones\Adr\Domain\Payload; | |
use Exception; | |
class BlogService extends ApplicationService | |
{ | |
protected $mapper; | |
protected $filter; | |
public function __construct( | |
BlogMapper $mapper, | |
BlogFilter $filter | |
) { | |
$this->mapper = $mapper; | |
$this->filter = $filter; | |
} | |
protected function fetchPage(int $page = 1, int $paging = 10) : Payload | |
{ | |
$blogs = $this->mapper->selectAllByPage($page, $paging); | |
return $this->newPayload(Payload::STATUS_FOUND, [ | |
'blogs' => $blogs, | |
]); | |
} | |
protected function fetchPost(int $id) : Payload | |
{ | |
// ... | |
} | |
protected function newPost(array $data = []) : Payload | |
{ | |
// ... | |
} | |
protected function addPost(array $data) : Payload | |
{ | |
// ... | |
} | |
protected function editPost(int $id, array $data) : Payload | |
{ | |
// ... | |
} | |
protected function deletePost(int $id) : Payload | |
{ | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment