Skip to content

Krizalys Onedrive Client

Christophe Vidal edited this page Aug 4, 2019 · 1 revision

Krizalys\Onedrive\Client

A client interface to communicate with the OneDrive API.

Client instances act as entry points allowing client applications to perform currently implemented OneDrive operations programmatically.

For example, assuming you have instantiated a client and the user has logged successfully and authorized your client application:

$client->getRoot()->upload('hello.txt', 'Hello World!');

Applications are managed via the Microsoft identity platform (v2.0); see "App registrations" in Microsoft Azure.

  • Class name: Client
  • Namespace: Krizalys\Onedrive

Constants

AUTH_URL

const AUTH_URL = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'

TOKEN_URL

const TOKEN_URL = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'

LEGACY_DATETIME_FORMAT

const LEGACY_DATETIME_FORMAT = 'Y-m-d\TH:i:sO'

Properties

$clientId

private string $clientId
  • Visibility: private

$graph

private \Microsoft\Graph\Graph $graph
  • Visibility: private

$httpClient

private \GuzzleHttp\ClientInterface $httpClient
  • Visibility: private

$serviceDefinition

private \Krizalys\Onedrive\Definition\ServiceDefinitionInterface $serviceDefinition
  • Visibility: private

$_state

private object $_state
  • Visibility: private

Methods

__construct

mixed Krizalys\Onedrive\Client::__construct(string $clientId, \Microsoft\Graph\Graph $graph, \GuzzleHttp\ClientInterface $httpClient, mixed $serviceDefinition, \Krizalys\Onedrive\mixed[string] $options)

Constructor.

  • Visibility: public

Arguments

  • $clientId string - The client ID.

  • $graph Microsoft\Graph\Graph - The Microsoft Graph.

  • $httpClient GuzzleHttp\ClientInterface - The Guzzle HTTP client.

  • $serviceDefinition mixed - The service definition. Not passing a \Krizalys\Onedrive\Definition\ServiceDefinitionInterface via this parameter is deprecated and will be disallowed in version 3. Passing a logger via this parameter is deprecated and will be disallowed in version 3.

  • $options Krizalys\Onedrive\mixed[string]

    The options to use while creating this object. Supported options:

    • 'state' (object): the OneDrive client state, as returned by getState(). Default: [].

getState

object Krizalys\Onedrive\Client::getState()

Gets the current state of this Client instance.

Typically saved in the session and passed back to the Client constructor for further requests.

  • Visibility: public

getLogInUrl

string Krizalys\Onedrive\Client::getLogInUrl(array<mixed,string> $scopes, string $redirectUri, string $state)

Gets the URL of the log in form.

Users should visit this URL in their browser to first be presented a form where the user is first allowed to log in to their OneDrive account, and then to grant the requested permissions to the OneDrive application.

After login, the browser is redirected to the given redirect URI, and a code is passed as a query string parameter to this URI.

A user-defined value may also be passed back to this URI as a query string parameter via the $state parameter; see "Use a state parameter" in Microsoft Azure documentation for example use cases.

The browser is also directly redirected to the given redirect URI if the user is already logged in.

  • Visibility: public

Arguments

  • $scopes array<mixed,string>

    The OneDrive scopes requested by the application. Supported values:

    • 'offline_access' ;
    • 'files.read' ;
    • 'files.read.all' ;
    • 'files.readwrite' ;
    • 'files.readwrite.all'.
  • $redirectUri string - The URI to which to redirect to upon successful log in.

  • $state string - The state to pass as a query string value to the redirect URI upon successful log in.

getTokenExpire

integer Krizalys\Onedrive\Client::getTokenExpire()

Gets the access token expiration delay.

  • Visibility: public

getAccessTokenStatus

integer Krizalys\Onedrive\Client::getAccessTokenStatus()

Gets the status of the current access token.

See AccessTokenStatus for the possible values returned.

  • Visibility: public

obtainAccessToken

mixed Krizalys\Onedrive\Client::obtainAccessToken(string $clientSecret, string $code)

Obtains a new access token from OAuth.

This token is valid for one hour.

  • Visibility: public

Arguments

  • $clientSecret string - The OneDrive client secret.
  • $code string - The code returned by OneDrive after successful log in.

renewAccessToken

mixed Krizalys\Onedrive\Client::renewAccessToken(string $clientSecret)

Renews the access token from OAuth.

This token is valid for one hour.

  • Visibility: public

