6
6
7
7
use Exception ;
8
8
use Office365 \PHP \Client \Runtime \ClientAction ;
9
+ use Office365 \PHP \Client \Runtime \ClientObject ;
9
10
use Office365 \PHP \Client \Runtime \ClientRequestStatus ;
10
11
use Office365 \PHP \Client \Runtime \ClientResult ;
11
12
use Office365 \PHP \Client \Runtime \IEntityType ;
@@ -70,45 +71,44 @@ public function processResponse($response)
70
71
$ resultObject = $ this ->resultObjects [$ this ->getCurrentAction ()->getId ()];
71
72
72
73
if ($ this ->getCurrentAction () instanceof InvokePostMethodQuery && $ this ->getCurrentAction ()->MethodBody instanceof ChangeLogItemQuery) {
73
- $ payload = $ this ->parseXmlResponse ($ response );
74
+ $ this ->processXmlResponse ($ response, $ resultObject );
74
75
} else {
75
- $ payload = $ this ->parseJsonResponse ($ response );
76
- }
77
-
78
- if ($ resultObject instanceof ClientResult) {
79
- if ($ this ->getCurrentAction () instanceof InvokeMethodQuery){
80
- $ this ->getSerializationContext ()->RootElement = $ this ->getCurrentAction ()->MethodName ;
81
- }
82
- $ resultObject ->fromJson ($ payload ,$ this ->getSerializationContext ());
83
- } else if ($ resultObject instanceof IEntityType) {
84
- $ this ->getSerializationContext ()->map ($ payload ,$ resultObject );
85
- $ this ->getCurrentAction ()->getResourcePath ()->ServerObjectIsNull = false ;
76
+ $ this ->processJsonResponse ($ response ,$ resultObject );
86
77
}
87
78
}
88
79
89
80
90
81
/**
91
82
* @param string $response
92
- * @return mixed
83
+ * @param ClientObject|ClientResult $resultObject
93
84
* @throws Exception
94
85
*/
95
- private function parseJsonResponse ($ response )
86
+ private function processJsonResponse ($ response, $ resultObject )
96
87
{
97
- $ error = array ();
88
+ $ errorPayload = array ();
98
89
$ payload = json_decode ($ response );
99
- if ($ this ->validateResponse ($ payload , $ error ) == false ) {
100
- throw new Exception ($ error ['Message ' ]);
90
+ if ($ this ->validateResponse ($ payload , $ errorPayload ) == false ) {
91
+ throw new Exception ($ errorPayload ['Message ' ]);
92
+ }
93
+
94
+ if ($ resultObject instanceof ClientResult) {
95
+ if ($ this ->getCurrentAction () instanceof InvokeMethodQuery){
96
+ $ this ->getSerializationContext ()->RootElement = $ this ->getCurrentAction ()->MethodName ;
97
+ }
98
+ $ resultObject ->fromJson ($ payload ,$ this ->getSerializationContext ());
99
+ } else if ($ resultObject instanceof IEntityType) {
100
+ $ this ->getSerializationContext ()->map ($ payload ,$ resultObject );
101
+ $ this ->getCurrentAction ()->getResourcePath ()->ServerObjectIsNull = false ;
101
102
}
102
- return $ payload ;
103
103
}
104
104
105
105
106
106
/**
107
107
* Process Xml response from SharePoint REST service
108
108
* @param string $response
109
- * @return array
109
+ * @param ClientObject $resultObject
110
110
*/
111
- private function parseXmlResponse ($ response )
111
+ private function processXmlResponse ($ response, $ resultObject )
112
112
{
113
113
$ payload = array ();
114
114
$ xml = simplexml_load_string ($ response );
@@ -122,7 +122,7 @@ private function parseXmlResponse($response)
122
122
}
123
123
$ payload [] = $ item ;
124
124
}
125
- return $ payload ;
125
+ $ this -> getSerializationContext ()-> map ( $ payload, $ resultObject ) ;
126
126
}
127
127
128
128
@@ -200,6 +200,9 @@ protected function getCurrentAction(){
200
200
}
201
201
202
202
203
+ /**
204
+ * @return ClientRequest
205
+ */
203
206
public function getNextRequest ()
204
207
{
205
208
$ request = new ODataRequest ($ this ->context );
0 commit comments