Documentation

GraphCollectionRequest extends GraphRequest
in package

Class GraphCollectionRequest

Tags
copyright

2021 Microsoft Corporation

license

https://opensource.org/licenses/MIT MIT License

link
https://developer.microsoft.com/graph

Table of Contents

$deltaLink  : string
The delta link to use in calling /delta a subsequent time
$end  : bool
True if the user has reached the end of the collection
$nextLink  : string
The next link to use in calling a new page of results
$originalReturnType  : string
The return type that the user specified
$pageSize  : int
The size of page to divide the collection into
$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
Constructs a new GraphCollectionRequest object
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
count()  : int
Gets the number of entries in the collection
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
getDeltaLink()  : string|null
Gets a delta link to use with subsequent calls to /delta
getHeaders()  : array<string, array<string|int, string>>
Get the request headers
getPage()  : array<string|int, mixed>
Gets the next page of results
getPageSize()  : int
Get page size
getRequestUri()  : UriInterface
isEnd()  : bool
Gets whether the user has reached the end of the collection
setAccessToken()  : $this
Sets a new accessToken
setPageSize()  : GraphCollectionRequest
Sets the number of results to return with each call to "getPage()"
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
processPageCallReturn()  : mixed
Clean up after making a page call request
setPageCallInfo()  : GraphCollectionRequest
Sets the required query information to get a new page

Properties

The delta link to use in calling /delta a subsequent time

protected string $deltaLink

$originalReturnType

The return type that the user specified

protected string $originalReturnType

$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

$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()

Constructs a new GraphCollectionRequest object

public __construct(string $requestType, string $endpoint, AbstractGraphClient $graphClient[, string $baseUrl = "" ]) : mixed
Parameters
$requestType : string

The HTTP verb for the request ("GET", "POST", "PUT", etc.)

$endpoint : string

The URI of the endpoint to hit

$graphClient : AbstractGraphClient
$baseUrl : string = ""

(optional) If empty, it's set to $client's national cloud

Tags
throws
GraphClientException
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
throws
GraphClientException

if attempting to overwrite SdkVersion header

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
throws
ClientExceptionInterface|GraphClientException

when unable to open $path for writing

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
throws
ClientExceptionInterface
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
throws
Exception

when promise fails

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

Gets a delta link to use with subsequent calls to /delta

public getDeltaLink() : string|null
Return values
string|null

The delta link

getHeaders()

Get the request headers

public getHeaders() : array<string, array<string|int, string>>
Return values
array<string, array<string|int, string>>

of headers

getPage()

Gets the next page of results

public getPage() : array<string|int, mixed>
Tags
throws
ClientExceptionInterface
Return values
array<string|int, mixed>

of objects of class $returnType

getRequestUri()

public getRequestUri() : UriInterface
Return values
UriInterface

isEnd()

Gets whether the user has reached the end of the collection

public isEnd() : bool
Return values
bool

The end

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
throws
GraphClientException

when $returnClass is not an existing class

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
throws
ClientExceptionInterface|GraphClientException

if $path cannot be opened for reading

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
throws
GraphClientException
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
Return values
void

processPageCallReturn()

Clean up after making a page call request

private processPageCallReturn(GraphResponse $response) : mixed
Parameters
$response : GraphResponse

The GraphResponse returned after making a page call

Return values
mixed

result of the call, formatted according to the returnType set by the user

Search results