Arguments

  • $clientSecret string - The client secret.

getDrives

array<mixed,\Krizalys\Onedrive\Proxy\DriveProxy> Krizalys\Onedrive\Client::getDrives()

Gets the current user's drive.

  • Visibility: public

getMyDrive

\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getMyDrive()

Gets the signed in user's drive.

  • Visibility: public

getDriveById

\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getDriveById(string $driveId)

Gets a drive by ID.

  • Visibility: public

Arguments

  • $driveId string - The drive ID.

getDriveByUser

\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getDriveByUser(string $idOrUserPrincipalName)

Gets a user's OneDrive.

  • Visibility: public

Arguments

  • $idOrUserPrincipalName string - The ID or user principal name.

getDriveByGroup

\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getDriveByGroup(string $groupId)

Gets the document library associated with a group.

  • Visibility: public

Arguments

  • $groupId string - The group ID.

getDriveBySite

\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getDriveBySite(string $siteId)

Gets the document library for a site.

  • Visibility: public

Arguments

  • $siteId string - The site ID.

getDriveItemById

\Krizalys\Onedrive\Proxy\DriveItemProxy Krizalys\Onedrive\Client::getDriveItemById(string $driveId, mixed $itemId)

Gets a drive item by ID.

  • Visibility: public

Arguments

  • $driveId string - The drive ID. Deprecated and will change in version 3; pass the drive item ID instead.
  • $itemId mixed - The drive item ID. Deprecated and will be removed in version 3; Omit this parameter.

getDriveItemByPath

\Krizalys\Onedrive\Proxy\DriveItemProxy Krizalys\Onedrive\Client::getDriveItemByPath(string $path)

Gets a drive item by path.

The path is given as an absolute path from the root of the drive, for example:

$driveItem = $client->getDriveItemByPath('/path/to/file.txt');
  • Visibility: public

Arguments

  • $path string - The path.

getRoot

\Krizalys\Onedrive\Proxy\DriveItemProxy Krizalys\Onedrive\Client::getRoot()

Gets the root drive item.

  • Visibility: public

getSpecialFolder

\Krizalys\Onedrive\Proxy\DriveItemProxy Krizalys\Onedrive\Client::getSpecialFolder(string $specialFolderName)

Gets a special folder by name.

See SpecialFolderName for the parameter $specialFolderName' supported values.

  • Visibility: public

Arguments

  • $specialFolderName string - The special folder name.

getShared

array<mixed,\Krizalys\Onedrive\Proxy\DriveItemProxy> Krizalys\Onedrive\Client::getShared()

Gets items shared with the signed-in user.

  • Visibility: public

getRecent

array<mixed,\Krizalys\Onedrive\Proxy\DriveItemProxy> Krizalys\Onedrive\Client::getRecent()

Gets recent files.

  • Visibility: public

createFolder

\Krizalys\Onedrive\Folder Krizalys\Onedrive\Client::createFolder(string $name, null|string $parentId, null|string $description)

Creates a folder in the current OneDrive account.

This operation is supported only on folders (as opposed to files): it fails if $parentId does not refer to a folder.

  • Visibility: public

Arguments

  • $name string - The name of the OneDrive folder to be created.
  • $parentId null|string - The ID of the OneDrive folder into which to create the OneDrive folder, or null to create it in the OneDrive root folder. Default: null.
  • $description null|string - The description of the OneDrive folder to be created, or null to create it without a description. Default: null.

createFile

\Krizalys\Onedrive\File Krizalys\Onedrive\Client::createFile(string $name, null|string $parentId, string|resource|\GuzzleHttp\Psr7\Stream $content, \Krizalys\Onedrive\mixed[string] $options)

Creates a file in the current OneDrive account.

This operation is supported only on folders (as opposed to files): it fails if $parentId does not refer to a folder.

  • Visibility: public

Arguments

  • $name string - The name of the OneDrive file to be created.
  • $parentId null|string - The ID of the OneDrive folder into which to create the OneDrive file, or null to create it in the OneDrive root folder. Default: null.
  • $content string|resource|GuzzleHttp\Psr7\Stream - The content of the OneDrive file to be created, as a string or as a resource to an already opened file. Default: ''.
  • $options Krizalys\Onedrive\mixed[string] - The options. Unused.

fetchDriveItem

object Krizalys\Onedrive\Client::fetchDriveItem(null|string $driveItemId)

