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

Core/REST/Server/Output/ValueObjectVisitor/ContentFieldValidationException.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\API\Repository\Values\Translation;
10 use eZ\Publish\Core\REST\Common\Output\Generator;
11 use eZ\Publish\Core\REST\Common\Output\Visitor;
12
16 class ContentFieldValidationException extends BadRequestException
17 {
25 public function visit(Visitor $visitor, Generator $generator, $data)
26 {
27 $generator->startObjectElement('ErrorMessage');
28
29 $statusCode = $this->getStatus();
30 $visitor->setStatus($statusCode);
31 $visitor->setHeader('Content-Type', $generator->getMediaType('ErrorMessage'));
32
33 $generator->startValueElement('errorCode', $statusCode);
34 $generator->endValueElement('errorCode');
35
36 $generator->startValueElement('errorMessage', $this->httpStatusCodes[$statusCode]);
37 $generator->endValueElement('errorMessage');
38
39 $generator->startValueElement('errorDescription', $data->getMessage());
40 $generator->endValueElement('errorDescription');
41
42 $generator->startHashElement('errorDetails');
43 $generator->startList('fields');
44 foreach ($data->getFieldErrors() as $fieldTypeId => $translations) {
45 foreach ($translations as $languageCode => $validationErrors) {
46 if (!is_array($validationErrors)) {
47 $validationErrors = [$validationErrors];
48 }
49
50 foreach ($validationErrors as $validationError) {
51 $generator->startHashElement('field');
52 $generator->startAttribute('fieldTypeId', $fieldTypeId);
53 $generator->endAttribute('fieldTypeId');
54
55 $generator->startList('errors');
56 $generator->startHashElement('error');
57
58 $generator->startValueElement('type', $validationError->getTarget());
59 $generator->endValueElement('type');
60
61 $translation = $validationError->getTranslatableMessage();
62 $generator->startValueElement(
63 'message',
64 $this->translator->trans(
65 $this->translationToString($translation),
66 $translation->values,
67 'repository_exceptions'
68 )
69 );
70 $generator->endValueElement('message');
71
72 $generator->endHashElement('error');
73 $generator->endList('errors');
74 $generator->endHashElement('field');
75 }
76 }
77 }
78 $generator->endList('fields');
79 $generator->endHashElement('errorDetails');
80
81 if ($this->debug) {
82 $generator->startValueElement('trace', $data->getTraceAsString());
83 $generator->endValueElement('trace');
84
85 $generator->startValueElement('file', $data->getFile());
86 $generator->endValueElement('file');
87
88 $generator->startValueElement('line', $data->getLine());
89 $generator->endValueElement('line');
90 }
91
92 $generator->endObjectElement('ErrorMessage');
93 }
94
102 private function translationToString(Translation $translation)
103 {
104 $values = $translation->values;
105 if ($translation instanceof Translation\Plural) {
106 if (current($values) === 1) {
107 return $translation->singular;
108 } else {
109 return $translation->plural;
110 }
111 } else {
112 return $translation->message;
113 }
114 }
115 }
eZ\Publish\API\Repository\Values\Translation\Plural
Class for translatable messages, which may contain plural forms.
Definition: Plural.php:33
eZ\Publish\API\Repository\Values\Translation
Base class fro translation messages.
Definition: Translation.php:15
eZ\Publish\Core\REST\Common\Output\Generator
Output generator.
Definition: REST/Common/Output/Generator.php:13
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\BadRequestException
BadRequestException value object visitor.
Definition: Output/ValueObjectVisitor/BadRequestException.php:13
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\BadRequestException\getStatus
getStatus()
Returns HTTP status code.
Definition: Output/ValueObjectVisitor/BadRequestException.php:19
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\ContentFieldValidationException
ContentFieldValidationException value object visitor.
Definition: Core/REST/Server/Output/ValueObjectVisitor/ContentFieldValidationException.php:17
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\ContentFieldValidationException\visit
visit(Visitor $visitor, Generator $generator, $data)
Visit struct returned by controllers.
Definition: Core/REST/Server/Output/ValueObjectVisitor/ContentFieldValidationException.php:25
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\ContentFieldValidationException\translationToString
translationToString(Translation $translation)
Convert a Translation object to a string, detecting singular/plural as needed.
Definition: Core/REST/Server/Output/ValueObjectVisitor/ContentFieldValidationException.php:102
eZ\Publish\API\Repository\Values\Translation
Definition: API/Repository/Values/Translation/Message.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+.