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
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Appwrite PHP SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-php.svg?style=flat-square&v=1)
![Version](https://img.shields.io/badge/api%20version-0.8.0-blue.svg?style=flat-square&v=1)
![Version](https://img.shields.io/badge/api%20version-0.9.0-blue.svg?style=flat-square&v=1)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite_io?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite_io)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK is compatible with Appwrite server version 0.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-php/releases).**
**This SDK is compatible with Appwrite server version 0.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-php/releases).**

Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way.
Use the PHP SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools.
For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the PHP SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)

![Appwrite](https://appwrite.io/images/github.png)

Expand All @@ -25,7 +24,7 @@ composer require appwrite/appwrite
## Getting Started

### Init your SDK
Initialize your SDK code with your project ID which can be found in your project settings page and your new API secret Key from project's API keys section.
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key from project's API keys section.

```php
$client = new Client();
Expand All @@ -39,7 +38,7 @@ $client
```

### Make Your First Request
Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the API References section.
Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section.

```php
$users = new Users($client);
Expand Down Expand Up @@ -80,7 +79,7 @@ try {
```

### Learn more
You can use followng resources to learn more and get help
You can use following resources to learn more and get help
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server)
- 📜 [Appwrite Docs](https://appwrite.io/docs)
- 💬 [Discord Community](https://appwrite.io/discord)
Expand Down
14 changes: 14 additions & 0 deletions docs/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ DELETE https://appwrite.io/v1/account/sessions

** Delete all sessions from the user account and remove any sessions cookies from the end client. **

## Get Session By ID

```http request
GET https://appwrite.io/v1/account/sessions/{sessionId}
```

** Use this endpoint to get a logged in user's session using a Session ID. Inputting 'current' will return the current session being used. **

### Parameters

| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| sessionId | string | **Required** Session unique ID. Use the string 'current' to get the current device session. | |

## Delete Account Session

```http request
Expand Down
16 changes: 16 additions & 0 deletions docs/examples/account/get-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Appwrite\Client;
use Appwrite\Services\Account;

$client = new Client();

$client
->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
->setProject('5df5acd0d48c2') // Your project ID
->setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token
;

$account = new Account($client);

$result = $account->getSession('[SESSION_ID]');
2 changes: 1 addition & 1 deletion docs/examples/functions/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ $client

$functions = new Functions($client);

$result = $functions->create('[NAME]', [], 'dotnet-3.1');
$result = $functions->create('[NAME]', [], 'java-11.0');
16 changes: 16 additions & 0 deletions docs/examples/users/update-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Appwrite\Client;
use Appwrite\Services\Users;

$client = new Client();

$client
->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
->setProject('5df5acd0d48c2') // Your project ID
->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;

$users = new Users($client);

$result = $users->updateVerification('[USER_ID]', false);
2 changes: 1 addition & 1 deletion docs/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ POST https://appwrite.io/v1/functions
| --- | --- | --- | --- |
| name | string | Function name. Max length: 128 chars. | |
| execute | array | An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
| env | string | Execution enviornment. | |
| runtime | string | Execution runtime. | |
| vars | object | Key-value JSON object. | {} |
| events | array | Events list. | [] |
| schedule | string | Schedule CRON syntax. | |
Expand Down
3 changes: 2 additions & 1 deletion docs/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ GET https://appwrite.io/v1/storage/files/{fileId}/preview
| fileId | string | **Required** File unique ID | |
| width | integer | Resize preview image width, Pass an integer between 0 to 4000. | 0 |
| height | integer | Resize preview image height, Pass an integer between 0 to 4000. | 0 |
| gravity | string | Image crop gravity. Can be one of center,top-left,top,top-right,left,right,bottom-left,bottom,bottom-right | center |
| quality | integer | Preview image quality. Pass an integer between 0 to 100. Defaults to 100. | 100 |
| borderWidth | integer | Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0. | 0 |
| borderColor | string | Preview image border color. Use a valid HEX color, no # is needed for prefix. | |
| borderRadius | integer | Preview image border radius in pixels. Pass an integer between 0 to 4000. | 0 |
| opacity | integer | Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1. | 1 |
| opacity | number | Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1. | 1 |
| rotation | integer | Preview image rotation in degrees. Pass an integer between 0 and 360. | 0 |
| background | string | Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix. | |
| output | string | Output format type (jpeg, jpg, png, gif and webp). | |
Expand Down
15 changes: 15 additions & 0 deletions docs/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,18 @@ PATCH https://appwrite.io/v1/users/{userId}/status
| userId | string | **Required** User unique ID. | |
| status | integer | User Status code. To activate the user pass 1, to block the user pass 2 and for disabling the user pass 0 | |

## Update Email Verification

```http request
PATCH https://appwrite.io/v1/users/{userId}/verification
```

** Update the user email verification status by its unique ID. **

### Parameters

| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| userId | string | **Required** User unique ID. | |
| emailVerification | boolean | User Email Verification Status. | |

4 changes: 2 additions & 2 deletions src/Appwrite/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class Client
*/
protected $headers = [
'content-type' => '',
'x-sdk-version' => 'appwrite:php:2.1.2',
'x-sdk-version' => 'appwrite:php:2.2.0',
];

/**
* SDK constructor.
*/
public function __construct()
{
$this->headers['X-Appwrite-Response-Format'] = '0.8.0';
$this->headers['X-Appwrite-Response-Format'] = '0.9.0';

}

Expand Down
24 changes: 24 additions & 0 deletions src/Appwrite/Services/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,30 @@ public function deleteSessions(): array
], $params);
}

/**
* Get Session By ID
*
* Use this endpoint to get a logged in user's session using a Session ID.
* Inputting 'current' will return the current session being used.
*
* @param string $sessionId
* @throws AppwriteException
* @return array
*/
public function getSession(string $sessionId): array
{
if (empty($sessionId)) {
throw new AppwriteException('Missing required parameter: "sessionId"');
}

$path = str_replace(['{sessionId}'], [$sessionId], '/account/sessions/{sessionId}');
$params = [];

return $this->client->call(Client::METHOD_GET, $path, [
'content-type' => 'application/json',
], $params);
}

/**
* Delete Account Session
*
Expand Down
12 changes: 6 additions & 6 deletions src/Appwrite/Services/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public function list(string $search = null, int $limit = null, int $offset = nul
*
* @param string $name
* @param array $execute
* @param string $env
* @param string $runtime
* @param array $vars
* @param array $events
* @param string $schedule
* @param int $timeout
* @throws AppwriteException
* @return array
*/
public function create(string $name, array $execute, string $env, array $vars = null, array $events = null, string $schedule = null, int $timeout = null): array
public function create(string $name, array $execute, string $runtime, array $vars = null, array $events = null, string $schedule = null, int $timeout = null): array
{
if (empty($name)) {
throw new AppwriteException('Missing required parameter: "name"');
Expand All @@ -74,8 +74,8 @@ public function create(string $name, array $execute, string $env, array $vars =
throw new AppwriteException('Missing required parameter: "execute"');
}

if (empty($env)) {
throw new AppwriteException('Missing required parameter: "env"');
if (empty($runtime)) {
throw new AppwriteException('Missing required parameter: "runtime"');
}

$path = str_replace([], [], '/functions');
Expand All @@ -89,8 +89,8 @@ public function create(string $name, array $execute, string $env, array $vars =
$params['execute'] = $execute;
}

if (!is_null($env)) {
$params['env'] = $env;
if (!is_null($runtime)) {
$params['runtime'] = $runtime;
}

if (!is_null($vars)) {
Expand Down
7 changes: 6 additions & 1 deletion src/Appwrite/Services/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public function getFileDownload(string $fileId): string
* @param string $fileId
* @param int $width
* @param int $height
* @param string $gravity
* @param int $quality
* @param int $borderWidth
* @param string $borderColor
Expand All @@ -224,7 +225,7 @@ public function getFileDownload(string $fileId): string
* @throws AppwriteException
* @return string
*/
public function getFilePreview(string $fileId, int $width = null, int $height = null, int $quality = null, int $borderWidth = null, string $borderColor = null, int $borderRadius = null, int $opacity = null, int $rotation = null, string $background = null, string $output = null): string
public function getFilePreview(string $fileId, int $width = null, int $height = null, string $gravity = null, int $quality = null, int $borderWidth = null, string $borderColor = null, int $borderRadius = null, int $opacity = null, int $rotation = null, string $background = null, string $output = null): string
{
if (empty($fileId)) {
throw new AppwriteException('Missing required parameter: "fileId"');
Expand All @@ -241,6 +242,10 @@ public function getFilePreview(string $fileId, int $width = null, int $height =
$params['height'] = $height;
}

if (!is_null($gravity)) {
$params['gravity'] = $gravity;
}

if (!is_null($quality)) {
$params['quality'] = $quality;
}
Expand Down
32 changes: 32 additions & 0 deletions src/Appwrite/Services/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,36 @@ public function updateStatus(string $userId, int $status): array
'content-type' => 'application/json',
], $params);
}

/**
* Update Email Verification
*
* Update the user email verification status by its unique ID.
*
* @param string $userId
* @param bool $emailVerification
* @throws AppwriteException
* @return array
*/
public function updateVerification(string $userId, bool $emailVerification): array
{
if (empty($userId)) {
throw new AppwriteException('Missing required parameter: "userId"');
}

if (empty($emailVerification)) {
throw new AppwriteException('Missing required parameter: "emailVerification"');
}

$path = str_replace(['{userId}'], [$userId], '/users/{userId}/verification');
$params = [];

if (!is_null($emailVerification)) {
$params['emailVerification'] = $emailVerification;
}

return $this->client->call(Client::METHOD_PATCH, $path, [
'content-type' => 'application/json',
], $params);
}
}