Fetches a drive item from the current OneDrive account.

  • Visibility: public

Arguments

  • $driveItemId null|string - The unique ID of the OneDrive drive item to fetch, or null to fetch the OneDrive root folder. Default: null.

fetchRoot

\Krizalys\Onedrive\Folder Krizalys\Onedrive\Client::fetchRoot()

Fetches the root folder from the current OneDrive account.

  • Visibility: public

fetchCameraRoll

\Krizalys\Onedrive\Folder Krizalys\Onedrive\Client::fetchCameraRoll()

Fetches the "Camera Roll" folder from the current OneDrive account.

  • Visibility: public

fetchDocs

\Krizalys\Onedrive\Folder Krizalys\Onedrive\Client::fetchDocs()

Fetches the "Documents" folder from the current OneDrive account.

  • Visibility: public

fetchPics

\Krizalys\Onedrive\Folder Krizalys\Onedrive\Client::fetchPics()

Fetches the "Pictures" folder from the current OneDrive account.

  • Visibility: public

fetchProperties

object Krizalys\Onedrive\Client::fetchProperties(null|string $driveItemId)

Fetches the properties of a drive item in the current OneDrive account.

  • Visibility: public

Arguments

  • $driveItemId null|string - The drive item ID, or null to fetch the OneDrive root folder. Default: null.

fetchDriveItems

\Krizalys\Onedrive\DriveItem Krizalys\Onedrive\Client::fetchDriveItems(null|string $driveItemId)

Fetches the drive items in a folder in the current OneDrive account.

This operation is supported only on folders (as opposed to files): it fails if $parentId does not refer to a folder.

  • Visibility: public

Arguments

  • $driveItemId null|string - The drive item ID, or null to fetch the OneDrive root folder. Default: null.

updateDriveItem

mixed Krizalys\Onedrive\Client::updateDriveItem(string $driveItemId, array<mixed,mixed>|object $properties, boolean $temp)

Updates the properties of a drive item in the current OneDrive account.

  • Visibility: public

Arguments

  • $driveItemId string - The unique ID of the drive item to update.
  • $properties array<mixed,mixed>|object - The properties to update. Default: [].
  • $temp boolean - Option to allow save to a temporary file in case of large files.

moveDriveItem

mixed Krizalys\Onedrive\Client::moveDriveItem(string $driveItemId, null|string $destinationId)

Moves a drive item into another folder.

$destinationId must refer to a folder.

  • Visibility: public

Arguments

  • $driveItemId string - The unique ID of the drive item to move.
  • $destinationId null|string - The unique ID of the folder into which to move the drive item, or null to move it to the OneDrive root folder. Default: null.

copyFile

mixed Krizalys\Onedrive\Client::copyFile(string $driveItemId, null|string $destinationId)

Copies a file into another folder.

This operation is supported only on files (as opposed to folders): it fails if $driveItemId does not refer to a file.

Additionally, $destinationId must refer to a folder.

  • Visibility: public

Arguments

  • $driveItemId string - The unique ID of the file to copy.
  • $destinationId null|string - The unique ID of the folder into which to copy the file, or nullto copy it to the OneDrive root folder. Default: null.

deleteDriveItem

mixed Krizalys\Onedrive\Client::deleteDriveItem(string $driveItemId)

Deletes a drive item in the current OneDrive account.

  • Visibility: public

Arguments

  • $driveItemId string - The unique ID of the drive item to delete.

fetchQuota

object Krizalys\Onedrive\Client::fetchQuota()

Fetches the quota of the current OneDrive account.

  • Visibility: public

fetchRecentDocs

object Krizalys\Onedrive\Client::fetchRecentDocs()

Fetches the recent documents uploaded to the current OneDrive account.

  • Visibility: public

fetchShared

object Krizalys\Onedrive\Client::fetchShared()

Fetches the drive items shared with the current OneDrive account.

  • Visibility: public

isFolder

boolean Krizalys\Onedrive\Client::isFolder(\Krizalys\Onedrive\Proxy\DriveItemProxy $item)

Checks whether a given drive item is a folder.

  • Visibility: public

Arguments

buildOptions

array<mixed,mixed> Krizalys\Onedrive\Client::buildOptions(\Krizalys\Onedrive\Proxy\DriveItemProxy $item, \Krizalys\Onedrive\mixed[string] $options)

Builds options for legacy File and Folder constructors.

  • Visibility: public

Arguments

Clone this wiki locally