1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the Policy 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
|
|
|
namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\User\PolicyDraft; |
12
|
|
|
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor; |
13
|
|
|
use eZ\Publish\Core\REST\Common\Output\Generator; |
14
|
|
|
use eZ\Publish\Core\REST\Common\Output\Visitor; |
15
|
|
|
use eZ\Publish\API\Repository\Values\User\Policy as PolicyValue; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Policy value object visitor. |
19
|
|
|
*/ |
20
|
|
|
class Policy extends ValueObjectVisitor |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Visit struct returned by controllers. |
24
|
|
|
* |
25
|
|
|
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor |
26
|
|
|
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator |
27
|
|
|
* @param Policy|PolicyDraft $data |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public function visit(Visitor $visitor, Generator $generator, $data) |
30
|
|
|
{ |
31
|
|
|
$generator->startObjectElement('Policy'); |
32
|
|
|
$visitor->setHeader('Content-Type', $generator->getMediaType($data instanceof PolicyDraft ? 'PolicyDraft' : 'Policy')); |
33
|
|
|
$visitor->setHeader('Accept-Patch', $generator->getMediaType('PolicyUpdate')); |
34
|
|
|
$this->visitPolicyAttributes($visitor, $generator, $data); |
|
|
|
|
35
|
|
|
$generator->endObjectElement('Policy'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function visitPolicyAttributes(Visitor $visitor, Generator $generator, PolicyValue $data) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$generator->startAttribute( |
41
|
|
|
'href', |
42
|
|
|
$this->router->generate('ezpublish_rest_loadPolicy', array('roleId' => $data->roleId, 'policyId' => $data->id)) |
43
|
|
|
); |
44
|
|
|
$generator->endAttribute('href'); |
45
|
|
|
|
46
|
|
|
$generator->startValueElement('id', $data->id); |
47
|
|
|
$generator->endValueElement('id'); |
48
|
|
|
|
49
|
|
|
if ($data instanceof PolicyDraft) { |
50
|
|
|
$generator->startValueElement('originalId', $data->originalId); |
51
|
|
|
$generator->endValueElement('originalId'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$generator->startValueElement('module', $data->module); |
55
|
|
|
$generator->endValueElement('module'); |
56
|
|
|
|
57
|
|
|
$generator->startValueElement('function', $data->function); |
58
|
|
|
$generator->endValueElement('function'); |
59
|
|
|
|
60
|
|
|
$limitations = $data->getLimitations(); |
61
|
|
View Code Duplication |
if (!empty($limitations)) { |
|
|
|
|
62
|
|
|
$generator->startHashElement('limitations'); |
63
|
|
|
$generator->startList('limitation'); |
64
|
|
|
|
65
|
|
|
foreach ($limitations as $limitation) { |
66
|
|
|
$this->visitLimitation($generator, $limitation); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$generator->endList('limitation'); |
70
|
|
|
$generator->endHashElement('limitations'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.