@@ -57,21 +57,26 @@ class HTTPRequest implements Comparable
57
57
*
58
58
* @var mixed
59
59
*/
60
- public $ body = NULL ;
60
+ public $ body = null ;
61
61
62
62
/**
63
- * Identifier for the request.
63
+ * Schema of the body of the request (if POST or PUT) .
64
64
*
65
- * @var string
65
+ * @var mixed
66
66
*/
67
- protected $ id ;
68
-
67
+ public $ body_schema = null ;
69
68
/**
70
69
* Structure of the request (if POST or PUT).
71
70
*
72
71
* @var RequestBodyElement
73
72
*/
74
73
public $ struct = [];
74
+ /**
75
+ * Identifier for the request.
76
+ *
77
+ * @var string
78
+ */
79
+ protected $ id ;
75
80
76
81
/**
77
82
* HTTPRequest constructor.
@@ -94,21 +99,38 @@ public function __construct(Transition &$parent)
94
99
public function parse (stdClass $ object ): self
95
100
{
96
101
$ this ->method = $ object ->attributes ->method ->content ?? $ object ->attributes ->method ;
97
- $ this ->title = isset ($ object ->meta ->title ) ? $ object ->meta ->title : NULL ;
102
+ $ this ->title = isset ($ object ->meta ->title ) ? $ object ->meta ->title : null ;
98
103
99
104
if (($ this ->method === 'POST ' || $ this ->method === 'PUT ' ) && !empty ($ object ->content )) {
100
105
foreach ($ object ->content as $ value ) {
101
106
if ($ value ->element === 'dataStructure ' ) {
102
107
$ this ->parse_structure ($ value );
103
108
continue ;
104
- } elseif ($ value ->element === 'copy ' ) {
109
+ }
110
+
111
+ if ($ value ->element === 'copy ' ) {
105
112
$ this ->description = MarkdownExtra::defaultTransform (htmlentities ($ value ->content ));
106
- } elseif ($ value ->element === 'asset ' ) {
107
- if (in_array ('messageBody ' , $ value ->meta ->classes )) {
108
- $ this ->body [] = (isset ($ value ->content )) ? $ value ->content : NULL ;
109
- $ this ->headers ['Content-Type ' ] =
110
- (isset ($ value ->attributes ->contentType )) ? $ value ->attributes ->contentType : '' ;
111
- }
113
+ continue ;
114
+ }
115
+
116
+ if ($ value ->element !== 'asset ' ) {
117
+ continue ;
118
+ }
119
+ if (is_array ($ value ->meta ->classes ) && in_array ('messageBody ' , $ value ->meta ->classes )) {
120
+ $ this ->body [] = (isset ($ value ->content )) ? $ value ->content : null ;
121
+ $ this ->headers ['Content-Type ' ] = (isset ($ value ->attributes ->contentType )) ? $ value ->attributes ->contentType : '' ;
122
+ continue ;
123
+ }
124
+
125
+ if (isset ($ value ->meta ->classes ->content )
126
+ && is_array ($ value ->meta ->classes ->content )
127
+ && $ value ->meta ->classes ->content [0 ]->content === 'messageBody ' ) {
128
+ $ this ->body [] = (isset ($ value ->content )) ? $ value ->content : null ;
129
+ $ this ->headers ['Content-Type ' ] = (isset ($ value ->attributes ->contentType ->content )) ? $ value ->attributes ->contentType ->content : '' ;
130
+ } elseif (isset ($ value ->meta ->classes ->content )
131
+ && is_array ($ value ->meta ->classes ->content )
132
+ && $ value ->meta ->classes ->content [0 ]->content === 'messageBodySchema ' ) {
133
+ $ this ->body_schema = (isset ($ value ->content )) ? $ value ->content : null ;
112
134
}
113
135
}
114
136
}
@@ -119,7 +141,7 @@ public function parse(stdClass $object): self
119
141
}
120
142
}
121
143
122
- if ($ this ->body === NULL ) {
144
+ if ($ this ->body === null ) {
123
145
$ this ->body = &$ this ->struct ;
124
146
}
125
147
@@ -152,15 +174,15 @@ public function get_id(): string
152
174
* @param string $base_url URL to the base server
153
175
* @param array $additional Extra options to pass to cURL
154
176
*
177
+ * @return string An executable cURL command
155
178
* @throws Exception
156
179
*
157
- * @return string An executable cURL command
158
180
*/
159
181
public function get_curl_command (string $ base_url , array $ additional = []): string
160
182
{
161
183
$ options = [];
162
184
163
- $ type = $ this ->headers ['Content-Type ' ] ?? NULL ;
185
+ $ type = $ this ->headers ['Content-Type ' ] ?? null ;
164
186
165
187
$ options [] = '-X ' . $ this ->method ;
166
188
if (empty ($ this ->body )) {
@@ -171,6 +193,9 @@ public function get_curl_command(string $base_url, array $additional = []): stri
171
193
$ options [] = '--data-binary ' . escapeshellarg (join ('' , $ this ->body ));
172
194
} elseif (is_subclass_of ($ this ->struct , StructureElement::class)) {
173
195
foreach ($ this ->struct ->value as $ body ) {
196
+ if (empty ($ body )) {
197
+ continue ;
198
+ }
174
199
$ options [] = '--data-binary ' . escapeshellarg (strip_tags ($ body ->print_request ($ type )));
175
200
}
176
201
}
@@ -179,7 +204,8 @@ public function get_curl_command(string $base_url, array $additional = []): stri
179
204
}
180
205
$ options = array_merge ($ options , $ additional );
181
206
182
- return htmlspecialchars ('curl ' . join (' ' , $ options ) . ' ' . escapeshellarg ($ this ->parent ->build_url ($ base_url , TRUE )));
207
+ return htmlspecialchars ('curl ' . join (' ' , $ options ) . ' ' . escapeshellarg ($ this ->parent ->build_url ($ base_url ,
208
+ true )));
183
209
}
184
210
185
211
/**
@@ -200,17 +226,17 @@ public function is_equal_to($b): bool
200
226
* @param string $base_url URL to the base server
201
227
* @param array $additional Extra options to pass to the service
202
228
*
229
+ * @return string
203
230
* @throws Exception
204
231
*
205
- * @return string
206
232
*/
207
233
public function get_hurl_link (string $ base_url , array $ additional = []): string
208
234
{
209
235
$ options = [];
210
236
211
- $ type = (isset ($ this ->headers ['Content-Type ' ])) ? $ this ->headers ['Content-Type ' ] : NULL ;
237
+ $ type = (isset ($ this ->headers ['Content-Type ' ])) ? $ this ->headers ['Content-Type ' ] : null ;
212
238
213
- $ url = $ this ->parent ->build_url ($ base_url , TRUE );
239
+ $ url = $ this ->parent ->build_url ($ base_url , true );
214
240
$ url = explode ('? ' , $ url );
215
241
if (isset ($ url [1 ])) {
216
242
$ params = [];
0 commit comments