PHPackages                             owncloud/ocis-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. owncloud/ocis-php-sdk

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

owncloud/ocis-php-sdk
=====================

v1.3.0(5mo ago)46721[4 issues](https://github.com/owncloud/ocis-php-sdk/issues)[5 PRs](https://github.com/owncloud/ocis-php-sdk/pulls)Apache-2.0PHPPHP ^8.1CI passing

Since Dec 22Pushed 1mo ago12 watchersCompare

[ Source](https://github.com/owncloud/ocis-php-sdk)[ Packagist](https://packagist.org/packages/owncloud/ocis-php-sdk)[ RSS](/packages/owncloud-ocis-php-sdk/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (22)Used By (0)

[![Build Status](https://camo.githubusercontent.com/92e53b7434ca0a7410154c6790cf7bdf2d2cc569daa37ac4c59ff5f99bcefe8b/68747470733a2f2f64726f6e652e6f776e636c6f75642e636f6d2f6170692f6261646765732f6f776e636c6f75642f6f6369732d7068702d73646b2f7374617475732e7376673f7265663d726566732f68656164732f6d61696e)](https://drone.owncloud.com/owncloud/ocis-php-sdk)[![Coverage](https://camo.githubusercontent.com/95081db4de856dece2d7a664523c7e761d4ea5064d24fa7664678911d06b54d3/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6f776e636c6f75645f6f6369732d7068702d73646b266d65747269633d636f766572616765)](https://sonarcloud.io/summary/new_code?id=owncloud_ocis-php-sdk)[![Code Smells](https://camo.githubusercontent.com/4f4cc30a76ba7c8e9821c826d9a2146fb2ea83cfc13b04e82c4535f683ef9901/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6f776e636c6f75645f6f6369732d7068702d73646b266d65747269633d636f64655f736d656c6c73)](https://sonarcloud.io/summary/new_code?id=owncloud_ocis-php-sdk)[![Quality Gate Status](https://camo.githubusercontent.com/92d2d7c4187e43021248a0133eb05f98e63b8cb69349d91905222acc6e49e85f/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6f776e636c6f75645f6f6369732d7068702d73646b266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=owncloud_ocis-php-sdk)[![Security Rating](https://camo.githubusercontent.com/af72796b463b5668b8c8d6e54fdd52d983fc2752ecd035f2372b031a22553a9a/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6f776e636c6f75645f6f6369732d7068702d73646b266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/summary/new_code?id=owncloud_ocis-php-sdk)

ocis-php-sdk
============

[](#ocis-php-sdk)

This SDK allows you to interact with [ownCloud Infinite Scale (oCIS)](https://github.com/owncloud/ocis/) storage using PHP.

Documentation
-------------

[](#documentation)

You can find a rendered version of the [API documentation](https://owncloud.dev/ocis-php-sdk/) in our dev docs.

To render the documentation locally, use the [phpDocumentor](https://www.phpdoc.org/) which needs to run in the root of the local repo. To do so, type the following example command:

```
docker run --rm -v ${PWD}:/data --user $(id -u):$(id -g) phpdoc/phpdoc:3

```

After the successful build, you will find the documentation inside the `docs` folder.

Installation via Composer
-------------------------

[](#installation-via-composer)

Add "owncloud/ocis-php-sdk" to the `require` block in your composer.json and then run composer install.

Warning

The ocis-php-sdk currently relies on a development version of the "owncloud/libre-graph-api-php" package. To ensure proper dependency resolution, it is necessary to set "minimum-stability": "dev" and "prefer-stable": true in your composer.json file.

```
{
    "minimum-stability": "dev",
    "prefer-stable": true,
    "require": {
        "owncloud/ocis-php-sdk": "^1.0"
    }
}
```

Alternatively, you can simply run the following from the command line:

```
composer config minimum-stability dev
composer config prefer-stable true
composer require owncloud/ocis-php-sdk
```

Getting started
---------------

[](#getting-started)

Ocis has two types of access token, one which is used to interact with drive, group, user, shares etc.(OICD access token) and another which can be used to interact with education endpoints (education access token).

Create an Ocis object using the service Url and an OIDC access token:

```
$ocis = new Ocis('https://example.ocis.com', $accessToken);
```

Or create an Ocis object to interact with education endpoints using the service Url and an education access token:

```
$ocis = new Ocis('https://education.ocis.com', null, [], $educationAccessToken);
```

At least one access token should be provided to use the SDK.

Acquiring an OICD access token is out of scope of this SDK, but you can find [examples for that below](#acquiring-an-access-token).

Also refreshing OICD tokens is not part of the SDK, but after you got a new token, you can update the Ocis object:

```
$ocis->setAccessToken($newAccessToken);
```

Education access token is set when starting the ocis graph server. You can get it using following snippet

```
$educationAccessToken = getenv("GRAPH_HTTP_API_TOKEN")
```

Drives (spaces)
---------------

[](#drives-spaces)

Drives can be listed using the `getAllDrives` or the `getMyDrives` method.

The Drive class is responsible for most file/folder related actions, like listing files, creating folders, uploading files, etc.

```
// get the personal drive of the authorized user
// `getMyDrives` returns all drives that the user is a member of
// but in this example the result is filtered to only return
// the personal drive (parameter 3 = DriveType::PERSONAL)
$drives = $ocis->getMyDrives(
    DriveOrder::NAME,
    OrderDirection::ASC,
    DriveType::PERSONAL
);

// get the drive id
$id = $drives[0]->getId();

// get the name of the drive
$name = $drives[0]->getName();

// get a link to the drive that can be opened in a browser and will lead the user to the web interface
$webUrl = $drives[0]->getWebUrl();

// create a folder inside the drive
$drives[0]->createFolder("/documents");

// upload a file to the drive
$drives[0]->uploadFile("/documents/myfile.txt", "Hello World!");

// get an array of all resources of the "/documents" folder inside the drive
$resources = $drives[0]->getResources("/documents");
```

### Drive Permission

[](#drive-permission)

Users/Groups can be invited to drives by specifying permissions. The **Drive** class has methods to invite Users/Groups, update permission roles and expiration dates, remove users and groups, etc.

Drive invitations are only possible on **project drives**.

```
// find all users with a specific surname
$users = $ocis->getUsers("einstein")[0];

// get all drives of type project
$drives = $ocis->getMyDrives(
    DriveOrder::NAME,
    OrderDirection::ASC,
    DriveType::PROJECT
);

// get the drive named 'game'
foreach ($drives as $drive) {
    if ($drive->getName) === 'game' {
        $gameDrive = $drive;
        break;
    }
}

// get all roles that are possible for that drive
$driveRoles = $gameDrive->getRoles();

// get the role that is allowed to view, download, upload, edit, add, delete and manage members
foreach ($driveRoles as $role) {
    if ($role->getDisplayName() === 'Manager') {
        $managerRole = $role;
        break;
    }
}

// invite user einstein on project drive 'game' with manager permission
$gameDrive->invite($users, $managerRole);
```

Notifications
-------------

[](#notifications)

Notifications can be listed using the `getNotifications` method, which will return an array of `Notification` objects representing all active notifications.

The `Notification` object can retrieve details of the corresponding notification and mark it as read (delete).

Sharing
-------

[](#sharing)

Given the correct permissions, an `OcisResource` can be shared with a group or a user. To define the access permissions of the receiver every share has to set `SharingRole`(s).

```
// get the resources of a subfolder inside a drive
$resources = $drive->getResources("/documents");

// get all roles that are possible for that particular resource
$roles = $resources[0]->getRoles();

// find the role that is allowed to read and write the shared file or folder
for ($roles as $role) {
    if ($role->getDisplayName() === 'Can edit') {
        $editorRole = $role;
        break;
    }
}

// find all users with a specific surname
$users = $ocis->getUsers("einstein")[0];

// share the resource with the users
$resources[0]->invite($users, $editorRole);
```

Education User
--------------

[](#education-user)

Education Users can only be created, listed and deleted using education access token. If you want to use other APIs you need to use the OICD access token.

```
// create education user
$educationUsers = $ocis->createEducationUser()
// list all education user
$educationUsers = $ocis->getEducationUsers()
// list education user by id
$educationUsers = $ocis->getEducationUserById()
// delete education user
$educationUser[0]->delete()
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- oCIS 5.0.0 or higher

Acquiring an Access Token
-------------------------

[](#acquiring-an-access-token)

For an easier experience in acquiring an access token, several PHP OIDC client libraries are available. The following code snippet showcases how to retrieve an access token with the `facile-it/php-openid-client` library.

### Install PHP dependencies

[](#install-php-dependencies)

You can install the [facile-it/php-openid-client](https://github.com/facile-it/php-openid-client) library using composer:

```
composer require facile-it/php-openid-client
composer require nyholm/psr7

```

### Required PHP Libraries

[](#required-php-libraries)

- php-bcmath
- php-gmp

### Code Snippet to Fetch an Access Token

[](#code-snippet-to-fetch-an-access-token)

```
