1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the takeit/AmpHtmlBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Rafał Muszyński <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Takeit\Bundle\AmpHtmlBundle\Controller; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
15
|
|
|
use Takeit\Bundle\AmpHtmlBundle\Converter\AmpConverterInterface; |
16
|
|
|
use Takeit\Bundle\AmpHtmlBundle\Loader\ThemeLoaderInterface; |
17
|
|
|
use Takeit\Bundle\AmpHtmlBundle\Model\AmpInterface; |
18
|
|
|
use Twig\Environment; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Renders AMP HTML compatible template. |
22
|
|
|
* |
23
|
|
|
* @author Rafał Muszyński <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class AmpViewController |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var Environment; |
29
|
|
|
*/ |
30
|
|
|
private $twig; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var AmpConverterInterface |
34
|
|
|
*/ |
35
|
|
|
private $converter; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var ThemeLoaderInterface |
39
|
|
|
*/ |
40
|
|
|
private $themeLoader; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param Environment $twig |
44
|
|
|
* @param AmpConverterInterface $converter |
45
|
|
|
* @param ThemeLoaderInterface $themeLoader |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
Environment $twig, |
49
|
|
|
AmpConverterInterface $converter, |
50
|
|
|
ThemeLoaderInterface $themeLoader |
51
|
|
|
) { |
52
|
|
|
$this->twig = $twig; |
53
|
|
|
$this->converter = $converter; |
54
|
|
|
$this->themeLoader = $themeLoader; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param AmpInterface $object |
59
|
|
|
* |
60
|
|
|
* @return Response |
61
|
|
|
*/ |
62
|
|
|
public function viewAction(AmpInterface $object) |
63
|
|
|
{ |
64
|
|
|
$this->themeLoader->load(); |
65
|
|
|
|
66
|
|
|
$response = new Response(); |
67
|
|
|
$content = $this->twig->render(sprintf('@%s/index.html.twig', ThemeLoaderInterface::THEME_NAMESPACE), [ |
68
|
|
|
'object' => $object, |
69
|
|
|
]); |
70
|
|
|
|
71
|
|
|
$response->setContent($this->converter->convertToAmp($content)); |
72
|
|
|
|
73
|
|
|
return $response; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|