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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## 32.2.0

* Added: `Project::getPrefs` and `Project::updatePrefs` for project preferences, and `Project::$prefs`
* Added: `AppwriteMigrationResource::PROJECTPREFERENCES()` to migrate project preferences
* Added: `Client::setEnvironment` to act in a project environment
* Added: `monitors.read`, `monitors.write`, `alerts.read`, `reviews.read` and `reviews.write` to `ProjectKeyScopes`
* Added: `Organization::$budgetNotify` and `Organization::$educationExpiresAt`
* Updated: requests send `X-Appwrite-Response-Format: 2.7.0`; README targets Appwrite 2.7.x

## 32.1.0

* Updated: protected `Client::getHttpClient()` and `createHttpClient()` drop their `bool` argument; `$httpClientNoRedirect` removed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Appwrite PHP SDK

![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-2.6.2-blue.svg?style=flat-square&v=1)
![Version](https://img.shields.io/badge/api%20version-2.7.0-blue.svg?style=flat-square&v=1)
[![X Account](https://img.shields.io/badge/follow-%40appwrite-000000?logo=x&style=flat-square)](https://x.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK targets Appwrite server version 2.6.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-php/releases) when APIs differ.
**This SDK targets Appwrite server version 2.7.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-php/releases) when APIs differ.

Appwrite is an open-source backend as a service server that abstracts and simplifies 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)

Expand Down
15 changes: 15 additions & 0 deletions docs/examples/project/get-prefs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```php
<?php

use Appwrite\Client;
use Appwrite\Services\Project;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setKey('<YOUR_API_KEY>'); // Your secret API key

$project = new Project($client);

$result = $project->getPrefs();
```
17 changes: 17 additions & 0 deletions docs/examples/project/update-prefs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```php
<?php

use Appwrite\Client;
use Appwrite\Services\Project;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setKey('<YOUR_API_KEY>'); // Your secret API key

$project = new Project($client);

$result = $project->updatePrefs(
prefs: []
);
```
20 changes: 20 additions & 0 deletions docs/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,26 @@ GET https://cloud.appwrite.io/v1/project/policies/{policyId}
| policyId | string | **Required** Policy ID. Can be one of: password-dictionary, password-history, password-strength, password-personal-data, password-pwned, password-rotation, session-alert, session-duration, session-invalidation, session-limit, user-limit, membership-privacy, mfa-factors, deny-aliased-email, deny-disposable-email, deny-free-email, deny-corporate-email, deny-realtime-guests, passkey. | |


```http request
GET https://cloud.appwrite.io/v1/project/prefs
```

** Get the project preferences. Preferences are a key-value object stored on the project for anyone working on it. **


```http request
PUT https://cloud.appwrite.io/v1/project/prefs
```

** Update the project preferences. The object you pass is stored as is and replaces any previous value. The maximum allowed prefs size is 64kB and throws an error if exceeded. **

### Parameters

| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| prefs | object | Prefs key-value JSON object. | {} |


```http request
PATCH https://cloud.appwrite.io/v1/project/protocols/{protocolId}
```
Expand Down
21 changes: 18 additions & 3 deletions src/Appwrite/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class Client
*
*/
protected array $headers = [
'user-agent' => 'AppwritePHPSDK/32.1.0 ()',
'user-agent' => 'AppwritePHPSDK/32.2.0 ()',
'x-sdk-name' => 'PHP',
'x-sdk-platform' => 'server',
'x-sdk-language' => 'php',
'x-sdk-version' => '32.1.0',
'x-sdk-version' => '32.2.0',
];

/**
Expand Down Expand Up @@ -108,7 +108,7 @@ class Client
public function __construct(private readonly ?ClientInterface $transport = null)
{
$this->requestFactory = new RequestFactory();
$this->headers['X-Appwrite-Response-Format'] = '2.6.2';
$this->headers['X-Appwrite-Response-Format'] = '2.7.0';
}

/**
Expand Down Expand Up @@ -201,6 +201,21 @@ public function setLocale(string $value): Client
return $this;
}

/**
* Set Environment
*
* The ID of the project environment to act in, alongside the project ID. Used with Appwrite Cloud projects that have environments.
*
*
*/
public function setEnvironment(string $value): Client
{
$this->addHeader('X-Appwrite-Environment', $value);
$this->config['environment'] = $value;

return $this;
}

/**
* Set Session
*
Expand Down
8 changes: 8 additions & 0 deletions src/Appwrite/Enums/AppwriteMigrationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class AppwriteMigrationResource implements JsonSerializable, Stringable
private static AppwriteMigrationResource $PROJECTVARIABLE;
private static AppwriteMigrationResource $PROJECTPROTOCOLS;
private static AppwriteMigrationResource $PROJECTLABELS;
private static AppwriteMigrationResource $PROJECTPREFERENCES;
private static AppwriteMigrationResource $PROJECTSERVICES;
private static AppwriteMigrationResource $PROJECTEMAILTEMPLATE;
private static AppwriteMigrationResource $PROJECTENVIRONMENT;
Expand Down Expand Up @@ -280,6 +281,12 @@ public static function PROJECTLABELS(): AppwriteMigrationResource

return self::$PROJECTLABELS;
}
public static function PROJECTPREFERENCES(): AppwriteMigrationResource
{
self::$PROJECTPREFERENCES ??= new AppwriteMigrationResource('project-preferences');

return self::$PROJECTPREFERENCES;
}
public static function PROJECTSERVICES(): AppwriteMigrationResource
{
self::$PROJECTSERVICES ??= new AppwriteMigrationResource('project-services');
Expand Down Expand Up @@ -344,6 +351,7 @@ public static function from(string $value): self
'project-variable' => self::PROJECTVARIABLE(),
'project-protocols' => self::PROJECTPROTOCOLS(),
'project-labels' => self::PROJECTLABELS(),
'project-preferences' => self::PROJECTPREFERENCES(),
'project-services' => self::PROJECTSERVICES(),
'project-email-template' => self::PROJECTEMAILTEMPLATE(),
'project-environment' => self::PROJECTENVIRONMENT(),
Expand Down
40 changes: 40 additions & 0 deletions src/Appwrite/Enums/ProjectKeyScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class ProjectKeyScopes implements JsonSerializable, Stringable
private static ProjectKeyScopes $RULESWRITE;
private static ProjectKeyScopes $WEBHOOKSREAD;
private static ProjectKeyScopes $WEBHOOKSWRITE;
private static ProjectKeyScopes $MONITORSREAD;
private static ProjectKeyScopes $MONITORSWRITE;
private static ProjectKeyScopes $ALERTSREAD;
private static ProjectKeyScopes $LOCALEREAD;
private static ProjectKeyScopes $AVATARSREAD;
private static ProjectKeyScopes $AVATARSWRITE;
Expand All @@ -112,6 +115,8 @@ class ProjectKeyScopes implements JsonSerializable, Stringable
private static ProjectKeyScopes $INSIGHTSWRITE;
private static ProjectKeyScopes $REPORTSREAD;
private static ProjectKeyScopes $REPORTSWRITE;
private static ProjectKeyScopes $REVIEWSREAD;
private static ProjectKeyScopes $REVIEWSWRITE;
private static ProjectKeyScopes $PRESENCESREAD;
private static ProjectKeyScopes $PRESENCESWRITE;
private static ProjectKeyScopes $DEDICATEDDATABASESEXECUTE;
Expand Down Expand Up @@ -677,6 +682,24 @@ public static function WEBHOOKSWRITE(): ProjectKeyScopes

return self::$WEBHOOKSWRITE;
}
public static function MONITORSREAD(): ProjectKeyScopes
{
self::$MONITORSREAD ??= new ProjectKeyScopes('monitors.read');

return self::$MONITORSREAD;
}
public static function MONITORSWRITE(): ProjectKeyScopes
{
self::$MONITORSWRITE ??= new ProjectKeyScopes('monitors.write');

return self::$MONITORSWRITE;
}
public static function ALERTSREAD(): ProjectKeyScopes
{
self::$ALERTSREAD ??= new ProjectKeyScopes('alerts.read');

return self::$ALERTSREAD;
}
public static function LOCALEREAD(): ProjectKeyScopes
{
self::$LOCALEREAD ??= new ProjectKeyScopes('locale.read');
Expand Down Expand Up @@ -767,6 +790,18 @@ public static function REPORTSWRITE(): ProjectKeyScopes

return self::$REPORTSWRITE;
}
public static function REVIEWSREAD(): ProjectKeyScopes
{
self::$REVIEWSREAD ??= new ProjectKeyScopes('reviews.read');

return self::$REVIEWSREAD;
}
public static function REVIEWSWRITE(): ProjectKeyScopes
{
self::$REVIEWSWRITE ??= new ProjectKeyScopes('reviews.write');

return self::$REVIEWSWRITE;
}
public static function PRESENCESREAD(): ProjectKeyScopes
{
self::$PRESENCESREAD ??= new ProjectKeyScopes('presences.read');
Expand Down Expand Up @@ -991,6 +1026,9 @@ public static function from(string $value): self
'rules.write' => self::RULESWRITE(),
'webhooks.read' => self::WEBHOOKSREAD(),
'webhooks.write' => self::WEBHOOKSWRITE(),
'monitors.read' => self::MONITORSREAD(),
'monitors.write' => self::MONITORSWRITE(),
'alerts.read' => self::ALERTSREAD(),
'locale.read' => self::LOCALEREAD(),
'avatars.read' => self::AVATARSREAD(),
'avatars.write' => self::AVATARSWRITE(),
Expand All @@ -1006,6 +1044,8 @@ public static function from(string $value): self
'insights.write' => self::INSIGHTSWRITE(),
'reports.read' => self::REPORTSREAD(),
'reports.write' => self::REPORTSWRITE(),
'reviews.read' => self::REVIEWSREAD(),
'reviews.write' => self::REVIEWSWRITE(),
'presences.read' => self::PRESENCESREAD(),
'presences.write' => self::PRESENCESWRITE(),
'dedicatedDatabases.execute' => self::DEDICATEDDATABASESEXECUTE(),
Expand Down
9 changes: 9 additions & 0 deletions src/Appwrite/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @param int $total total number of team members.
* @param Preferences $prefs team preferences as a key-value object
* @param array $budgetAlerts project budget limit
* @param array $budgetNotify organization roles whose confirmed members are emailed when a budget alert fires.
* @param string $billingPlan organization's billing plan id.
* @param string $billingPlanId organization's billing plan id.
* @param BillingPlan $billingPlanDetails organization's billing plan.
Expand All @@ -48,6 +49,7 @@
* @param string|null $programManagerCalendar program manager's calendar link.
* @param string|null $programDiscordChannelName program's discord channel name.
* @param string|null $programDiscordChannelUrl program's discord channel url.
* @param string|null $educationExpiresAt when the education plan ends, for an organization on it.
* @param BillingLimits|null $billingLimits billing limits reached
* @param string|null $billingPlanDowngrade billing plan selected for downgrade.
* @param string|null $billingTaxId tax id
Expand All @@ -60,6 +62,7 @@ public function __construct(
public int $total,
public Preferences $prefs,
public array $budgetAlerts,
public array $budgetNotify,
public string $billingPlan,
public string $billingPlanId,
public BillingPlan $billingPlanDetails,
Expand All @@ -85,6 +88,7 @@ public function __construct(
public ?string $programManagerCalendar = null,
public ?string $programDiscordChannelName = null,
public ?string $programDiscordChannelUrl = null,
public ?string $educationExpiresAt = null,
public ?BillingLimits $billingLimits = null,
public ?string $billingPlanDowngrade = null,
public ?string $billingTaxId = null
Expand All @@ -103,6 +107,7 @@ public static function from(array $data): static
'name' => "",
'total' => 0,
'budgetAlerts' => [75],
'budgetNotify' => ["owner", "billing"],
'billingPlan' => "tier-0",
'billingPlanId' => "tier-0",
'billingEmail' => "",
Expand All @@ -127,6 +132,7 @@ public static function from(array $data): static
total: $data['total'],
prefs: static::hydrateTypedValue(Preferences::class, $data['prefs']),
budgetAlerts: $data['budgetAlerts'],
budgetNotify: $data['budgetNotify'],
billingPlan: $data['billingPlan'],
billingPlanId: $data['billingPlanId'],
billingPlanDetails: static::hydrateTypedValue(BillingPlan::class, $data['billingPlanDetails']),
Expand All @@ -152,6 +158,7 @@ public static function from(array $data): static
programManagerCalendar: $data['programManagerCalendar'] ?? null,
programDiscordChannelName: $data['programDiscordChannelName'] ?? null,
programDiscordChannelUrl: $data['programDiscordChannelUrl'] ?? null,
educationExpiresAt: $data['educationExpiresAt'] ?? null,
billingLimits: array_key_exists('billingLimits', $data) ? static::hydrateTypedValue(BillingLimits::class, $data['billingLimits'], true) : null,
billingPlanDowngrade: $data['billingPlanDowngrade'] ?? null,
billingTaxId: $data['billingTaxId'] ?? null
Expand All @@ -172,6 +179,7 @@ public function toArray(): array
'prefs' => static::serializeValue($this->prefs),
'billingBudget' => static::serializeValue($this->billingBudget),
'budgetAlerts' => static::serializeValue($this->budgetAlerts),
'budgetNotify' => static::serializeValue($this->budgetNotify),
'billingPlan' => static::serializeValue($this->billingPlan),
'billingPlanId' => static::serializeValue($this->billingPlanId),
'billingPlanDetails' => static::serializeValue($this->billingPlanDetails),
Expand All @@ -193,6 +201,7 @@ public function toArray(): array
'programManagerCalendar' => static::serializeValue($this->programManagerCalendar),
'programDiscordChannelName' => static::serializeValue($this->programDiscordChannelName),
'programDiscordChannelUrl' => static::serializeValue($this->programDiscordChannelUrl),
'educationExpiresAt' => static::serializeValue($this->educationExpiresAt),
'billingLimits' => static::serializeValue($this->billingLimits),
'billingPlanDowngrade' => static::serializeValue($this->billingPlanDowngrade),
'billingTaxId' => static::serializeValue($this->billingTaxId),
Expand Down
4 changes: 4 additions & 0 deletions src/Appwrite/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @param list<ProjectProtocol> $protocols list of protocols.
* @param list<Block> $blocks project blocks information
* @param string $consoleAccessedAt last time the project was accessed via console. used with plan's projectinactivitydays to determine if project is paused.
* @param Preferences|null $prefs project preferences as a key-value object
* @param bool|null $wafEnabled whether waf enforcement is enabled for the project.
* @param string|null $parentId id of the project this environment belongs to. null when the project is not an environment.
* @param BillingLimits|null $billingLimits billing limits reached
Expand Down Expand Up @@ -92,6 +93,7 @@ public function __construct(
public array $protocols,
public array $blocks,
public string $consoleAccessedAt,
public ?Preferences $prefs = null,
public ?bool $wafEnabled = null,
public ?string $parentId = null,
public ?BillingLimits $billingLimits = null,
Expand Down Expand Up @@ -198,6 +200,7 @@ public static function from(array $data): static
)
: $data['blocks'],
consoleAccessedAt: $data['consoleAccessedAt'],
prefs: array_key_exists('prefs', $data) ? static::hydrateTypedValue(Preferences::class, $data['prefs'], true) : null,
wafEnabled: $data['wafEnabled'] ?? null,
parentId: $data['parentId'] ?? null,
billingLimits: array_key_exists('billingLimits', $data) ? static::hydrateTypedValue(BillingLimits::class, $data['billingLimits'], true) : null,
Expand Down Expand Up @@ -248,6 +251,7 @@ public function toArray(): array
'pingCount' => static::serializeValue($this->pingCount),
'pingedAt' => static::serializeValue($this->pingedAt),
'labels' => static::serializeValue($this->labels),
'prefs' => static::serializeValue($this->prefs),
'status' => static::serializeValue($this->status),
'onboarding' => static::serializeValue($this->onboarding),
'authMethods' => static::serializeValue($this->authMethods),
Expand Down
Loading