1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the ContentList ValueObjectVisitor class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\Core\MVC\ConfigResolverInterface; |
14
|
|
|
use eZ\Publish\Core\MVC\Symfony\RequestStackAware; |
15
|
|
|
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor; |
16
|
|
|
use eZ\Publish\Core\REST\Common\Output\Generator; |
17
|
|
|
use eZ\Publish\Core\REST\Common\Output\Visitor; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* CachedValue value object visitor. |
21
|
|
|
*/ |
22
|
|
|
class CachedValue extends ValueObjectVisitor |
23
|
|
|
{ |
24
|
|
|
use RequestStackAware; |
25
|
|
|
|
26
|
|
|
/** @var ConfigResolverInterface */ |
27
|
|
|
protected $configResolver; |
28
|
|
|
|
29
|
|
|
public function __construct(ConfigResolverInterface $configResolver) |
30
|
|
|
{ |
31
|
|
|
$this->configResolver = $configResolver; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param Visitor $visitor |
36
|
|
|
* @param Generator $generator |
37
|
|
|
* @param \eZ\Publish\Core\REST\Server\Values\CachedValue $data |
38
|
|
|
*/ |
39
|
|
|
public function visit(Visitor $visitor, Generator $generator, $data) |
40
|
|
|
{ |
41
|
|
|
$visitor->visitValueObject($data->value); |
42
|
|
|
|
43
|
|
|
if ($this->getParameter('content.view_cache') !== true) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$response = $visitor->getResponse(); |
48
|
|
|
$response->setPublic(); |
49
|
|
|
$response->setVary('Accept'); |
50
|
|
|
|
51
|
|
|
if ($this->getParameter('content.ttl_cache') === true) { |
52
|
|
|
$response->setSharedMaxAge($this->getParameter('content.default_ttl')); |
53
|
|
|
$request = $this->getCurrentRequest(); |
54
|
|
|
if (isset($request) && $request->headers->has('X-User-Hash')) { |
55
|
|
|
$response->setVary('X-User-Hash', false); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (!empty($data->cacheTags)) { |
60
|
|
|
// See doc/specifications/cache/multi_tagging.md |
61
|
|
|
$tags = []; |
62
|
|
|
foreach ($data->cacheTags as $tag => $values) { |
63
|
|
|
foreach ((array)$values as $value) { |
64
|
|
|
$tags[] = $tag . '-'. $value; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$response->headers->set( |
69
|
|
|
'xkey', |
70
|
|
|
$tags |
71
|
|
|
false |
|
|
|
|
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getParameter($parameterName, $defaultValue = null) |
77
|
|
|
{ |
78
|
|
|
if ($this->configResolver->hasParameter($parameterName)) { |
79
|
|
|
return $this->configResolver->getParameter($parameterName); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $defaultValue; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|