1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Explicit Architecture POC, |
7
|
|
|
* which is created on top of the Symfony Demo application. |
8
|
|
|
* |
9
|
|
|
* (c) Herberto Graça <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Acme\App\Presentation\Web\Core\Component\Blog\Anonymous\Post; |
16
|
|
|
|
17
|
|
|
use Acme\App\Core\Component\Blog\Application\Query\PostQueryInterface; |
18
|
|
|
use Acme\App\Core\Port\TemplateEngine\TemplateEngineInterface; |
19
|
|
|
use Psr\Http\Message\ResponseInterface; |
20
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Controller used to manage blog contents in the public part of the site. |
24
|
|
|
* |
25
|
|
|
* @author Ryan Weaver <[email protected]> |
26
|
|
|
* @author Javier Eguiluz <[email protected]> |
27
|
|
|
* @author Herberto Graca <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class PostController |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var TemplateEngineInterface |
33
|
|
|
*/ |
34
|
|
|
private $templateEngine; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var PostQueryInterface |
38
|
|
|
*/ |
39
|
|
|
private $postQuery; |
40
|
|
|
|
41
|
|
|
public function __construct( |
42
|
|
|
TemplateEngineInterface $templateEngine, |
43
|
|
|
PostQueryInterface $postQuery |
44
|
|
|
) { |
45
|
|
|
$this->templateEngine = $templateEngine; |
46
|
|
|
$this->postQuery = $postQuery; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* NOTE: The $post controller argument is automatically injected by Symfony |
51
|
|
|
* after performing a database query looking for a Post with the 'slug' |
52
|
|
|
* value given in the route. |
53
|
|
|
* See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html. |
54
|
|
|
*/ |
55
|
|
|
public function get(ServerRequestInterface $request): ResponseInterface |
56
|
|
|
{ |
57
|
|
|
// Symfony's 'dump()' function is an improved version of PHP's 'var_dump()' but |
58
|
|
|
// it's not available in the 'prod' environment to prevent leaking sensitive information. |
59
|
|
|
// It can be used both in PHP files and Twig templates, but it requires to |
60
|
|
|
// have enabled the DebugBundle. Uncomment the following line to see it in action: |
61
|
|
|
// |
62
|
|
|
// dump($post, $this->getUser(), new \DateTimeImmutable()); |
63
|
|
|
|
64
|
|
|
return $this->templateEngine->renderResponse( |
65
|
|
|
'@Blog/Anonymous/Post/get.html.twig', |
66
|
|
|
$this->postQuery |
67
|
|
|
->includeAuthor() |
68
|
|
|
->includeTags() |
69
|
|
|
->includeComments() |
70
|
|
|
->includeCommentsAuthor() |
71
|
|
|
->execute($request->getAttribute('slug')) |
72
|
|
|
->hydrateSingleResultAs(GetViewModel::class) |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|