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