GraphRequest
in package
Class GraphRequest
Tags
Table of Contents
- $requestType : string
- The type of request to make ("GET", "POST", etc.)
- $returnsStream : bool
- True if the response should be returned as a stream
- $returnType : string|null
- The object type to cast the response to
- $graphClient : AbstractGraphClient
- The Graph client
- $headers : array<string, string|string[]>
- An array of headers to send with the request
- $httpRequest : Request
- PSR-7 Request to be passed to HTTP client
- $requestBody : StreamInterface|string
- The body of the request (optional)
- $requestUri : UriInterface
- Full Request URI (base URL + endpoint)
- __construct() : mixed
- GraphRequest constructor.
- addHeaders() : GraphRequest
- Adds custom headers to the request
- attachBody() : $this
- Attach a body to the request. Will JSON encode any Microsoft\Graph\Model objects as well as arrays
- download() : void
- Download a file from OneDrive to a given location
- execute() : array<string|int, mixed>|GraphResponse|StreamInterface|object
- Executes the HTTP request using $graphClient's http client or a PSR-18 compliant HTTP client
- executeAsync() : Promise
- Executes the HTTP request asynchronously using $client
- getBody() : string|StreamInterface
- Get the body of the request
- getHeaders() : array<string, array<string|int, string>>
- Get the request headers
- getRequestUri() : UriInterface
- setAccessToken() : $this
- Sets a new accessToken
- setReturnType() : $this
- Sets the return type of the response object Can be set to a model or \Psr\Http\Message\StreamInterface
- upload() : array<string|int, mixed>|GraphResponse|StreamInterface|object
- Upload a file from $path to Graph API
- initPsr7HttpRequest() : void
- initRequestUri() : void
- Creates full request URI by resolving $baseUrl and $endpoint based on RFC 3986
- setRequestUri() : void
- initHeaders() : void
- Sets default headers based on baseUrl being a Graph endpoint or not
Properties
$requestType
The type of request to make ("GET", "POST", etc.)
protected
string
$requestType
$returnsStream
True if the response should be returned as a stream
protected
bool
$returnsStream
$returnType
The object type to cast the response to
protected
string|null
$returnType
$graphClient
The Graph client
private
AbstractGraphClient
$graphClient
$headers
An array of headers to send with the request
private
array<string, string|string[]>
$headers
$httpRequest
PSR-7 Request to be passed to HTTP client
private
Request
$httpRequest
$requestBody
The body of the request (optional)
private
StreamInterface|string
$requestBody
= null
$requestUri
Full Request URI (base URL + endpoint)
private
UriInterface
$requestUri
Methods
__construct()
GraphRequest constructor.
public
__construct(string $requestType, string $endpoint, AbstractGraphClient $graphClient[, string $baseUrl = "" ]) : mixed
Sets $baseUrl by default to $graphClient's national cloud Resolves $baseUrl and $endpoint based on RFC 3986
Parameters
- $requestType : string
-
The HTTP method to use e.g. "GET" or "POST"
- $endpoint : string
-
The url path on the host to be called-
- $graphClient : AbstractGraphClient
-
The Graph client to use
- $baseUrl : string = ""
-
(optional) If empty, it's set to $client's national cloud
Tags
Return values
mixed —addHeaders()
Adds custom headers to the request
public
addHeaders(array<string, string|string[]> $headers) : GraphRequest
Parameters
- $headers : array<string, string|string[]>
-
An array of custom headers
Tags
Return values
GraphRequest —object
attachBody()
Attach a body to the request. Will JSON encode any Microsoft\Graph\Model objects as well as arrays
public
attachBody(string|StreamInterface|object|array<string|int, mixed> $body) : $this
Parameters
- $body : string|StreamInterface|object|array<string|int, mixed>
-
The payload to include in the request
Return values
$this —object
download()
Download a file from OneDrive to a given location
public
download(string $path[, ClientInterface|null $client = null ]) : void
Parameters
- $path : string
-
path to download the file contents to
- $client : ClientInterface|null = null
-
(optional) When null, defaults to $graphClient's http client
Tags
Return values
void —execute()
Executes the HTTP request using $graphClient's http client or a PSR-18 compliant HTTP client
public
execute([ClientInterface|null $client = null ]) : array<string|int, mixed>|GraphResponse|StreamInterface|object
Parameters
- $client : ClientInterface|null = null
-
(optional) When null, uses $graphClient's http client
Tags
Return values
array<string|int, mixed>|GraphResponse|StreamInterface|object —Graph Response object or response body cast to $returnType
executeAsync()
Executes the HTTP request asynchronously using $client
public
executeAsync([HttpAsyncClient|null $client = null ]) : Promise
Parameters
- $client : HttpAsyncClient|null = null
-
(optional) When null, uses $graphClient's http client
Tags
Return values
Promise —Resolves to GraphResponse object|response body cast to $returnType. Fails throwing the exception
getBody()
Get the body of the request
public
getBody() : string|StreamInterface
Return values
string|StreamInterface —request body
getHeaders()
Get the request headers
public
getHeaders() : array<string, array<string|int, string>>
Return values
array<string, array<string|int, string>> —of headers
getRequestUri()
public
getRequestUri() : UriInterface
Return values
UriInterface —setAccessToken()
Sets a new accessToken
public
setAccessToken(string $accessToken) : $this
Parameters
- $accessToken : string
-
A valid access token to validate the Graph call
Return values
$this —object
setReturnType()
Sets the return type of the response object Can be set to a model or \Psr\Http\Message\StreamInterface
public
setReturnType(string $returnClass) : $this
Parameters
- $returnClass : string
-
The class name to use
Tags
Return values
$this —object
upload()
Upload a file from $path to Graph API
public
upload(string $path[, ClientInterface|null $client = null ]) : array<string|int, mixed>|GraphResponse|StreamInterface|object
Parameters
- $path : string
-
path of file to be uploaded
- $client : ClientInterface|null = null
-
(optional)
Tags
Return values
array<string|int, mixed>|GraphResponse|StreamInterface|object —Graph Response object or response body cast to $returnType
initPsr7HttpRequest()
protected
initPsr7HttpRequest() : void
Return values
void —initRequestUri()
Creates full request URI by resolving $baseUrl and $endpoint based on RFC 3986
protected
initRequestUri(string $baseUrl, string $endpoint) : void
Parameters
- $baseUrl : string
- $endpoint : string
Tags
Return values
void —setRequestUri()
protected
setRequestUri(UriInterface $uri) : void
Parameters
- $uri : UriInterface
Return values
void —initHeaders()
Sets default headers based on baseUrl being a Graph endpoint or not
private
initHeaders(string $baseUrl) : void
Parameters
- $baseUrl : string