Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Output/ValueObjectVisitor/UserSession.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
8
9 use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
10 use eZ\Publish\Core\REST\Common\Output\Generator;
11 use eZ\Publish\Core\REST\Common\Output\Visitor;
12 use eZ\Publish\Core\REST\Server\Values\UserSession as UserSessionValue;
13
17 class UserSession extends ValueObjectVisitor
18 {
26 public function visit(Visitor $visitor, Generator $generator, $data)
27 {
28 $status = $data->created ? 201 : 200;
29 $visitor->setStatus($status);
30
31 $visitor->setHeader('Content-Type', $generator->getMediaType('Session'));
32 //@todo Needs refactoring, disabling certain headers should not be done this way
33 $visitor->setHeader('Accept-Patch', false);
34
35 $generator->startObjectElement('Session');
36 $this->visitUserSessionAttributes($visitor, $generator, $data);
37 $generator->endObjectElement('Session');
38 }
39
40 protected function visitUserSessionAttributes(Visitor $visitor, Generator $generator, UserSessionValue $data)
41 {
42 $sessionHref = $this->router->generate('ezpublish_rest_deleteSession', ['sessionId' => $data->sessionId]);
43
44 $generator->startAttribute('href', $sessionHref);
45 $generator->endAttribute('href');
46
47 $generator->startValueElement('name', $data->sessionName);
48 $generator->endValueElement('name');
49
50 $generator->startValueElement('identifier', $data->sessionId);
51 $generator->endValueElement('identifier');
52
53 $generator->startValueElement('csrfToken', $data->csrfToken);
54 $generator->endValueElement('csrfToken');
55
56 $generator->startObjectElement('User', 'User');
57 $generator->startAttribute(
58 'href',
59 $this->router->generate('ezpublish_rest_loadUser', ['userId' => $data->user->id])
60 );
61 $generator->endAttribute('href');
62 $generator->endObjectElement('User');
63 }
64 }
eZ\Publish\Core\REST\Common\Output\Generator
Output generator.
Definition: REST/Common/Output/Generator.php:13
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor
Basic ValueObjectVisitor.
Definition: ValueObjectVisitor.php:18
eZ\Publish\Core\REST\Common\Output\Visitor
Visits a value object into an HTTP Response.
Definition: Visitor.php:15
eZ\Publish\Core\REST\Common\Output\Visitor\setStatus
setStatus($statusCode)
Sets the given status code in the corresponding header.
Definition: Visitor.php:78
eZ\Publish\Core\REST\Common\Output\Visitor\setHeader
setHeader($name, $value)
Set HTTP response header.
Definition: Visitor.php:64
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\UserSession
UserSession value object visitor.
Definition: Output/ValueObjectVisitor/UserSession.php:18
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\UserSession\visit
visit(Visitor $visitor, Generator $generator, $data)
Visit struct returned by controllers.
Definition: Output/ValueObjectVisitor/UserSession.php:26
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\UserSession\visitUserSessionAttributes
visitUserSessionAttributes(Visitor $visitor, Generator $generator, UserSessionValue $data)
Definition: Output/ValueObjectVisitor/UserSession.php:40
eZ\Publish\Core\REST\Server\Values\UserSession
User list view model.
Definition: Values/UserSession.php:16
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor
Definition: Common/Output/ValueObjectVisitor/ContentObjectStates.php:7
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor
Definition: Output/ValueObjectVisitor/BadRequestException.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.