1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by: Jens |
4
|
|
|
* Date: 12-10-2017 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace CloudControl\Cms\cc\application; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
use CloudControl\Cms\cc\Application; |
11
|
|
|
use CloudControl\Cms\cc\Request; |
12
|
|
|
use CloudControl\Cms\storage\Storage; |
13
|
|
|
|
14
|
|
|
class ApplicationRenderer |
15
|
|
|
{ |
16
|
|
|
protected $storage; |
17
|
|
|
protected $request; |
18
|
|
|
protected $application; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* ApplicationRenderer constructor. |
22
|
|
|
* @param Application $application |
23
|
|
|
* @param Storage $storage |
24
|
|
|
* @param Request $request |
25
|
|
|
*/ |
26
|
|
|
public function __construct(Application $application, Storage $storage, Request $request) |
27
|
|
|
{ |
28
|
|
|
$this->storage = $storage; |
29
|
|
|
$this->request = $request; |
30
|
|
|
$this->application = $application; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Loop through all application components and render them |
35
|
|
|
* @param array $applicationComponents |
36
|
|
|
*/ |
37
|
|
|
public function renderApplicationComponents($applicationComponents) |
38
|
|
|
{ |
39
|
|
|
foreach ($applicationComponents as $applicationComponent) { |
40
|
|
|
$applicationComponent->{'object'}->render(); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Loop through all (matched) sitemap components and render them |
46
|
|
|
* @param array $matchedSitemapItems |
47
|
|
|
* @throws \Exception |
48
|
|
|
*/ |
49
|
|
|
public function renderSitemapComponents($matchedSitemapItems) |
50
|
|
|
{ |
51
|
|
|
if (!empty($matchedSitemapItems)) { |
52
|
|
|
$this->setCachingHeaders(); |
53
|
|
|
} |
54
|
|
|
foreach ($matchedSitemapItems as $sitemapItem) { |
55
|
|
|
$sitemapItem->object->render($this->application); |
56
|
|
|
ob_clean(); |
57
|
|
|
echo $sitemapItem->object->get(); |
58
|
|
|
ob_end_flush(); |
59
|
|
|
exit; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Set the default caching of pages to 2 days |
65
|
|
|
* @throws \Exception |
66
|
|
|
*/ |
67
|
|
|
public function setCachingHeaders() |
68
|
|
|
{ |
69
|
|
|
$expires = new \DateTime(); |
70
|
|
|
$interval = new \DateInterval('P2D'); // 2 days |
71
|
|
|
$maxAge = date_create('@0')->add($interval)->getTimestamp(); |
72
|
|
|
$expires = $expires->add($interval); |
73
|
|
|
|
74
|
|
|
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', $expires->getTimestamp())); |
75
|
|
|
header('Cache-Control: max-age=' . $maxAge); |
76
|
|
|
} |
77
|
|
|
} |