-
Notifications
You must be signed in to change notification settings - Fork 66
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
const AUTH_URL = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
const TOKEN_URL = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'
const LEGACY_DATETIME_FORMAT = 'Y-m-d\TH:i:sO'
private string $clientId
- Visibility: private
private \Microsoft\Graph\Graph $graph
- Visibility: private
private \GuzzleHttp\ClientInterface $httpClient
- Visibility: private
private \Krizalys\Onedrive\Definition\ServiceDefinitionInterface $serviceDefinition
- Visibility: private
private object $_state
- Visibility: private
mixed Krizalys\Onedrive\Client::__construct(string $clientId, \Microsoft\Graph\Graph $graph, \GuzzleHttp\ClientInterface $httpClient, mixed $serviceDefinition, \Krizalys\Onedrive\mixed[string] $options)
Constructor.
- Visibility: public
-
$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 bygetState()
. Default:[]
.
-
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
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
-
$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.
integer Krizalys\Onedrive\Client::getTokenExpire()
Gets the access token expiration delay.
- Visibility: public
integer Krizalys\Onedrive\Client::getAccessTokenStatus()
Gets the status of the current access token.
See AccessTokenStatus for the possible values returned.
- Visibility: public
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
- $clientSecret string - The OneDrive client secret.
- $code string - The code returned by OneDrive after successful log in.
mixed Krizalys\Onedrive\Client::renewAccessToken(string $clientSecret)
Renews the access token from OAuth.
This token is valid for one hour.
- Visibility: public
- $clientSecret string - The client secret.
array<mixed,\Krizalys\Onedrive\Proxy\DriveProxy> Krizalys\Onedrive\Client::getDrives()
Gets the current user's drive.
- Visibility: public
\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getMyDrive()
Gets the signed in user's drive.
- Visibility: public
\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getDriveById(string $driveId)
Gets a drive by ID.
- Visibility: public
- $driveId string - The drive ID.
\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getDriveByUser(string $idOrUserPrincipalName)
Gets a user's OneDrive.
- Visibility: public
- $idOrUserPrincipalName string - The ID or user principal name.
\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getDriveByGroup(string $groupId)
Gets the document library associated with a group.
- Visibility: public
- $groupId string - The group ID.
\Krizalys\Onedrive\Proxy\DriveProxy Krizalys\Onedrive\Client::getDriveBySite(string $siteId)
Gets the document library for a site.
- Visibility: public
- $siteId string - The site ID.
\Krizalys\Onedrive\Proxy\DriveItemProxy Krizalys\Onedrive\Client::getDriveItemById(string $driveId, mixed $itemId)
Gets a drive item by ID.
- Visibility: public
- $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.
\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
- $path string - The path.
\Krizalys\Onedrive\Proxy\DriveItemProxy Krizalys\Onedrive\Client::getRoot()
Gets the root drive item.
- Visibility: public
\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
- $specialFolderName string - The special folder name.
array<mixed,\Krizalys\Onedrive\Proxy\DriveItemProxy> Krizalys\Onedrive\Client::getShared()
Gets items shared with the signed-in user.
- Visibility: public
array<mixed,\Krizalys\Onedrive\Proxy\DriveItemProxy> Krizalys\Onedrive\Client::getRecent()
Gets recent files.
- Visibility: public
\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
- $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
.
\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
- $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.
object Krizalys\Onedrive\Client::fetchDriveItem(null|string $driveItemId)
Fetches a drive item from the current OneDrive account.
- Visibility: public
- $driveItemId null|string - The unique ID of the OneDrive drive item to fetch, or
null
to fetch the OneDrive root folder. Default:null
.
\Krizalys\Onedrive\Folder Krizalys\Onedrive\Client::fetchRoot()
Fetches the root folder from the current OneDrive account.
- Visibility: public
\Krizalys\Onedrive\Folder Krizalys\Onedrive\Client::fetchCameraRoll()
Fetches the "Camera Roll" folder from the current OneDrive account.
- Visibility: public
\Krizalys\Onedrive\Folder Krizalys\Onedrive\Client::fetchDocs()
Fetches the "Documents" folder from the current OneDrive account.
- Visibility: public
\Krizalys\Onedrive\Folder Krizalys\Onedrive\Client::fetchPics()
Fetches the "Pictures" folder from the current OneDrive account.
- Visibility: public
object Krizalys\Onedrive\Client::fetchProperties(null|string $driveItemId)
Fetches the properties of a drive item in the current OneDrive account.
- Visibility: public
- $driveItemId null|string - The drive item ID, or
null
to fetch the OneDrive root folder. Default:null
.
\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
- $driveItemId null|string - The drive item ID, or
null
to fetch the OneDrive root folder. Default:null
.
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
- $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.
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
- $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
.
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
- $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
null
to copy it to the OneDrive root folder. Default:null
.
mixed Krizalys\Onedrive\Client::deleteDriveItem(string $driveItemId)
Deletes a drive item in the current OneDrive account.
- Visibility: public
- $driveItemId string - The unique ID of the drive item to delete.
object Krizalys\Onedrive\Client::fetchQuota()
Fetches the quota of the current OneDrive account.
- Visibility: public
object Krizalys\Onedrive\Client::fetchRecentDocs()
Fetches the recent documents uploaded to the current OneDrive account.
- Visibility: public
object Krizalys\Onedrive\Client::fetchShared()
Fetches the drive items shared with the current OneDrive account.
- Visibility: public
boolean Krizalys\Onedrive\Client::isFolder(\Krizalys\Onedrive\Proxy\DriveItemProxy $item)
Checks whether a given drive item is a folder.
- Visibility: public
- $item Krizalys\Onedrive\Proxy\DriveItemProxy - The drive item.
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
- $item Krizalys\Onedrive\Proxy\DriveItemProxy - The drive item.
- $options Krizalys\Onedrive\mixed[string] - The options.