Skip to content

Commit 1b6f903

Browse files
Copilotanderly
andcommitted
Add IODataResponse interface and update all return types
Co-authored-by: anderly <[email protected]>
1 parent 3cfd603 commit 1b6f903

File tree

6 files changed

+112
-43
lines changed

6 files changed

+112
-43
lines changed

src/IODataClient.php

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,68 +88,81 @@ public function query();
8888
* @param $requestUri
8989
* @param array $bindings
9090
*
91-
* @return IODataRequest
91+
* @return IODataResponse
9292
*/
9393
public function get($requestUri, $bindings = []);
9494

9595
/**
96-
* Run a GET HTTP request against the service.
96+
* Run a POST request against the service.
9797
*
98-
* @param $requestUri
99-
* @param array $bindings
98+
* @param string $requestUri
99+
* @param mixed $postData
100100
*
101-
* @return IODataRequest
101+
* @return IODataResponse
102102
*/
103-
public function getNextPage($requestUri, $bindings = []);
103+
public function post($requestUri, $postData);
104104

105105
/**
106-
* Run a GET HTTP request against the service and return a generator
106+
* Run a PATCH request against the service.
107107
*
108-
* @param $requestUri
109-
* @param array $bindings
108+
* @param string $requestUri
109+
* @param mixed $body
110110
*
111-
* @return IODataRequest
111+
* @return IODataResponse
112112
*/
113-
public function cursor($requestUri, $bindings = []);
113+
public function patch($requestUri, $body);
114114

115115
/**
116-
* Run a POST request against the service.
116+
* Run a DELETE request against the service.
117117
*
118118
* @param string $requestUri
119-
* @param mixed $postData
120119
*
121-
* @return IODataRequest
120+
* @return IODataResponse
122121
*/
123-
public function post($requestUri, $postData);
122+
public function delete($requestUri);
124123

125124
/**
126-
* Run a PUT request against the service.
125+
* Return an ODataRequest
127126
*
127+
* @param string $method
128128
* @param string $requestUri
129129
* @param mixed $body
130130
*
131-
* @return IODataRequest
131+
* @return IODataResponse
132+
*
133+
* @throws ODataException
132134
*/
133-
public function put($requestUri, $body);
135+
public function request($method, $requestUri, $body = null);
134136

135137
/**
136-
* Run a PATCH request against the service.
138+
* Run a GET HTTP request against the service.
137139
*
138-
* @param string $requestUri
139-
* @param mixed $body
140+
* @param $requestUri
141+
* @param array $bindings
140142
*
141-
* @return IODataRequest
143+
* @return IODataResponse
142144
*/
143-
public function patch($requestUri, $body);
145+
public function getNextPage($requestUri, $bindings = []);
144146

145147
/**
146-
* Run a DELETE request against the service.
148+
* Run a GET HTTP request against the service and return a generator
149+
*
150+
* @param $requestUri
151+
* @param array $bindings
152+
*
153+
* @return IODataResponse
154+
*/
155+
public function cursor($requestUri, $bindings = []);
156+
157+
/**
158+
* Run a PUT request against the service.
147159
*
148160
* @param string $requestUri
161+
* @param mixed $body
149162
*
150-
* @return IODataRequest
163+
* @return IODataResponse
151164
*/
152-
public function delete($requestUri);
165+
public function put($requestUri, $body);
153166

154167
/**
155168
* Get the query grammar used by the connection.

src/IODataResponse.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace SaintSystems\OData;
4+
5+
interface IODataResponse
6+
{
7+
/**
8+
* Get the decoded body of the HTTP response
9+
*
10+
* @var array The decoded body
11+
*/
12+
public function getBody();
13+
14+
/**
15+
* Get the undecoded body of the HTTP response
16+
*
17+
* @var string The undecoded body
18+
*/
19+
public function getRawBody();
20+
21+
/**
22+
* Get the status of the HTTP response
23+
*
24+
* @var string The HTTP status
25+
*/
26+
public function getStatus();
27+
28+
/**
29+
* Get the headers of the response
30+
*
31+
* @var array The response headers
32+
*/
33+
public function getHeaders();
34+
35+
/**
36+
* Converts the response JSON object to a OData SDK object
37+
*
38+
* @param mixed $returnType The type to convert the object(s) to
39+
*
40+
* @return mixed object or array of objects of type $returnType
41+
*/
42+
public function getResponseAsObject($returnType);
43+
44+
/**
45+
* Gets the skip token of a response object from OData
46+
*
47+
* @return string skip token, if provided
48+
*/
49+
public function getSkipToken();
50+
51+
/**
52+
* Gets the Id of response object (if set) from OData
53+
*
54+
* @return mixed id if this was an insert, if provided
55+
*/
56+
public function getId();
57+
}

