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

common.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST;
8
9 use eZ\Publish\Core\FieldType;
10
11 if (!defined('HTTP_BASE_URL')) {
12 define('HTTP_BASE_URL', 'http://localhost:8042/');
13 }
14
15 /*
16 * This file includes the configuration of the REST SDK client.
17 *
18 * This is a client configuration for testing purposes only.
19 */
20
21 // Set communication encoding depending on environment defined in the
22 // phpunit.xml files. This defines what encoding will be generated and thus send
23 // to the server.
24 $generator = getenv('backendEncoding') === 'xml' ?
25 new Common\Output\Generator\Xml(
26 new Common\Output\Generator\Xml\FieldTypeHashGenerator()
27 ) :
28 new Common\Output\Generator\Json(
29 new Common\Output\Generator\Json\FieldTypeHashGenerator()
30 );
31
32 // The URL Handler is responsible for URL parsing and generation. It will be
33 // used in the output generators and in some parsing handlers.
34 $requestParser = new Common\RequestParser\EzPublish();
35
36 // FieldTypes to be used in integration tests. The field types are only used
37 // in terms of conversions from and to hash values.
38 $fieldTypes = [
39 new Client\FieldType(new FieldType\Author\Type()),
40 new Client\FieldType(new FieldType\Checkbox\Type()),
41 new Client\FieldType(new FieldType\DateAndTime\Type()),
42 new Client\FieldType(new FieldType\Float\Type()),
43 new Client\FieldType(new FieldType\Integer\Type()),
44 new Client\FieldType(new FieldType\Keyword\Type()),
45 new Client\FieldType(new FieldType\MapLocation\Type()),
46 new Client\FieldType(new FieldType\Relation\Type()),
47 new Client\FieldType(new FieldType\RelationList\Type()),
48 new Client\FieldType(new FieldType\Selection\Type()),
49 new Client\FieldType(new FieldType\TextBlock\Type()),
50 new Client\FieldType(new FieldType\TextLine\Type()),
51 new Client\FieldType(new FieldType\Url\Type()),
52 new Client\FieldType(new FieldType\User\Type()),
53 new Client\FieldType(new FieldType\Null\Type('ezpage')), // @todo FIXME: Add correct type
54 ];
55
56 // The IntegrationTestRepository is only meant for integration tests. It
57 // handles sessions which run throughout a single test case run and submission
58 // of user information to the server, which needs a corresponding
59 // authenticator.
60 $repository = new Client\IntegrationTestRepository(
61 // The HTTP Client. Needs to implement the Client\HttpClient interface.
62 //
63 // We are using a test client here, so that we maintain a consistent session during each test case
64 // and submit user information to the server.
65 $authenticator = new Client\HttpClient\Authentication\IntegrationTestAuthenticator(
66 new Client\HttpClient\Stream(
67 // Server address to communicate with. You might want to make this
68 // configurable using environment variables, or something alike.
69 HTTP_BASE_URL
70 )
71 ),
72 new Common\Input\Dispatcher(
73 // The parsing dispatcher is configured after the repository has been
74 // created due to circular references
75 $parsingDispatcher = new Common\Input\ParsingDispatcher(),
76 [
77 // Defines the available data format encoding handlers. used to
78 // process the input data and convert it into an array structure
79 // usable by the parsers.
80 //
81 // More generators should not be necessary to configure, unless new transport
82 // encoding formats need to be supported.
83 'json' => new Common\Input\Handler\Json(),
84 'xml' => new Common\Input\Handler\Xml(),
85 ]
86 ),
87 new Common\Output\Visitor(
88 // The generator defines what transport encoding format will be used.
89 // This should either be the XML or JSON generator. In this case we use
90 // a generator depending on an environment variable, as defined above.
91 $generator,
92 // The defined output visitors for the available value objects.
93 //
94 // If there is new data available, which should be visited and send to
95 // the server extend this array. It always maps the class name of the
96 // value object (or its parent class(es)) to the respective visitor
97 // implementation instance.
98 [
99 '\\eZ\\Publish\\API\\Repository\\Values\\Content\\SectionCreateStruct' => new Client\Output\ValueObjectVisitor\SectionCreateStruct($requestParser),
100 '\\eZ\\Publish\\API\\Repository\\Values\\Content\\SectionUpdateStruct' => new Client\Output\ValueObjectVisitor\SectionUpdateStruct($requestParser),
101 '\\eZ\\Publish\\Core\\REST\\Common\\Values\\SectionIncludingContentMetadataUpdateStruct' => new Client\Output\ValueObjectVisitor\SectionIncludingContentMetadataUpdateStruct($requestParser),
102 '\\eZ\\Publish\\API\\Repository\\Values\\User\\RoleCreateStruct' => new Client\Output\ValueObjectVisitor\RoleCreateStruct($requestParser),
103 '\\eZ\\Publish\\API\\Repository\\Values\\User\\RoleUpdateStruct' => new Client\Output\ValueObjectVisitor\RoleUpdateStruct($requestParser),
104 '\\eZ\\Publish\\API\\Repository\\Values\\User\\PolicyCreateStruct' => new Client\Output\ValueObjectVisitor\PolicyCreateStruct($requestParser),
105 '\\eZ\\Publish\\API\\Repository\\Values\\User\\Limitation' => new Client\Output\ValueObjectVisitor\Limitation($requestParser),
106 '\\eZ\\Publish\\API\\Repository\\Values\\User\\PolicyUpdateStruct' => new Client\Output\ValueObjectVisitor\PolicyUpdateStruct($requestParser),
107 '\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationCreateStruct' => new Client\Output\ValueObjectVisitor\LocationCreateStruct($requestParser),
108 '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroupCreateStruct' => new Client\Output\ValueObjectVisitor\ObjectStateGroupCreateStruct($requestParser),
109 '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroupUpdateStruct' => new Client\Output\ValueObjectVisitor\ObjectStateGroupUpdateStruct($requestParser),
110 '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateCreateStruct' => new Client\Output\ValueObjectVisitor\ObjectStateCreateStruct($requestParser),
111 '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateUpdateStruct' => new Client\Output\ValueObjectVisitor\ObjectStateUpdateStruct($requestParser),
112 ]
113 ),
114 $requestParser,
115 $fieldTypes,
116 $authenticator
117 );
118
119 // Object with convenience methods for parsers
120 $parserTools = new Common\Input\ParserTools();
121
122 // Parser for field values (using FieldTypes for toHash()/fromHash() operations)
123 $fieldTypeParser = new Common\Input\FieldTypeParser(
124 $repository->getContentService(),
125 $repository->getContentTypeService(),
126 $repository->getFieldTypeService(),
127 new Common\FieldTypeProcessorRegistry()
128 );
129
130 // The parsing dispatcher configures which parsers are used for which
131 // mime type. The mime types (content types) are provided *WITHOUT* an
132 // encoding type (+json / +xml).
133 //
134 // For each mime type you specify an instance of the parser which
135 // should be used to process the given mime type.
136 $inputParsers = [
137 'application/vnd.ez.api.Version' => new Client\Input\Parser\Content(
138 $parserTools,
139 $repository->getContentService(),
140 // Circular reference, since REST does not transmit content info when
141 // loading the VersionInfo (which is included in the content)
142 new Client\Input\Parser\VersionInfo($parserTools, $repository->getContentService()),
143 $fieldTypeParser
144 ),
145 'application/vnd.ez.api.ContentList' => new Client\Input\Parser\ContentList(),
146 'application/vnd.ez.api.ContentInfo' => new Client\Input\Parser\ContentInfo(
147 $parserTools,
148 $repository->getContentTypeService()
149 ),
150 'application/vnd.ez.api.ContentType' => new Client\Input\Parser\ContentType(
151 $parserTools,
152 $repository->getContentTypeService()
153 ),
154 'application/vnd.ez.api.FieldDefinitionList' => new Client\Input\Parser\FieldDefinitionList(
155 $parserTools,
156 $repository->getContentTypeService()
157 ),
158 'application/vnd.ez.api.FieldDefinition' => new Client\Input\Parser\FieldDefinition(
159 $parserTools,
160 $fieldTypeParser
161 ),
162 'application/vnd.ez.api.SectionList' => new Client\Input\Parser\SectionList(),
163 'application/vnd.ez.api.Section' => new Client\Input\Parser\Section(),
164 'application/vnd.ez.api.ErrorMessage' => new Client\Input\Parser\ErrorMessage(),
165 'application/vnd.ez.api.RoleList' => new Client\Input\Parser\RoleList(),
166 'application/vnd.ez.api.Role' => new Client\Input\Parser\Role(),
167 'application/vnd.ez.api.Policy' => new Client\Input\Parser\Policy(),
168 'application/vnd.ez.api.limitation' => new Client\Input\Parser\Limitation(),
169 'application/vnd.ez.api.PolicyList' => new Client\Input\Parser\PolicyList(),
170 'application/vnd.ez.api.RelationList' => new Client\Input\Parser\RelationList(),
171 'application/vnd.ez.api.Relation' => new Client\Input\Parser\Relation(
172 $repository->getContentService()
173 ),
174 'application/vnd.ez.api.RoleAssignmentList' => new Client\Input\Parser\RoleAssignmentList(),
175 'application/vnd.ez.api.RoleAssignment' => new Client\Input\Parser\RoleAssignment(),
176 'application/vnd.ez.api.Location' => new Client\Input\Parser\Location(
177 $parserTools
178 ),
179 'application/vnd.ez.api.LocationList' => new Client\Input\Parser\LocationList(),
180 'application/vnd.ez.api.ObjectStateGroup' => new Client\Input\Parser\ObjectStateGroup(
181 $parserTools
182 ),
183 'application/vnd.ez.api.ObjectStateGroupList' => new Client\Input\Parser\ObjectStateGroupList(),
184 'application/vnd.ez.api.ObjectState' => new Client\Input\Parser\ObjectState(
185 $parserTools
186 ),
187 'application/vnd.ez.api.ObjectStateList' => new Client\Input\Parser\ObjectStateList(),
188 ];
189 foreach ($inputParsers as $mimeType => $parser) {
190 $parsingDispatcher->addParser($mimeType, $parser);
191 }
192
193 // Force sets the used user. This will be refactored most likely, since this is
194 // not really valid for a REST client.
195 /*
196 Code commented while implementing EZP-21168, the stubs are removed.
197
198 $repository->setCurrentUser(
199 new \eZ\Publish\API\Repository\Tests\Stubs\Values\User\UserStub(
200 array(
201 'content' => new \eZ\Publish\API\Repository\Tests\Stubs\Values\Content\ContentStub(
202 array(
203 'id' => 14
204 )
205 )
206 )
207 )
208 );
209 */
210
211 return $repository;
eZ\Publish\API\Repository\Values\ContentType\ContentType
Definition: API/Repository/Values/ContentType/ContentType.php:36
eZ\Publish\API\Repository\Values\ContentType\FieldDefinition
Definition: API/Repository/Values/ContentType/FieldDefinition.php:31
eZ\Publish\API\Repository\Values\Content\ContentInfo
Definition: API/Repository/Values/Content/ContentInfo.php:31
eZ\Publish\API\Repository\Values\Content\Content
Definition: Publish/API/Repository/Values/Content/Content.php:21
eZ\Publish\API\Repository\Values\Content\Location
Definition: API/Repository/Values/Content/Location.php:32
eZ\Publish\API\Repository\Values\Content\RelationList
List of relations.
Definition: API/Repository/Values/Content/RelationList.php:20
eZ\Publish\API\Repository\Values\Content\Relation
Definition: API/Repository/Values/Content/Relation.php:21
eZ\Publish\API\Repository\Values\Content\Section
Definition: API/Repository/Values/Content/Section.php:19
eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup
Definition: API/Repository/Values/ObjectState/ObjectStateGroup.php:22
eZ\Publish\API\Repository\Values\ObjectState\ObjectState
Definition: API/Repository/Values/ObjectState/ObjectState.php:23
eZ\Publish\API\Repository\Values\User\Role
Definition: API/Repository/Values/User/Role.php:19
eZ\Publish\Core\FieldType\FieldType
Base class for field types, the most basic storage unit of data inside eZ Publish.
Definition: Core/FieldType/FieldType.php:35
eZ\Publish\Core\Persistence\TransformationProcessor\DefinitionBased\Parser
Parser for transformation specifications.
Definition: Persistence/TransformationProcessor/DefinitionBased/Parser.php:35
eZ\Publish\Core\REST\Client\FieldType
Definition: Core/REST/Client/FieldType.php:15
eZ\Publish\Core\REST\Client\Input\Parser\ContentList
Parser for ContentList.
Definition: Client/Input/Parser/ContentList.php:16
eZ\Publish\Core\REST\Client\Input\Parser\ErrorMessage
Parser for ErrorMessage.
Definition: Input/Parser/ErrorMessage.php:18
eZ\Publish\Core\REST\Client\Input\Parser\FieldDefinitionList
Parser for FieldDefinitionList.
Definition: Client/Input/Parser/FieldDefinitionList.php:19
eZ\Publish\Core\REST\Client\Input\Parser\Limitation
Parser for Limitation.
Definition: Core/REST/Client/Input/Parser/Limitation.php:17
eZ\Publish\Core\REST\Client\Input\Parser\LocationList
Parser for LocationList.
Definition: Core/REST/Client/Input/Parser/LocationList.php:16
eZ\Publish\Core\REST\Client\Input\Parser\ObjectStateGroupList
Parser for ObjectStateGroupList.
Definition: Client/Input/Parser/ObjectStateGroupList.php:16
eZ\Publish\Core\REST\Client\Input\Parser\ObjectStateList
Parser for ObjectStateList.
Definition: Client/Input/Parser/ObjectStateList.php:16
eZ\Publish\Core\REST\Client\Input\Parser\PolicyList
Parser for PolicyList.
Definition: Client/Input/Parser/PolicyList.php:16
eZ\Publish\Core\REST\Client\Input\Parser\Policy
Parser for Policy.
Definition: Core/REST/Client/Input/Parser/Policy.php:17
eZ\Publish\Core\REST\Client\Input\Parser\RoleAssignmentList
Parser for RoleAssignmentList.
Definition: Client/Input/Parser/RoleAssignmentList.php:16
eZ\Publish\Core\REST\Client\Input\Parser\RoleAssignment
Parser for RoleAssignment.
Definition: Core/REST/Client/Input/Parser/RoleAssignment.php:18
eZ\Publish\Core\REST\Client\Input\Parser\RoleList
Parser for RoleList.
Definition: Client/Input/Parser/RoleList.php:16
eZ\Publish\Core\REST\Client\Input\Parser\SectionList
Parser for SectionList.
Definition: Client/Input/Parser/SectionList.php:16
eZ\Publish\Core\REST\Client\IntegrationTestRepository
REST Client Repository to be used in integration tests.
Definition: IntegrationTestRepository.php:23
eZ\Publish\Core\REST\Common\Input\FieldTypeParser
Definition: FieldTypeParser.php:15
eZ\Publish\Core\REST\Common\Input\ParserTools
Tools object to be used in Input Parsers.
Definition: ParserTools.php:17
eZ\Publish\SPI\Persistence\Content\VersionInfo
This class holds version information data.
Definition: SPI/Persistence/Content/VersionInfo.php:15
eZ\Publish\Core\REST\$inputParsers
$inputParsers
Definition: common.php:136
eZ\Publish\Core\REST\$fieldTypeParser
$fieldTypeParser
Definition: common.php:123
eZ\Publish\Core\REST\$fieldTypes
$fieldTypes
Definition: common.php:38
eZ\Publish\Core\REST\$parserTools
$parserTools
Definition: common.php:120
eZ\Publish\Core\REST\$requestParser
$requestParser
Definition: common.php:34
eZ\Publish\Core\FieldType\Handler
Field type handler interface.
Definition: Core/FieldType/Handler.php:16
eZ\Bundle\EzPublishRestBundle\Features\Context\SubContext\Authentication
trait Authentication
Definition: Authentication.php:10
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.