_request = $request; $this->_body = $body; $this->_httpStatusCode = $httpStatusCode; $this->_headers = $headers; $this->_decodedBody = $this->_decodeBody(); } /** * Decode the JSON response into an array * * @return array The decoded response */ private function _decodeBody() { $decodedBody = json_decode($this->_body, true); if ($decodedBody === null) { $decodedBody = array(); } return $decodedBody; } /** * Get the decoded body of the HTTP response * * @return array The decoded body */ public function getBody() { return $this->_decodedBody; } /** * Get the undecoded body of the HTTP response * * @return StreamInterface|null The undecoded body */ public function getRawBody() { return $this->_body; } /** * Get the status of the HTTP response * * @return string|null The HTTP status */ public function getStatus() { return $this->_httpStatusCode; } /** * Get the headers of the response * * @return array|null The response headers */ public function getHeaders() { return $this->_headers; } /** * Converts the response JSON object to a Graph SDK object * * @param mixed $returnType The type to convert the object(s) to * * @return mixed object or array of objects of type $returnType */ public function getResponseAsObject($returnType) { $class = $returnType; $result = $this->getBody(); //If more than one object is returned if (array_key_exists('value', $result)) { $values = $result['value']; //Check that this is an object array instead of a value called "value" if (is_array($values)) { $objArray = array(); foreach ($values as $obj) { $objArray[] = new $class($obj); } return $objArray; } } return new $class($result); } /** * Gets the next link of a response object from OData * If the nextLink is null, there are no more pages * * @return string|null nextLink, if provided */ public function getNextLink() { if (array_key_exists("@odata.nextLink", $this->getBody())) { $nextLink = $this->getBody()['@odata.nextLink']; return $nextLink; } return null; } /** * Gets the delta link of a response object from OData * If the deltaLink is null, there are more pages in the collection; * use nextLink to obtain more * * @return string|null deltaLink */ public function getDeltaLink() { if (array_key_exists("@odata.deltaLink", $this->getBody())) { $deltaLink = $this->getBody()['@odata.deltaLink']; return $deltaLink; } return null; } }