src/ODataClient.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function query()
242242
* @param string $requestUri
243243
* @param array $bindings
244244
*
245-
* @return IODataRequest
245+
* @return IODataResponse
246246
*/
247247
public function get($requestUri, $bindings = [])
248248
{
@@ -256,7 +256,7 @@ public function get($requestUri, $bindings = [])
256256
* @param string $requestUri
257257
* @param array $bindings
258258
*
259-
* @return IODataRequest
259+
* @return IODataResponse
260260
*/
261261
public function getNextPage($requestUri, $bindings = [])
262262
{
@@ -295,7 +295,7 @@ public function cursor($requestUri, $bindings = [])
295295
* @param string $requestUri
296296
* @param mixed $postData
297297
*
298-
* @return IODataRequest
298+
* @return IODataResponse
299299
*/
300300
public function post($requestUri, $postData)
301301
{
@@ -308,7 +308,7 @@ public function post($requestUri, $postData)
308308
* @param string $requestUri
309309
* @param mixed $body
310310
*
311-
* @return IODataRequest
311+
* @return IODataResponse
312312
*/
313313
public function put($requestUri, $body)
314314
{
@@ -321,7 +321,7 @@ public function put($requestUri, $body)
321321
* @param string $requestUri
322322
* @param mixed $body
323323
*
324-
* @return IODataRequest
324+
* @return IODataResponse
325325
*/
326326
public function patch($requestUri, $body)
327327
{
@@ -333,7 +333,7 @@ public function patch($requestUri, $body)
333333
*
334334
* @param string $requestUri
335335
*
336-
* @return IODataRequest
336+
* @return IODataResponse
337337
*/
338338
public function delete($requestUri)
339339
{
@@ -363,7 +363,7 @@ protected function createRequest($method, $requestUri)
363363
* @param string $requestUri
364364
* @param mixed $body
365365
*
366-
* @return IODataRequest
366+
* @return IODataResponse
367367
*
368368
* @throws ODataException
369369
*/

src/ODataResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @package SaintSystems.OData
2626
* @license https://opensource.org/licenses/MIT MIT License
2727
*/
28-
class ODataResponse
28+
class ODataResponse implements IODataResponse
2929
{
3030
/**
3131
* The request

src/Query/Builder.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use SaintSystems\OData\Constants;
1010
use SaintSystems\OData\Exception\ODataQueryException;
1111
use SaintSystems\OData\IODataClient;
12-
use SaintSystems\OData\IODataRequest;
1312
use SaintSystems\OData\QueryOptions;
1413

1514
class Builder
@@ -1168,7 +1167,7 @@ public function patch($body, $properties = [], $options = null)
11681167
/**
11691168
* Run the query as a "GET" request against the client.
11701169
*
1171-
* @return IODataRequest
1170+
* @return IODataResponse
11721171
*/
11731172
protected function runGet()
11741173
{
@@ -1216,7 +1215,7 @@ public function cursor()
12161215
/**
12171216
* Run the query as a "PATCH" request against the client.
12181217
*
1219-
* @return IODataRequest
1218+
* @return IODataResponse
12201219
*/
12211220
protected function runPatch($body)
12221221
{
@@ -1239,7 +1238,7 @@ protected function runPatch($body)
12391238
/**
12401239
* Run the query as a "POST" request against the client.
12411240
*
1242-
* @return IODataRequest
1241+
* @return IODataResponse
12431242
*/
12441243
protected function runPost($body)
12451244
{
@@ -1262,7 +1261,7 @@ protected function runPost($body)
12621261
/**
12631262
* Run the query as a "DELETE" request against the client.
12641263
*
1265-
* @return IODataRequest
1264+
* @return IODataResponse
12661265
*/
12671266
protected function runDelete()
12681267
{
@@ -1303,7 +1302,7 @@ public function count()
13031302
*
13041303
* @param array $values
13051304
*
1306-
* @return bool
1305+
* @return IODataResponse
13071306
*/
13081307
public function insert(array $values)
13091308
{

src/Query/IProcessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
namespace SaintSystems\OData\Query;
44

5-
use SaintSystems\OData\IODataRequest;
5+
use SaintSystems\OData\IODataResponse;
66

77
interface IProcessor
88
{
99
/**
1010
* Process the results of a "select" query.
1111
*
1212
* @param Builder $query
13-
* @param IODataRequest $results
13+
* @param IODataResponse $results
1414
*
15-
* @return IODataRequest
15+
* @return IODataResponse
1616
*/
1717
public function processSelect(Builder $query, $results);
1818
}

0 commit comments

Comments
 (0)