1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the UserSession 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\Core\REST\Common\Output\ValueObjectVisitor; |
12
|
|
|
use eZ\Publish\Core\REST\Common\Output\Generator; |
13
|
|
|
use eZ\Publish\Core\REST\Common\Output\Visitor; |
14
|
|
|
use eZ\Publish\Core\REST\Server\Values\UserSession as UserSessionValue; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* UserSession value object visitor. |
18
|
|
|
*/ |
19
|
|
|
class UserSession extends ValueObjectVisitor |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Visit struct returned by controllers. |
23
|
|
|
* |
24
|
|
|
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor |
25
|
|
|
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator |
26
|
|
|
* @param \eZ\Publish\Core\REST\Server\Values\UserSession $data |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
public function visit(Visitor $visitor, Generator $generator, $data) |
29
|
|
|
{ |
30
|
|
|
$status = $data->created ? 201 : 200; |
|
|
|
|
31
|
|
|
$visitor->setStatus($status); |
32
|
|
|
|
33
|
|
|
$visitor->setHeader('Content-Type', $generator->getMediaType('Session')); |
34
|
|
|
//@todo Needs refactoring, disabling certain headers should not be done this way |
35
|
|
|
$visitor->setHeader('Accept-Patch', false); |
36
|
|
|
|
37
|
|
|
$generator->startObjectElement('Session'); |
38
|
|
|
$this->visitUserSessionAttributes($visitor, $generator, $data); |
39
|
|
|
$generator->endObjectElement('Session'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function visitUserSessionAttributes(Visitor $visitor, Generator $generator, UserSessionValue $data) |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$sessionHref = $this->router->generate('ezpublish_rest_deleteSession', array('sessionId' => $data->sessionId)); |
45
|
|
|
|
46
|
|
|
$generator->startAttribute('href', $sessionHref); |
47
|
|
|
$generator->endAttribute('href'); |
48
|
|
|
|
49
|
|
|
$generator->startValueElement('name', $data->sessionName); |
50
|
|
|
$generator->endValueElement('name'); |
51
|
|
|
|
52
|
|
|
$generator->startValueElement('identifier', $data->sessionId); |
53
|
|
|
$generator->endValueElement('identifier'); |
54
|
|
|
|
55
|
|
|
$generator->startValueElement('csrfToken', $data->csrfToken); |
56
|
|
|
$generator->endValueElement('csrfToken'); |
57
|
|
|
|
58
|
|
|
$generator->startObjectElement('User', 'User'); |
59
|
|
|
$generator->startAttribute( |
60
|
|
|
'href', |
61
|
|
|
$this->router->generate('ezpublish_rest_loadUser', array('userId' => $data->user->id)) |
62
|
|
|
); |
63
|
|
|
$generator->endAttribute('href'); |
64
|
|
|
$generator->endObjectElement('User'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.