1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the UserGroupRefList 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\REST\Common\Output\ValueObjectVisitor; |
14
|
|
|
use eZ\Publish\Core\REST\Common\Output\Generator; |
15
|
|
|
use eZ\Publish\Core\REST\Common\Output\Visitor; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* UserGroupRefList value object visitor. |
19
|
|
|
*/ |
20
|
|
|
class UserGroupRefList 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 \eZ\Publish\Core\REST\Server\Values\UserGroupRefList $data |
28
|
|
|
*/ |
29
|
|
|
public function visit(Visitor $visitor, Generator $generator, $data) |
30
|
|
|
{ |
31
|
|
|
$generator->startObjectElement('UserGroupRefList'); |
32
|
|
|
$visitor->setHeader('Content-Type', $generator->getMediaType('UserGroupRefList')); |
33
|
|
|
//@todo Needs refactoring, disabling certain headers should not be done this way |
34
|
|
|
$visitor->setHeader('Accept-Patch', false); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$generator->startAttribute('href', $data->path); |
37
|
|
|
$generator->endAttribute('href'); |
38
|
|
|
|
39
|
|
|
$groupCount = count($data->userGroups); |
40
|
|
|
|
41
|
|
|
$generator->startList('UserGroup'); |
42
|
|
|
foreach ($data->userGroups as $userGroup) { |
43
|
|
|
$generator->startObjectElement('UserGroup'); |
44
|
|
|
|
45
|
|
|
$generator->startAttribute( |
46
|
|
|
'href', |
47
|
|
|
$this->router->generate( |
48
|
|
|
'ezpublish_rest_loadUserGroup', |
49
|
|
|
array( |
50
|
|
|
'groupPath' => trim($userGroup->mainLocation->pathString, '/'), |
51
|
|
|
) |
52
|
|
|
) |
53
|
|
|
); |
54
|
|
|
$generator->endAttribute('href'); |
55
|
|
|
|
56
|
|
|
if ($data->userId !== null && $groupCount > 1) { |
57
|
|
|
$generator->startHashElement('unassign'); |
58
|
|
|
|
59
|
|
|
$generator->startAttribute( |
60
|
|
|
'href', |
61
|
|
|
$this->router->generate( |
62
|
|
|
'ezpublish_rest_unassignUserFromUserGroup', |
63
|
|
|
array( |
64
|
|
|
'userId' => $data->userId, |
65
|
|
|
'groupPath' => $userGroup->mainLocation->path[count($userGroup->mainLocation->path) - 1], |
66
|
|
|
) |
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
$generator->endAttribute('href'); |
70
|
|
|
|
71
|
|
|
$generator->startAttribute('method', 'DELETE'); |
72
|
|
|
$generator->endAttribute('method'); |
73
|
|
|
|
74
|
|
|
$generator->endHashElement('unassign'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$generator->endObjectElement('UserGroup'); |
78
|
|
|
} |
79
|
|
|
$generator->endList('UserGroup'); |
80
|
|
|
|
81
|
|
|
$generator->endObjectElement('UserGroupRefList'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: