Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@
You can install the PHP SDK with Composer by editing your `composer.json` file:
```
{
"minimum-stability": "RC",
"require": {
"microsoft/microsoft-graph": "^2.0.0-RC27",
}
}
```
OR
```
{
"require": {
"microsoft/microsoft-graph": "^2.0.0-RC27",
"microsoft/microsoft-graph-core": "@RC"
"microsoft/microsoft-graph": "^2.0.0",
}
}
```
Expand Down
45 changes: 25 additions & 20 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This guide highlights breaking changes, bug fixes and new features introduced during major upgrades.


# Upgrading to 2.0.0-RC5
# Upgrading to 2.0.0
- [New Features](#new-features)
- [Breaking Changes](#breaking-changes)
- [Bug Fixes](#bug-fixes)
Expand All @@ -28,7 +28,7 @@ $graph->createRequest('GET', '/me')
->setAccessToken(getAccessToken()) //after initial token expires
...

// v2.0-RC
// v2.0
$tokenRequestContext = new AuthorizationCodeContext(
'tenantId',
'clientId',
Expand All @@ -37,7 +37,7 @@ $tokenRequestContext = new AuthorizationCodeContext(
'redirectUri'
);
$scopes = ['User.Read', 'Mail.Read'];
$authProvider = new PhpLeagueAuthenticationProvider($tokenRequestContext, $scopes);
$authProvider = new GraphPhpLeagueAuthenticationProvider($tokenRequestContext, $scopes);

```

Expand All @@ -54,8 +54,8 @@ $response = $graphClient->createRequest('GET', '/users/userId/messages')
->setReturnType(Model\User::class)
->execute();

// v2.0-RC
$response = $graphServiceClient->usersById('userId')->messages()->get()->wait();
// v2.0
$response = $graphServiceClient->users()->byUserId('userId')->messages()->get()->wait();
```

Hopefully this makes it more intuitive to work with the SDK and reduces time checking reference docs. Your feedback would be appreciated on your preferred experience or whether we should support both scenarios.
Expand All @@ -69,6 +69,21 @@ This would be mostly helpful for handling [throttling scenarios](https://docs.mi

See [this example](docs/Examples.md#customizing-middleware-configuration) on how to customize middleware.

## Improved support for paged collections
For performance reasons, collections of entities are often split into pages and each page is returned with a URL to the next page. The `PageIterator` class simplifies consuming of paged collections. `PageIterator` handles enumerating the current page and requesting subsequent pages automatically.

See [this example](docs/Examples.md#paging-through-a-collection)

## Support for Batch Requests
Combine multiple requests in a single call with ease. Up to 20 individual requests can be batched together to reduce network latency of making each request separately. The `BatchRequestBuilder` allows you to make requests to the `/$batch` endpoint of the Microsoft Graph API.

See [this example](docs/Examples.md#batching-requests)

## Support for resumable large file uploads
To upload files larger than 3MB, Microsoft Graph API supports uploads using resumable upload sessions where several bytes are uploaded at a time. The SDK provides a LargeFileUpload task that slices your file into chunks and progressively uploads them until completion.

See [this example](docs/Examples.md#uploading-large-files)

# Breaking Changes
The following breaking changes were introduced in v2.0.0 with more detailed upgrade steps in the following section:
- [Moved Beta models to the Microsoft Graph Beta SDK](#moved-beta-models-to-the-microsoft-graph-beta-sdkhttpspackagistorgpackagesmicrosoftmicrosoft-graph-beta).
Expand All @@ -85,15 +100,7 @@ Version 2 removes our Beta models from the current package to allow us to adhere
from merging breaking Beta model updates weekly. Users of the Beta models can now use the Beta SDK by requiring it in your `composer.json`:
```php
"require": {
"microsoft/microsoft-graph-beta": "^2.0.0-RC6",
"microsoft/microsoft-graph-core": "@RC"
}
```
OR
```php
"minimum-stability": "RC"
"require": {
"microsoft/microsoft-graph-beta": "^2.0.0-RC6"
"microsoft/microsoft-graph-beta": "^2.0.0",
}
```
Moving forward, the current package (`microsoft/microsoft-graph`) will only contain v1 models that match the [Microsoft Graph v1 API metadata](https://graph.microsoft.com/v1.0/$metadata)
Expand All @@ -109,16 +116,14 @@ $graph->setBaseUrl('https://graph.microsoft.com/')
->setApiVersion('v1.0')
->setAccessToken('xyz');

// 2.0-RC
// 2.0
$tokenRequestContext = new ClientCredentialContext(
'tenantId',
'clientId',
'clientSecret'
);
$scopes = ['https://graph.microsoft.com/.default'];
$authProvider = new PhpLeagueAuthenticationProvider($tokenRequestContext, $scopes);
$requestAdapter = new GraphRequestAdapter($authProvider);
$graphServiceClient = new GraphServiceClient($requestAdapter);
// uses https://graph.microsoft.com/.default scopes
$graphServiceClient = new GraphServiceClient($tokenRequestContext);

```
With version 2's configuration, all your requests are authenticated without additional effort.
Expand Down Expand Up @@ -158,7 +163,7 @@ The error response payload can be retrieved using `getError()` on the exception

try {

} catch (ApiException $ex) {
} catch (ODataError $ex) {
echo "{$ex->getError()->getCode()} : {$ex->getError()->getMessage()}";

}
Expand Down
58 changes: 40 additions & 18 deletions docs/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,27 @@ We call `iterate()` while passing a callback to be executed. If the callback ret
Iteration can be resumed by calling `iterate()` again.

```php
use Microsoft\Graph\Core\Tasks\PageIterator;
use Microsoft\Graph\Generated\Models\Message;
use DateTimeInterface;

$messages = $graphServiceClient->users()->byUserId(USER_ID)->messages()->get()->wait();

$pageIterator = new PageIterator($messages, $graphServiceClient->getRequestAdapter());

$callback = function (Message $message) {
echo "Message ID: {$message->getId()}";
return ($message->getId() !== 5);
}
$counter = 0;
$callback = function (Message $message) use (&$counter) {
echo "Subject: {$message->getSubject()}, Received at: {$message->getReceivedDateTime()->format(DateTimeInterface::RFC2822)}\n";
$counter ++;
return ($counter % 5 != 0);
};

// iteration will pause at message ID 5
$pageIterator->iterate($callback);
while ($pageIterator->hasNext()) {
// iteration pauses and resumes after every 5 messages
$pageIterator->iterate($callback);

// resumes iteration from next message (ID 6)
$pageIterator->iterate($callback);
echo "\nPaused iteration...Total messages: {$counter}\n\n";
}

```

Expand All @@ -173,15 +179,19 @@ To get the raw response:
```php

// PHP 7
$nativeResponseHandler = new NativeResponseHandler();
$config = new MeRequestBuilderGetRequestConfiguration();
$config->options = [new ResponsehandlerOption(new NativeResponseHandler())];
$user = $graphServiceClient->me()->get($config)->wait()->wait();
$config->options = [new ResponseHandlerOption($nativeResponseHandler)];
$result = $graphServiceClient->me()->get($config)->wait();
$rawResponse = $result->getResponse();


// PHP 8
$user = $graphServiceClient->me()->get(new MeRequestBuilderGetRequestConfiguration(
options: [new ResponseHandlerOption(new NativeResponseHandler())]
))->wait()->wait();
$nativeResponseHandler = new NativeResponseHandler();
$result = $graphServiceClient->me()->get(new MeRequestBuilderGetRequestConfiguration(
options: [new ResponseHandlerOption($nativeResponseHandler)]
))->wait();
$rawResponse = $result->getResponse();
```

## Send an email
Expand Down Expand Up @@ -299,6 +309,8 @@ The SDK provides a `LargeFileUpload` task that slices your file into bytes and p
To add a large attachment to an Outlook message:

```php
use Psr\Http\Client\NetworkExceptionInterface;


// create a file stream
$file = Utils::streamFor(fopen('fileName', 'r'));
Expand All @@ -312,16 +324,27 @@ $attachmentItem->setSize($file->getSize());
$uploadSessionRequestBody = new CreateUploadSessionPostRequestBody();
$uploadSessionRequestBody->setAttachmentItem($attachmentItem);

/** @var UploadSession $uploadSession */
$uploadSession = $graphServiceClient->users()->byUserId(USER_ID)->messages()->byMessageId('[id]')->attachments()->createUploadSession()->post($uploadSessionRequestBody)->wait();

// upload
$largeFileUpload = new LargeFileUploadTask($uploadSession, $graphServiceClient->getRequestAdapter(), $file);
try{
try {
$uploadSession = $largeFileUpload->upload()->wait();
} catch (\Psr\Http\Client\NetworkExceptionInterface $ex) {
} catch (NetworkExceptionInterface $ex) {
// resume upload in case of network errors
$uploadSession = $largeFileUpload->resume()->wait();
$retries = 0;
$maxRetries = 3;
while ($retries < $maxRetries) {
try {
$uploadSession = $largeFileUpload->resume()->wait();
if ($uploadSession) {
break;
}
} catch (NetworkExceptionInterface $ex) {
$retries ++;
}
}
throw $ex;
}

```
Expand Down Expand Up @@ -429,7 +452,6 @@ use Microsoft\Graph\BatchRequestBuilder;
use Microsoft\Graph\Core\Requests\BatchResponseItem;

$requestBuilder = new BatchRequestBuilder($graphServiceClient->getRequestAdapter());
/** @var BatchResponseContent $batchResponse */
$batchResponse = $requestBuilder->postAsync($batchRequestContent)->wait();

```
Expand Down