diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e0f6e96..bf49df96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Change Log +## 23.0.0 + +* [BREAKING] Renamed Webhook model fields: `security` → `tls`, `httpUser` → `authUsername`, `httpPass` → `authPassword`, `signatureKey` → `secret` +* [BREAKING] Renamed Webhook service parameters to match: `security` → `tls`, `httpUser` → `authUsername`, `httpPass` → `authPassword` +* [BREAKING] Renamed `Webhooks::updateSignature()` to `Webhooks::updateSecret()` with new optional `secret` parameter +* Added `from(array)` static factory method and `toArray()` serializer to all response models with required-field validation +* Added `secret` parameter to Webhook create and update methods +* Added `x` OAuth provider to `OAuthProvider` enum +* Added `userType` field to `Log` model +* Added `purge` parameter to `updateCollection` and `updateTable` for cache invalidation +* Added Project service: platform CRUD, key CRUD, protocol/service status management +* Added new models: `Key`, `KeyList`, `Project`, `DevKey`, `MockNumber`, `AuthProvider`, `PlatformAndroid`, `PlatformApple`, `PlatformLinux`, `PlatformList`, `PlatformWeb`, `PlatformWindows`, `BillingLimits`, `Block` +* Added new enums: `PlatformType`, `ProtocolId`, `ServiceId` +* Updated `BuildRuntime`, `Runtime` enums with `dart-3.11` and `flutter-3.41` +* Updated `Scopes` enum with `keysRead`, `keysWrite`, `platformsRead`, `platformsWrite` +* Updated `X-Appwrite-Response-Format` header to `1.9.1` +* Updated TTL description for list caching in Databases and TablesDB +* Replaced internal `FIELD_MAP`/`ARRAY_TYPES` constants and `parseResponse()` with explicit `Model::from()` hydration + ## 22.0.0 * [BREAKING] Raised minimum PHP version from 8.0 to 8.2 diff --git a/README.md b/README.md index fabdf436..1d399118 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # 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-1.9.0-blue.svg?style=flat-square&v=1) +![Version](https://img.shields.io/badge/api%20version-1.9.1-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?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) diff --git a/docs/account.md b/docs/account.md index 8c7314f3..11d4edbf 100644 --- a/docs/account.md +++ b/docs/account.md @@ -565,7 +565,7 @@ A user is limited to 10 active sessions at a time by default. [Learn more about | Field Name | Type | Description | Default | | --- | --- | --- | --- | -| provider | string | **Required** OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom. | | +| provider | string | **Required** OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, x, yahoo, yammer, yandex, zoho, zoom. | | | success | string | URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. | | | failure | string | URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. | | | scopes | array | A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. | [] | diff --git a/docs/databases.md b/docs/databases.md index 6adfc45d..71399a9b 100644 --- a/docs/databases.md +++ b/docs/databases.md @@ -220,6 +220,7 @@ PUT https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectionI | permissions | array | An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). | | | documentSecurity | boolean | Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions). | | | enabled | boolean | Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled. | 1 | +| purge | boolean | When true, purge all cached list responses for this collection as part of the update. Use this to force readers to see fresh data immediately instead of waiting for the cache TTL to expire. | | ```http request @@ -951,7 +952,7 @@ GET https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectionI | queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. | [] | | transactionId | string | Transaction ID to read uncommitted changes within the transaction. | | | total | boolean | When set to false, the total count returned will be 0 and will not be calculated. | 1 | -| ttl | integer | TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours). | 0 | +| ttl | integer | TTL (seconds) for caching list responses. Responses are stored in an in-memory key-value cache, keyed per project, collection, schema version (attributes and indexes), caller authorization roles, and the exact query — so users with different permissions never share cached entries. Schema changes invalidate cached entries automatically; document writes do not, so choose a TTL you are comfortable serving as stale data. Set to 0 to disable caching. Must be between 0 and 86400 (24 hours). | 0 | ```http request diff --git a/docs/examples/databases/update-collection.md b/docs/examples/databases/update-collection.md index 79271f6d..ddd369b1 100644 --- a/docs/examples/databases/update-collection.md +++ b/docs/examples/databases/update-collection.md @@ -19,5 +19,6 @@ $result = $databases->updateCollection( name: '', // optional permissions: [Permission::read(Role::any())], // optional documentSecurity: false, // optional - enabled: false // optional + enabled: false, // optional + purge: false // optional );``` diff --git a/docs/examples/project/create-android-platform.md b/docs/examples/project/create-android-platform.md new file mode 100644 index 00000000..491a36f3 --- /dev/null +++ b/docs/examples/project/create-android-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->createAndroidPlatform( + platformId: '', + name: '', + applicationId: '' +);``` diff --git a/docs/examples/project/create-apple-platform.md b/docs/examples/project/create-apple-platform.md new file mode 100644 index 00000000..38487ce9 --- /dev/null +++ b/docs/examples/project/create-apple-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->createApplePlatform( + platformId: '', + name: '', + bundleIdentifier: '' +);``` diff --git a/docs/examples/project/create-key.md b/docs/examples/project/create-key.md new file mode 100644 index 00000000..cd8020b0 --- /dev/null +++ b/docs/examples/project/create-key.md @@ -0,0 +1,20 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->createKey( + keyId: '', + name: '', + scopes: [Scopes::SESSIONSWRITE()], + expire: '2020-10-15T06:38:00.000+00:00' // optional +);``` diff --git a/docs/examples/project/create-linux-platform.md b/docs/examples/project/create-linux-platform.md new file mode 100644 index 00000000..ff21b34d --- /dev/null +++ b/docs/examples/project/create-linux-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->createLinuxPlatform( + platformId: '', + name: '', + packageName: '' +);``` diff --git a/docs/examples/project/create-web-platform.md b/docs/examples/project/create-web-platform.md new file mode 100644 index 00000000..932e10e9 --- /dev/null +++ b/docs/examples/project/create-web-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->createWebPlatform( + platformId: '', + name: '', + hostname: 'app.example.com' +);``` diff --git a/docs/examples/project/create-windows-platform.md b/docs/examples/project/create-windows-platform.md new file mode 100644 index 00000000..9a6f1757 --- /dev/null +++ b/docs/examples/project/create-windows-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->createWindowsPlatform( + platformId: '', + name: '', + packageIdentifierName: '' +);``` diff --git a/docs/examples/project/delete-key.md b/docs/examples/project/delete-key.md new file mode 100644 index 00000000..5e90c2e9 --- /dev/null +++ b/docs/examples/project/delete-key.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->deleteKey( + keyId: '' +);``` diff --git a/docs/examples/project/delete-platform.md b/docs/examples/project/delete-platform.md new file mode 100644 index 00000000..ca537aa2 --- /dev/null +++ b/docs/examples/project/delete-platform.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->deletePlatform( + platformId: '' +);``` diff --git a/docs/examples/project/get-key.md b/docs/examples/project/get-key.md new file mode 100644 index 00000000..8e8ba5e5 --- /dev/null +++ b/docs/examples/project/get-key.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->getKey( + keyId: '' +);``` diff --git a/docs/examples/project/get-platform.md b/docs/examples/project/get-platform.md new file mode 100644 index 00000000..3e783acb --- /dev/null +++ b/docs/examples/project/get-platform.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->getPlatform( + platformId: '' +);``` diff --git a/docs/examples/project/list-keys.md b/docs/examples/project/list-keys.md new file mode 100644 index 00000000..0d1dbffd --- /dev/null +++ b/docs/examples/project/list-keys.md @@ -0,0 +1,17 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->listKeys( + queries: [], // optional + total: false // optional +);``` diff --git a/docs/examples/project/list-platforms.md b/docs/examples/project/list-platforms.md new file mode 100644 index 00000000..596d6280 --- /dev/null +++ b/docs/examples/project/list-platforms.md @@ -0,0 +1,17 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->listPlatforms( + queries: [], // optional + total: false // optional +);``` diff --git a/docs/examples/project/update-android-platform.md b/docs/examples/project/update-android-platform.md new file mode 100644 index 00000000..43df5075 --- /dev/null +++ b/docs/examples/project/update-android-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateAndroidPlatform( + platformId: '', + name: '', + applicationId: '' +);``` diff --git a/docs/examples/project/update-apple-platform.md b/docs/examples/project/update-apple-platform.md new file mode 100644 index 00000000..2aa4f294 --- /dev/null +++ b/docs/examples/project/update-apple-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateApplePlatform( + platformId: '', + name: '', + bundleIdentifier: '' +);``` diff --git a/docs/examples/project/update-key.md b/docs/examples/project/update-key.md new file mode 100644 index 00000000..589f018a --- /dev/null +++ b/docs/examples/project/update-key.md @@ -0,0 +1,20 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateKey( + keyId: '', + name: '', + scopes: [Scopes::SESSIONSWRITE()], + expire: '2020-10-15T06:38:00.000+00:00' // optional +);``` diff --git a/docs/examples/project/update-labels.md b/docs/examples/project/update-labels.md new file mode 100644 index 00000000..1c2897ed --- /dev/null +++ b/docs/examples/project/update-labels.md @@ -0,0 +1,16 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateLabels( + labels: [] +);``` diff --git a/docs/examples/project/update-linux-platform.md b/docs/examples/project/update-linux-platform.md new file mode 100644 index 00000000..b05cbfaa --- /dev/null +++ b/docs/examples/project/update-linux-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateLinuxPlatform( + platformId: '', + name: '', + packageName: '' +);``` diff --git a/docs/examples/project/update-protocol-status.md b/docs/examples/project/update-protocol-status.md new file mode 100644 index 00000000..272332d3 --- /dev/null +++ b/docs/examples/project/update-protocol-status.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateProtocolStatus( + protocolId: ProtocolId::REST(), + enabled: false +);``` diff --git a/docs/examples/project/update-service-status.md b/docs/examples/project/update-service-status.md new file mode 100644 index 00000000..fea9614c --- /dev/null +++ b/docs/examples/project/update-service-status.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateServiceStatus( + serviceId: ServiceId::ACCOUNT(), + enabled: false +);``` diff --git a/docs/examples/project/update-web-platform.md b/docs/examples/project/update-web-platform.md new file mode 100644 index 00000000..213e96f7 --- /dev/null +++ b/docs/examples/project/update-web-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateWebPlatform( + platformId: '', + name: '', + hostname: 'app.example.com' +);``` diff --git a/docs/examples/project/update-windows-platform.md b/docs/examples/project/update-windows-platform.md new file mode 100644 index 00000000..40c881dd --- /dev/null +++ b/docs/examples/project/update-windows-platform.md @@ -0,0 +1,18 @@ +```php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your secret API key + +$project = new Project($client); + +$result = $project->updateWindowsPlatform( + platformId: '', + name: '', + packageIdentifierName: '' +);``` diff --git a/docs/examples/tablesdb/update-table.md b/docs/examples/tablesdb/update-table.md index 4409db26..7ce092d1 100644 --- a/docs/examples/tablesdb/update-table.md +++ b/docs/examples/tablesdb/update-table.md @@ -19,5 +19,6 @@ $result = $tablesDB->updateTable( name: '', // optional permissions: [Permission::read(Role::any())], // optional rowSecurity: false, // optional - enabled: false // optional + enabled: false, // optional + purge: false // optional );``` diff --git a/docs/examples/webhooks/create.md b/docs/examples/webhooks/create.md index 008a8167..4e017506 100644 --- a/docs/examples/webhooks/create.md +++ b/docs/examples/webhooks/create.md @@ -17,7 +17,8 @@ $result = $webhooks->create( name: '', events: [], enabled: false, // optional - security: false, // optional - httpUser: '', // optional - httpPass: '' // optional + tls: false, // optional + authUsername: '', // optional + authPassword: '', // optional + secret: '' // optional );``` diff --git a/docs/examples/webhooks/update-signature.md b/docs/examples/webhooks/update-secret.md similarity index 76% rename from docs/examples/webhooks/update-signature.md rename to docs/examples/webhooks/update-secret.md index 5101085f..73c3f955 100644 --- a/docs/examples/webhooks/update-signature.md +++ b/docs/examples/webhooks/update-secret.md @@ -11,6 +11,7 @@ $client = (new Client()) $webhooks = new Webhooks($client); -$result = $webhooks->updateSignature( - webhookId: '' +$result = $webhooks->updateSecret( + webhookId: '', + secret: '' // optional );``` diff --git a/docs/examples/webhooks/update.md b/docs/examples/webhooks/update.md index b253b1fc..8b71a93f 100644 --- a/docs/examples/webhooks/update.md +++ b/docs/examples/webhooks/update.md @@ -17,7 +17,7 @@ $result = $webhooks->update( url: '', events: [], enabled: false, // optional - security: false, // optional - httpUser: '', // optional - httpPass: '' // optional + tls: false, // optional + authUsername: '', // optional + authPassword: '' // optional );``` diff --git a/docs/project.md b/docs/project.md index eb7e26a9..903afa53 100644 --- a/docs/project.md +++ b/docs/project.md @@ -1,6 +1,309 @@ # Project Service +```http request +GET https://cloud.appwrite.io/v1/project/keys +``` + +** Get a list of all API keys from the current project. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: expire, accessedAt, name, scopes | [] | +| total | boolean | When set to false, the total count returned will be 0 and will not be calculated. | 1 | + + +```http request +POST https://cloud.appwrite.io/v1/project/keys +``` + +** Create a new API key. It's recommended to have multiple API keys with strict scopes for separate functions within your project. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| keyId | string | Key ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. | | +| name | string | Key name. Max length: 128 chars. | | +| scopes | array | Key scopes list. Maximum of 100 scopes are allowed. | | +| expire | string | Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration. | | + + +```http request +GET https://cloud.appwrite.io/v1/project/keys/{keyId} +``` + +** Get a key by its unique ID. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| keyId | string | **Required** Key ID. | | + + +```http request +PUT https://cloud.appwrite.io/v1/project/keys/{keyId} +``` + +** Update a key by its unique ID. Use this endpoint to update the name, scopes, or expiration time of an API key. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| keyId | string | **Required** Key ID. | | +| name | string | Key name. Max length: 128 chars. | | +| scopes | array | Key scopes list. Maximum of 100 scopes are allowed. | | +| expire | string | Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration. | | + + +```http request +DELETE https://cloud.appwrite.io/v1/project/keys/{keyId} +``` + +** Delete a key by its unique ID. Once deleted, the key can no longer be used to authenticate API calls. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| keyId | string | **Required** Key ID. | | + + +```http request +PUT https://cloud.appwrite.io/v1/project/labels +``` + +** Update the project labels. Labels can be used to easily filter projects in an organization. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| labels | array | Array of project labels. Replaces the previous labels. Maximum of 1000 labels are allowed, each up to 36 alphanumeric characters long. | | + + +```http request +GET https://cloud.appwrite.io/v1/project/platforms +``` + +** Get a list of all platforms in the project. This endpoint returns an array of all platforms and their configurations. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: type, name, hostname, bundleIdentifier, applicationId, packageIdentifierName, packageName | [] | +| total | boolean | When set to false, the total count returned will be 0 and will not be calculated. | 1 | + + +```http request +POST https://cloud.appwrite.io/v1/project/platforms/android +``` + +** Create a new Android platform for your project. Use this endpoint to register a new Android platform where your users will run your application which will interact with the Appwrite API. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | Platform ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. | | +| name | string | Platform name. Max length: 128 chars. | | +| applicationId | string | Android application ID. Max length: 256 chars. | | + + +```http request +PUT https://cloud.appwrite.io/v1/project/platforms/android/{platformId} +``` + +** Update an Android platform by its unique ID. Use this endpoint to update the platform's name or application ID. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | **Required** Platform ID. | | +| name | string | Platform name. Max length: 128 chars. | | +| applicationId | string | Android application ID. Max length: 256 chars. | | + + +```http request +POST https://cloud.appwrite.io/v1/project/platforms/apple +``` + +** Create a new Apple platform for your project. Use this endpoint to register a new Apple platform where your users will run your application which will interact with the Appwrite API. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | Platform ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. | | +| name | string | Platform name. Max length: 128 chars. | | +| bundleIdentifier | string | Apple bundle identifier. Max length: 256 chars. | | + + +```http request +PUT https://cloud.appwrite.io/v1/project/platforms/apple/{platformId} +``` + +** Update an Apple platform by its unique ID. Use this endpoint to update the platform's name or bundle identifier. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | **Required** Platform ID. | | +| name | string | Platform name. Max length: 128 chars. | | +| bundleIdentifier | string | Apple bundle identifier. Max length: 256 chars. | | + + +```http request +POST https://cloud.appwrite.io/v1/project/platforms/linux +``` + +** Create a new Linux platform for your project. Use this endpoint to register a new Linux platform where your users will run your application which will interact with the Appwrite API. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | Platform ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. | | +| name | string | Platform name. Max length: 128 chars. | | +| packageName | string | Linux package name. Max length: 256 chars. | | + + +```http request +PUT https://cloud.appwrite.io/v1/project/platforms/linux/{platformId} +``` + +** Update a Linux platform by its unique ID. Use this endpoint to update the platform's name or package name. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | **Required** Platform ID. | | +| name | string | Platform name. Max length: 128 chars. | | +| packageName | string | Linux package name. Max length: 256 chars. | | + + +```http request +POST https://cloud.appwrite.io/v1/project/platforms/web +``` + +** Create a new web platform for your project. Use this endpoint to register a new platform where your users will run your application which will interact with the Appwrite API. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | Platform ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. | | +| name | string | Platform name. Max length: 128 chars. | | +| hostname | string | Platform web hostname. Max length: 256 chars. | | + + +```http request +PUT https://cloud.appwrite.io/v1/project/platforms/web/{platformId} +``` + +** Update a web platform by its unique ID. Use this endpoint to update the platform's name or hostname. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | **Required** Platform ID. | | +| name | string | Platform name. Max length: 128 chars. | | +| hostname | string | Platform web hostname. Max length: 256 chars. | | + + +```http request +POST https://cloud.appwrite.io/v1/project/platforms/windows +``` + +** Create a new Windows platform for your project. Use this endpoint to register a new Windows platform where your users will run your application which will interact with the Appwrite API. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | Platform ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. | | +| name | string | Platform name. Max length: 128 chars. | | +| packageIdentifierName | string | Windows package identifier name. Max length: 256 chars. | | + + +```http request +PUT https://cloud.appwrite.io/v1/project/platforms/windows/{platformId} +``` + +** Update a Windows platform by its unique ID. Use this endpoint to update the platform's name or package identifier name. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | **Required** Platform ID. | | +| name | string | Platform name. Max length: 128 chars. | | +| packageIdentifierName | string | Windows package identifier name. Max length: 256 chars. | | + + +```http request +GET https://cloud.appwrite.io/v1/project/platforms/{platformId} +``` + +** Get a platform by its unique ID. This endpoint returns the platform's details, including its name, type, and key configurations. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | **Required** Platform ID. | | + + +```http request +DELETE https://cloud.appwrite.io/v1/project/platforms/{platformId} +``` + +** Delete a platform by its unique ID. This endpoint removes the platform and all its configurations from the project. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| platformId | string | **Required** Platform ID. | | + + +```http request +PATCH https://cloud.appwrite.io/v1/project/protocols/{protocolId}/status +``` + +** Update the status of a specific protocol. Use this endpoint to enable or disable a protocol in your project. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| protocolId | string | **Required** Protocol name. Can be one of: rest, graphql, websocket | | +| enabled | boolean | Protocol status. | | + + +```http request +PATCH https://cloud.appwrite.io/v1/project/services/{serviceId}/status +``` + +** Update the status of a specific service. Use this endpoint to enable or disable a service in your project. ** + +### Parameters + +| Field Name | Type | Description | Default | +| --- | --- | --- | --- | +| serviceId | string | **Required** Service name. Can be one of: account, avatars, databases, tablesdb, locale, health, project, storage, teams, users, vcs, sites, functions, proxy, graphql, migrations, messaging | | +| enabled | boolean | Service status. | | + + ```http request GET https://cloud.appwrite.io/v1/project/variables ``` diff --git a/docs/tablesdb.md b/docs/tablesdb.md index 326752c8..cd779b10 100644 --- a/docs/tablesdb.md +++ b/docs/tablesdb.md @@ -220,6 +220,7 @@ PUT https://cloud.appwrite.io/v1/tablesdb/{databaseId}/tables/{tableId} | permissions | array | An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). | | | rowSecurity | boolean | Enables configuring permissions for individual rows. A user needs one of row or table-level permissions to access a row. [Learn more about permissions](https://appwrite.io/docs/permissions). | | | enabled | boolean | Is table enabled? When set to 'disabled', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled. | 1 | +| purge | boolean | When true, purge all cached list responses for this table as part of the update. Use this to force readers to see fresh data immediately instead of waiting for the cache TTL to expire. | | ```http request @@ -1016,7 +1017,7 @@ GET https://cloud.appwrite.io/v1/tablesdb/{databaseId}/tables/{tableId}/rows | queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. | [] | | transactionId | string | Transaction ID to read uncommitted changes within the transaction. | | | total | boolean | When set to false, the total count returned will be 0 and will not be calculated. | 1 | -| ttl | integer | TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours). | 0 | +| ttl | integer | TTL (seconds) for caching list responses. Responses are stored in an in-memory key-value cache, keyed per project, table, schema version (columns and indexes), caller authorization roles, and the exact query — so users with different permissions never share cached entries. Schema changes invalidate cached entries automatically; row writes do not, so choose a TTL you are comfortable serving as stale data. Set to 0 to disable caching. Must be between 0 and 86400 (24 hours). | 0 | ```http request diff --git a/docs/webhooks.md b/docs/webhooks.md index 685b5cbd..c8b7ec5c 100644 --- a/docs/webhooks.md +++ b/docs/webhooks.md @@ -11,7 +11,7 @@ GET https://cloud.appwrite.io/v1/webhooks | Field Name | Type | Description | Default | | --- | --- | --- | --- | -| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, url, httpUser, security, events, enabled, logs, attempts | [] | +| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, url, authUsername, tls, events, enabled, logs, attempts | [] | | total | boolean | When set to false, the total count returned will be 0 and will not be calculated. | 1 | @@ -30,9 +30,10 @@ POST https://cloud.appwrite.io/v1/webhooks | name | string | Webhook name. Max length: 128 chars. | | | events | array | Events list. Maximum of 100 events are allowed. | | | enabled | boolean | Enable or disable a webhook. | 1 | -| security | boolean | Certificate verification, false for disabled or true for enabled. | | -| httpUser | string | Webhook HTTP user. Max length: 256 chars. | | -| httpPass | string | Webhook HTTP password. Max length: 256 chars. | | +| tls | boolean | Certificate verification, false for disabled or true for enabled. | | +| authUsername | string | Webhook HTTP user. Max length: 256 chars. | | +| authPassword | string | Webhook HTTP password. Max length: 256 chars. | | +| secret | string | Webhook secret key. If not provided, a new key will be generated automatically. Key must be at least 8 characters long, and at max 256 characters. | | ```http request @@ -63,9 +64,9 @@ PUT https://cloud.appwrite.io/v1/webhooks/{webhookId} | url | string | Webhook URL. | | | events | array | Events list. Maximum of 100 events are allowed. | | | enabled | boolean | Enable or disable a webhook. | 1 | -| security | boolean | Certificate verification, false for disabled or true for enabled. | | -| httpUser | string | Webhook HTTP user. Max length: 256 chars. | | -| httpPass | string | Webhook HTTP password. Max length: 256 chars. | | +| tls | boolean | Certificate verification, false for disabled or true for enabled. | | +| authUsername | string | Webhook HTTP user. Max length: 256 chars. | | +| authPassword | string | Webhook HTTP password. Max length: 256 chars. | | ```http request @@ -82,14 +83,15 @@ DELETE https://cloud.appwrite.io/v1/webhooks/{webhookId} ```http request -PATCH https://cloud.appwrite.io/v1/webhooks/{webhookId}/signature +PATCH https://cloud.appwrite.io/v1/webhooks/{webhookId}/secret ``` -** Update the webhook signature key. This endpoint can be used to regenerate the signature key used to sign and validate payload deliveries for a specific webhook. ** +** Update the webhook signing key. This endpoint can be used to regenerate the signing key used to sign and validate payload deliveries for a specific webhook. ** ### Parameters | Field Name | Type | Description | Default | | --- | --- | --- | --- | | webhookId | string | **Required** Webhook ID. | | +| secret | string | Webhook secret key. If not provided, a new key will be generated automatically. Key must be at least 8 characters long, and at max 256 characters. | | diff --git a/src/Appwrite/Client.php b/src/Appwrite/Client.php index 0a9c7ea6..69fac5af 100644 --- a/src/Appwrite/Client.php +++ b/src/Appwrite/Client.php @@ -37,11 +37,11 @@ class Client */ protected array $headers = [ 'content-type' => '', - 'user-agent' => 'AppwritePHPSDK/22.0.0 ()', + 'user-agent' => 'AppwritePHPSDK/23.0.0 ()', 'x-sdk-name'=> 'PHP', 'x-sdk-platform'=> 'server', 'x-sdk-language'=> 'php', - 'x-sdk-version'=> '22.0.0', + 'x-sdk-version'=> '23.0.0', ]; /** @@ -63,7 +63,7 @@ class Client */ public function __construct() { - $this->headers['X-Appwrite-Response-Format'] = '1.9.0'; + $this->headers['X-Appwrite-Response-Format'] = '1.9.1'; } diff --git a/src/Appwrite/Enums/OAuthProvider.php b/src/Appwrite/Enums/OAuthProvider.php index 70d70d52..a1938bd4 100644 --- a/src/Appwrite/Enums/OAuthProvider.php +++ b/src/Appwrite/Enums/OAuthProvider.php @@ -40,6 +40,7 @@ class OAuthProvider implements JsonSerializable private static OAuthProvider $TRADESHIFTBOX; private static OAuthProvider $TWITCH; private static OAuthProvider $WORDPRESS; + private static OAuthProvider $X; private static OAuthProvider $YAHOO; private static OAuthProvider $YAMMER; private static OAuthProvider $YANDEX; @@ -301,6 +302,13 @@ public static function WORDPRESS(): OAuthProvider } return self::$WORDPRESS; } + public static function X(): OAuthProvider + { + if (!isset(self::$X)) { + self::$X = new OAuthProvider('x'); + } + return self::$X; + } public static function YAHOO(): OAuthProvider { if (!isset(self::$YAHOO)) { @@ -374,6 +382,7 @@ public static function from(string $value): self 'tradeshiftBox' => self::TRADESHIFTBOX(), 'twitch' => self::TWITCH(), 'wordpress' => self::WORDPRESS(), + 'x' => self::X(), 'yahoo' => self::YAHOO(), 'yammer' => self::YAMMER(), 'yandex' => self::YANDEX(), diff --git a/src/Appwrite/Enums/PlatformType.php b/src/Appwrite/Enums/PlatformType.php new file mode 100644 index 00000000..4b1651a8 --- /dev/null +++ b/src/Appwrite/Enums/PlatformType.php @@ -0,0 +1,79 @@ +value = $value; + } + + public function __toString(): string + { + return $this->value; + } + + public function jsonSerialize(): string + { + return $this->value; + } + + public static function WINDOWS(): PlatformType + { + if (!isset(self::$WINDOWS)) { + self::$WINDOWS = new PlatformType('windows'); + } + return self::$WINDOWS; + } + public static function APPLE(): PlatformType + { + if (!isset(self::$APPLE)) { + self::$APPLE = new PlatformType('apple'); + } + return self::$APPLE; + } + public static function ANDROID(): PlatformType + { + if (!isset(self::$ANDROID)) { + self::$ANDROID = new PlatformType('android'); + } + return self::$ANDROID; + } + public static function LINUX(): PlatformType + { + if (!isset(self::$LINUX)) { + self::$LINUX = new PlatformType('linux'); + } + return self::$LINUX; + } + public static function WEB(): PlatformType + { + if (!isset(self::$WEB)) { + self::$WEB = new PlatformType('web'); + } + return self::$WEB; + } + + public static function from(string $value): self + { + return match ($value) { + 'windows' => self::WINDOWS(), + 'apple' => self::APPLE(), + 'android' => self::ANDROID(), + 'linux' => self::LINUX(), + 'web' => self::WEB(), + default => throw new \InvalidArgumentException('Unknown PlatformType value: ' . $value), + }; + } +} diff --git a/src/Appwrite/Enums/ProtocolId.php b/src/Appwrite/Enums/ProtocolId.php new file mode 100644 index 00000000..476aec75 --- /dev/null +++ b/src/Appwrite/Enums/ProtocolId.php @@ -0,0 +1,61 @@ +value = $value; + } + + public function __toString(): string + { + return $this->value; + } + + public function jsonSerialize(): string + { + return $this->value; + } + + public static function REST(): ProtocolId + { + if (!isset(self::$REST)) { + self::$REST = new ProtocolId('rest'); + } + return self::$REST; + } + public static function GRAPHQL(): ProtocolId + { + if (!isset(self::$GRAPHQL)) { + self::$GRAPHQL = new ProtocolId('graphql'); + } + return self::$GRAPHQL; + } + public static function WEBSOCKET(): ProtocolId + { + if (!isset(self::$WEBSOCKET)) { + self::$WEBSOCKET = new ProtocolId('websocket'); + } + return self::$WEBSOCKET; + } + + public static function from(string $value): self + { + return match ($value) { + 'rest' => self::REST(), + 'graphql' => self::GRAPHQL(), + 'websocket' => self::WEBSOCKET(), + default => throw new \InvalidArgumentException('Unknown ProtocolId value: ' . $value), + }; + } +} diff --git a/src/Appwrite/Enums/Scopes.php b/src/Appwrite/Enums/Scopes.php index 5087bf79..95438adb 100644 --- a/src/Appwrite/Enums/Scopes.php +++ b/src/Appwrite/Enums/Scopes.php @@ -67,6 +67,10 @@ class Scopes implements JsonSerializable private static Scopes $WEBHOOKSWRITE; private static Scopes $PROJECTREAD; private static Scopes $PROJECTWRITE; + private static Scopes $KEYSREAD; + private static Scopes $KEYSWRITE; + private static Scopes $PLATFORMSREAD; + private static Scopes $PLATFORMSWRITE; private static Scopes $POLICIESWRITE; private static Scopes $POLICIESREAD; private static Scopes $ARCHIVESREAD; @@ -521,6 +525,34 @@ public static function PROJECTWRITE(): Scopes } return self::$PROJECTWRITE; } + public static function KEYSREAD(): Scopes + { + if (!isset(self::$KEYSREAD)) { + self::$KEYSREAD = new Scopes('keys.read'); + } + return self::$KEYSREAD; + } + public static function KEYSWRITE(): Scopes + { + if (!isset(self::$KEYSWRITE)) { + self::$KEYSWRITE = new Scopes('keys.write'); + } + return self::$KEYSWRITE; + } + public static function PLATFORMSREAD(): Scopes + { + if (!isset(self::$PLATFORMSREAD)) { + self::$PLATFORMSREAD = new Scopes('platforms.read'); + } + return self::$PLATFORMSREAD; + } + public static function PLATFORMSWRITE(): Scopes + { + if (!isset(self::$PLATFORMSWRITE)) { + self::$PLATFORMSWRITE = new Scopes('platforms.write'); + } + return self::$PLATFORMSWRITE; + } public static function POLICIESWRITE(): Scopes { if (!isset(self::$POLICIESWRITE)) { @@ -649,6 +681,10 @@ public static function from(string $value): self 'webhooks.write' => self::WEBHOOKSWRITE(), 'project.read' => self::PROJECTREAD(), 'project.write' => self::PROJECTWRITE(), + 'keys.read' => self::KEYSREAD(), + 'keys.write' => self::KEYSWRITE(), + 'platforms.read' => self::PLATFORMSREAD(), + 'platforms.write' => self::PLATFORMSWRITE(), 'policies.write' => self::POLICIESWRITE(), 'policies.read' => self::POLICIESREAD(), 'archives.read' => self::ARCHIVESREAD(), diff --git a/src/Appwrite/Enums/ServiceId.php b/src/Appwrite/Enums/ServiceId.php new file mode 100644 index 00000000..5bef611f --- /dev/null +++ b/src/Appwrite/Enums/ServiceId.php @@ -0,0 +1,187 @@ +value = $value; + } + + public function __toString(): string + { + return $this->value; + } + + public function jsonSerialize(): string + { + return $this->value; + } + + public static function ACCOUNT(): ServiceId + { + if (!isset(self::$ACCOUNT)) { + self::$ACCOUNT = new ServiceId('account'); + } + return self::$ACCOUNT; + } + public static function AVATARS(): ServiceId + { + if (!isset(self::$AVATARS)) { + self::$AVATARS = new ServiceId('avatars'); + } + return self::$AVATARS; + } + public static function DATABASES(): ServiceId + { + if (!isset(self::$DATABASES)) { + self::$DATABASES = new ServiceId('databases'); + } + return self::$DATABASES; + } + public static function TABLESDB(): ServiceId + { + if (!isset(self::$TABLESDB)) { + self::$TABLESDB = new ServiceId('tablesdb'); + } + return self::$TABLESDB; + } + public static function LOCALE(): ServiceId + { + if (!isset(self::$LOCALE)) { + self::$LOCALE = new ServiceId('locale'); + } + return self::$LOCALE; + } + public static function HEALTH(): ServiceId + { + if (!isset(self::$HEALTH)) { + self::$HEALTH = new ServiceId('health'); + } + return self::$HEALTH; + } + public static function PROJECT(): ServiceId + { + if (!isset(self::$PROJECT)) { + self::$PROJECT = new ServiceId('project'); + } + return self::$PROJECT; + } + public static function STORAGE(): ServiceId + { + if (!isset(self::$STORAGE)) { + self::$STORAGE = new ServiceId('storage'); + } + return self::$STORAGE; + } + public static function TEAMS(): ServiceId + { + if (!isset(self::$TEAMS)) { + self::$TEAMS = new ServiceId('teams'); + } + return self::$TEAMS; + } + public static function USERS(): ServiceId + { + if (!isset(self::$USERS)) { + self::$USERS = new ServiceId('users'); + } + return self::$USERS; + } + public static function VCS(): ServiceId + { + if (!isset(self::$VCS)) { + self::$VCS = new ServiceId('vcs'); + } + return self::$VCS; + } + public static function SITES(): ServiceId + { + if (!isset(self::$SITES)) { + self::$SITES = new ServiceId('sites'); + } + return self::$SITES; + } + public static function FUNCTIONS(): ServiceId + { + if (!isset(self::$FUNCTIONS)) { + self::$FUNCTIONS = new ServiceId('functions'); + } + return self::$FUNCTIONS; + } + public static function PROXY(): ServiceId + { + if (!isset(self::$PROXY)) { + self::$PROXY = new ServiceId('proxy'); + } + return self::$PROXY; + } + public static function GRAPHQL(): ServiceId + { + if (!isset(self::$GRAPHQL)) { + self::$GRAPHQL = new ServiceId('graphql'); + } + return self::$GRAPHQL; + } + public static function MIGRATIONS(): ServiceId + { + if (!isset(self::$MIGRATIONS)) { + self::$MIGRATIONS = new ServiceId('migrations'); + } + return self::$MIGRATIONS; + } + public static function MESSAGING(): ServiceId + { + if (!isset(self::$MESSAGING)) { + self::$MESSAGING = new ServiceId('messaging'); + } + return self::$MESSAGING; + } + + public static function from(string $value): self + { + return match ($value) { + 'account' => self::ACCOUNT(), + 'avatars' => self::AVATARS(), + 'databases' => self::DATABASES(), + 'tablesdb' => self::TABLESDB(), + 'locale' => self::LOCALE(), + 'health' => self::HEALTH(), + 'project' => self::PROJECT(), + 'storage' => self::STORAGE(), + 'teams' => self::TEAMS(), + 'users' => self::USERS(), + 'vcs' => self::VCS(), + 'sites' => self::SITES(), + 'functions' => self::FUNCTIONS(), + 'proxy' => self::PROXY(), + 'graphql' => self::GRAPHQL(), + 'migrations' => self::MIGRATIONS(), + 'messaging' => self::MESSAGING(), + default => throw new \InvalidArgumentException('Unknown ServiceId value: ' . $value), + }; + } +} diff --git a/src/Appwrite/Models/ActivityEvent.php b/src/Appwrite/Models/ActivityEvent.php index 51483d4e..92c16093 100644 --- a/src/Appwrite/Models/ActivityEvent.php +++ b/src/Appwrite/Models/ActivityEvent.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id' - ]; - /** * ActivityEvent constructor. * @@ -87,4 +80,185 @@ public function __construct( public string $countryName ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('userType', $data)) { + throw new \InvalidArgumentException('Missing required field "userType" for ' . static::class . '.'); + } + if (!array_key_exists('userId', $data)) { + throw new \InvalidArgumentException('Missing required field "userId" for ' . static::class . '.'); + } + if (!array_key_exists('userEmail', $data)) { + throw new \InvalidArgumentException('Missing required field "userEmail" for ' . static::class . '.'); + } + if (!array_key_exists('userName', $data)) { + throw new \InvalidArgumentException('Missing required field "userName" for ' . static::class . '.'); + } + if (!array_key_exists('resourceParent', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceParent" for ' . static::class . '.'); + } + if (!array_key_exists('resourceType', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceType" for ' . static::class . '.'); + } + if (!array_key_exists('resourceId', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceId" for ' . static::class . '.'); + } + if (!array_key_exists('resource', $data)) { + throw new \InvalidArgumentException('Missing required field "resource" for ' . static::class . '.'); + } + if (!array_key_exists('event', $data)) { + throw new \InvalidArgumentException('Missing required field "event" for ' . static::class . '.'); + } + if (!array_key_exists('userAgent', $data)) { + throw new \InvalidArgumentException('Missing required field "userAgent" for ' . static::class . '.'); + } + if (!array_key_exists('ip', $data)) { + throw new \InvalidArgumentException('Missing required field "ip" for ' . static::class . '.'); + } + if (!array_key_exists('mode', $data)) { + throw new \InvalidArgumentException('Missing required field "mode" for ' . static::class . '.'); + } + if (!array_key_exists('country', $data)) { + throw new \InvalidArgumentException('Missing required field "country" for ' . static::class . '.'); + } + if (!array_key_exists('time', $data)) { + throw new \InvalidArgumentException('Missing required field "time" for ' . static::class . '.'); + } + if (!array_key_exists('projectId', $data)) { + throw new \InvalidArgumentException('Missing required field "projectId" for ' . static::class . '.'); + } + if (!array_key_exists('teamId', $data)) { + throw new \InvalidArgumentException('Missing required field "teamId" for ' . static::class . '.'); + } + if (!array_key_exists('hostname', $data)) { + throw new \InvalidArgumentException('Missing required field "hostname" for ' . static::class . '.'); + } + if (!array_key_exists('osCode', $data)) { + throw new \InvalidArgumentException('Missing required field "osCode" for ' . static::class . '.'); + } + if (!array_key_exists('osName', $data)) { + throw new \InvalidArgumentException('Missing required field "osName" for ' . static::class . '.'); + } + if (!array_key_exists('osVersion', $data)) { + throw new \InvalidArgumentException('Missing required field "osVersion" for ' . static::class . '.'); + } + if (!array_key_exists('clientType', $data)) { + throw new \InvalidArgumentException('Missing required field "clientType" for ' . static::class . '.'); + } + if (!array_key_exists('clientCode', $data)) { + throw new \InvalidArgumentException('Missing required field "clientCode" for ' . static::class . '.'); + } + if (!array_key_exists('clientName', $data)) { + throw new \InvalidArgumentException('Missing required field "clientName" for ' . static::class . '.'); + } + if (!array_key_exists('clientVersion', $data)) { + throw new \InvalidArgumentException('Missing required field "clientVersion" for ' . static::class . '.'); + } + if (!array_key_exists('clientEngine', $data)) { + throw new \InvalidArgumentException('Missing required field "clientEngine" for ' . static::class . '.'); + } + if (!array_key_exists('clientEngineVersion', $data)) { + throw new \InvalidArgumentException('Missing required field "clientEngineVersion" for ' . static::class . '.'); + } + if (!array_key_exists('deviceName', $data)) { + throw new \InvalidArgumentException('Missing required field "deviceName" for ' . static::class . '.'); + } + if (!array_key_exists('deviceBrand', $data)) { + throw new \InvalidArgumentException('Missing required field "deviceBrand" for ' . static::class . '.'); + } + if (!array_key_exists('deviceModel', $data)) { + throw new \InvalidArgumentException('Missing required field "deviceModel" for ' . static::class . '.'); + } + if (!array_key_exists('countryCode', $data)) { + throw new \InvalidArgumentException('Missing required field "countryCode" for ' . static::class . '.'); + } + if (!array_key_exists('countryName', $data)) { + throw new \InvalidArgumentException('Missing required field "countryName" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + userType: $data['userType'], + userId: $data['userId'], + userEmail: $data['userEmail'], + userName: $data['userName'], + resourceParent: $data['resourceParent'], + resourceType: $data['resourceType'], + resourceId: $data['resourceId'], + resource: $data['resource'], + event: $data['event'], + userAgent: $data['userAgent'], + ip: $data['ip'], + mode: $data['mode'], + country: $data['country'], + time: $data['time'], + projectId: $data['projectId'], + teamId: $data['teamId'], + hostname: $data['hostname'], + osCode: $data['osCode'], + osName: $data['osName'], + osVersion: $data['osVersion'], + clientType: $data['clientType'], + clientCode: $data['clientCode'], + clientName: $data['clientName'], + clientVersion: $data['clientVersion'], + clientEngine: $data['clientEngine'], + clientEngineVersion: $data['clientEngineVersion'], + deviceName: $data['deviceName'], + deviceBrand: $data['deviceBrand'], + deviceModel: $data['deviceModel'], + countryCode: $data['countryCode'], + countryName: $data['countryName'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + 'userType' => static::serializeValue($this->userType), + 'userId' => static::serializeValue($this->userId), + 'userEmail' => static::serializeValue($this->userEmail), + 'userName' => static::serializeValue($this->userName), + 'resourceParent' => static::serializeValue($this->resourceParent), + 'resourceType' => static::serializeValue($this->resourceType), + 'resourceId' => static::serializeValue($this->resourceId), + 'resource' => static::serializeValue($this->resource), + 'event' => static::serializeValue($this->event), + 'userAgent' => static::serializeValue($this->userAgent), + 'ip' => static::serializeValue($this->ip), + 'mode' => static::serializeValue($this->mode), + 'country' => static::serializeValue($this->country), + 'time' => static::serializeValue($this->time), + 'projectId' => static::serializeValue($this->projectId), + 'teamId' => static::serializeValue($this->teamId), + 'hostname' => static::serializeValue($this->hostname), + 'osCode' => static::serializeValue($this->osCode), + 'osName' => static::serializeValue($this->osName), + 'osVersion' => static::serializeValue($this->osVersion), + 'clientType' => static::serializeValue($this->clientType), + 'clientCode' => static::serializeValue($this->clientCode), + 'clientName' => static::serializeValue($this->clientName), + 'clientVersion' => static::serializeValue($this->clientVersion), + 'clientEngine' => static::serializeValue($this->clientEngine), + 'clientEngineVersion' => static::serializeValue($this->clientEngineVersion), + 'deviceName' => static::serializeValue($this->deviceName), + 'deviceBrand' => static::serializeValue($this->deviceBrand), + 'deviceModel' => static::serializeValue($this->deviceModel), + 'countryCode' => static::serializeValue($this->countryCode), + 'countryName' => static::serializeValue($this->countryName) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ActivityEventList.php b/src/Appwrite/Models/ActivityEventList.php index 8987e2f5..7039b9c6 100644 --- a/src/Appwrite/Models/ActivityEventList.php +++ b/src/Appwrite/Models/ActivityEventList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'events' => ActivityEvent::class - ]; - /** * ActivityEventList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $events ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('events', $data)) { + throw new \InvalidArgumentException('Missing required field "events" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + events: is_array($data['events']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(ActivityEvent::class, $item), + $data['events'] + ) + : $data['events'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'events' => static::serializeValue($this->events) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AlgoArgon2.php b/src/Appwrite/Models/AlgoArgon2.php index 1196f639..aa6de2ee 100644 --- a/src/Appwrite/Models/AlgoArgon2.php +++ b/src/Appwrite/Models/AlgoArgon2.php @@ -24,4 +24,45 @@ public function __construct( public int $threads ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('memoryCost', $data)) { + throw new \InvalidArgumentException('Missing required field "memoryCost" for ' . static::class . '.'); + } + if (!array_key_exists('timeCost', $data)) { + throw new \InvalidArgumentException('Missing required field "timeCost" for ' . static::class . '.'); + } + if (!array_key_exists('threads', $data)) { + throw new \InvalidArgumentException('Missing required field "threads" for ' . static::class . '.'); + } + + return new static( + type: $data['type'], + memoryCost: $data['memoryCost'], + timeCost: $data['timeCost'], + threads: $data['threads'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'type' => static::serializeValue($this->type), + 'memoryCost' => static::serializeValue($this->memoryCost), + 'timeCost' => static::serializeValue($this->timeCost), + 'threads' => static::serializeValue($this->threads) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AlgoBcrypt.php b/src/Appwrite/Models/AlgoBcrypt.php index 6b4639f7..a2a1a945 100644 --- a/src/Appwrite/Models/AlgoBcrypt.php +++ b/src/Appwrite/Models/AlgoBcrypt.php @@ -18,4 +18,30 @@ public function __construct( public string $type ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + + return new static( + type: $data['type'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'type' => static::serializeValue($this->type) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AlgoMd5.php b/src/Appwrite/Models/AlgoMd5.php index 16993137..06a1f851 100644 --- a/src/Appwrite/Models/AlgoMd5.php +++ b/src/Appwrite/Models/AlgoMd5.php @@ -18,4 +18,30 @@ public function __construct( public string $type ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + + return new static( + type: $data['type'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'type' => static::serializeValue($this->type) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AlgoPhpass.php b/src/Appwrite/Models/AlgoPhpass.php index 1d0e3376..353f8809 100644 --- a/src/Appwrite/Models/AlgoPhpass.php +++ b/src/Appwrite/Models/AlgoPhpass.php @@ -18,4 +18,30 @@ public function __construct( public string $type ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + + return new static( + type: $data['type'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'type' => static::serializeValue($this->type) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AlgoScrypt.php b/src/Appwrite/Models/AlgoScrypt.php index e185d1bb..e602f313 100644 --- a/src/Appwrite/Models/AlgoScrypt.php +++ b/src/Appwrite/Models/AlgoScrypt.php @@ -26,4 +26,50 @@ public function __construct( public int $length ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('costCpu', $data)) { + throw new \InvalidArgumentException('Missing required field "costCpu" for ' . static::class . '.'); + } + if (!array_key_exists('costMemory', $data)) { + throw new \InvalidArgumentException('Missing required field "costMemory" for ' . static::class . '.'); + } + if (!array_key_exists('costParallel', $data)) { + throw new \InvalidArgumentException('Missing required field "costParallel" for ' . static::class . '.'); + } + if (!array_key_exists('length', $data)) { + throw new \InvalidArgumentException('Missing required field "length" for ' . static::class . '.'); + } + + return new static( + type: $data['type'], + costCpu: $data['costCpu'], + costMemory: $data['costMemory'], + costParallel: $data['costParallel'], + length: $data['length'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'type' => static::serializeValue($this->type), + 'costCpu' => static::serializeValue($this->costCpu), + 'costMemory' => static::serializeValue($this->costMemory), + 'costParallel' => static::serializeValue($this->costParallel), + 'length' => static::serializeValue($this->length) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AlgoScryptModified.php b/src/Appwrite/Models/AlgoScryptModified.php index 03702fc1..c8018a36 100644 --- a/src/Appwrite/Models/AlgoScryptModified.php +++ b/src/Appwrite/Models/AlgoScryptModified.php @@ -24,4 +24,45 @@ public function __construct( public string $signerKey ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('salt', $data)) { + throw new \InvalidArgumentException('Missing required field "salt" for ' . static::class . '.'); + } + if (!array_key_exists('saltSeparator', $data)) { + throw new \InvalidArgumentException('Missing required field "saltSeparator" for ' . static::class . '.'); + } + if (!array_key_exists('signerKey', $data)) { + throw new \InvalidArgumentException('Missing required field "signerKey" for ' . static::class . '.'); + } + + return new static( + type: $data['type'], + salt: $data['salt'], + saltSeparator: $data['saltSeparator'], + signerKey: $data['signerKey'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'type' => static::serializeValue($this->type), + 'salt' => static::serializeValue($this->salt), + 'saltSeparator' => static::serializeValue($this->saltSeparator), + 'signerKey' => static::serializeValue($this->signerKey) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AlgoSha.php b/src/Appwrite/Models/AlgoSha.php index 94c70b8a..4da8de8c 100644 --- a/src/Appwrite/Models/AlgoSha.php +++ b/src/Appwrite/Models/AlgoSha.php @@ -18,4 +18,30 @@ public function __construct( public string $type ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + + return new static( + type: $data['type'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'type' => static::serializeValue($this->type) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ArraySerializable.php b/src/Appwrite/Models/ArraySerializable.php index 2fe332f3..b387f3cf 100644 --- a/src/Appwrite/Models/ArraySerializable.php +++ b/src/Appwrite/Models/ArraySerializable.php @@ -6,135 +6,15 @@ trait ArraySerializable { /** * @param array $data - */ - public static function from(array $data): static - { - $parameters = static::getConstructorParameters(); - - if ($parameters === []) { - return new static(); - } - - $arguments = []; - $additionalProperties = static::hasAdditionalProperties() - ? static::extractAdditionalProperties($data, $parameters) - : []; - - foreach ($parameters as $parameter) { - $name = $parameter->getName(); - - if ($name === 'data' && static::hasAdditionalProperties()) { - $arguments[$name] = $additionalProperties; - continue; - } - - $field = static::getFieldMap()[$name] ?? $name; - - if (!array_key_exists($field, $data)) { - if ($parameter->isDefaultValueAvailable()) { - $arguments[$name] = $parameter->getDefaultValue(); - continue; - } - - throw new \InvalidArgumentException('Missing required field "' . $field . '" for ' . static::class . '.'); - } - - $arguments[$name] = static::hydrateValue($name, $data[$field], $parameter); - } - - return new static(...$arguments); - } - - /** - * @return array - */ - public function toArray(): array - { - $result = []; - - foreach (get_object_vars($this) as $name => $value) { - if ($name === 'data' && static::hasAdditionalProperties()) { - foreach (static::serializeAdditionalProperties($value) as $field => $fieldValue) { - $result[$field] = $fieldValue; - } - - continue; - } - - $field = static::getFieldMap()[$name] ?? $name; - $result[$field] = static::serializeValue($value); - } - - return $result; - } - - /** - * @return array - */ - private static function getFieldMap(): array - { - return defined(static::class . '::FIELD_MAP') ? static::FIELD_MAP : []; - } - - /** - * @return array - */ - private static function getArrayTypes(): array - { - return defined(static::class . '::ARRAY_TYPES') ? static::ARRAY_TYPES : []; - } - - private static function hasAdditionalProperties(): bool - { - return defined(static::class . '::ADDITIONAL_PROPERTIES') && static::ADDITIONAL_PROPERTIES; - } - - /** - * @return array - */ - private static function getConstructorParameters(): array - { - /** @var array> $cache */ - static $cache = []; - - if (isset($cache[static::class])) { - return $cache[static::class]; - } - - $reflection = new \ReflectionClass(static::class); - $constructor = $reflection->getConstructor(); - - if ($constructor === null) { - $cache[static::class] = []; - return []; - } - - return $cache[static::class] = $constructor->getParameters(); - } - - /** - * @param array $data - * @param array $parameters + * @param array $knownFields * @return array */ - private static function extractAdditionalProperties(array $data, array $parameters): array + private static function extractAdditionalPropertiesFromFields(array $data, array $knownFields): array { - if (isset($data['data']) && is_array($data['data'])) { + if (!\in_array('data', $knownFields, true) && isset($data['data']) && is_array($data['data'])) { return $data['data']; } - $knownFields = []; - - foreach ($parameters as $parameter) { - $name = $parameter->getName(); - - if ($name === 'data') { - continue; - } - - $knownFields[] = static::getFieldMap()[$name] ?? $name; - } - return array_diff_key($data, array_flip($knownFields)); } @@ -156,56 +36,16 @@ private static function serializeAdditionalProperties(mixed $value): array return $result; } - private static function hydrateValue(string $name, mixed $value, \ReflectionParameter $parameter): mixed - { - if ($value === null) { - return null; - } - - $type = $parameter->getType(); - - if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) { - $typeName = $type->getName(); - - if (!method_exists($typeName, 'from')) { - return $value; - } - - return is_array($value) ? $typeName::from($value) : $typeName::from((string) $value); - } - - if ($type instanceof \ReflectionNamedType && $type->getName() === 'array' && is_array($value)) { - $arrayType = static::getArrayTypes()[$name] ?? null; - - if ($arrayType === null) { - foreach ($value as $item) { - if (is_array($item) || is_object($item)) { - @trigger_error( - 'Array property "' . $name . '" on ' . static::class . ' contains structured values but has no ARRAY_TYPES mapping. Values will remain unhydrated.', - E_USER_WARNING - ); - break; - } - } - - return $value; - } - - return array_map( - static fn (mixed $item): mixed => static::hydrateArrayItem($arrayType, $item), - $value - ); - } - - return $value; - } - - private static function hydrateArrayItem(string $type, mixed $value): mixed + private static function hydrateTypedValue(string $type, mixed $value, bool $allowsNull = false): mixed { if ($value === null || !method_exists($type, 'from')) { return $value; } + if ($allowsNull && $value === '') { + return null; + } + return is_array($value) ? $type::from($value) : $type::from((string) $value); } diff --git a/src/Appwrite/Models/AttributeBoolean.php b/src/Appwrite/Models/AttributeBoolean.php index 56e55e4d..a1ff7ce4 100644 --- a/src/Appwrite/Models/AttributeBoolean.php +++ b/src/Appwrite/Models/AttributeBoolean.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeBoolean constructor. * @@ -31,8 +21,8 @@ * @param bool $required is attribute required? * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. - * @param bool|null $xarray is attribute an array? - * @param bool|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param bool|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -42,8 +32,68 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?bool $xdefault = null + public ?bool $array = null, + public ?bool $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeDatetime.php b/src/Appwrite/Models/AttributeDatetime.php index 0f961431..ad7f5405 100644 --- a/src/Appwrite/Models/AttributeDatetime.php +++ b/src/Appwrite/Models/AttributeDatetime.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeDatetime constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. * @param string $format iso 8601 format. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. only null is optional + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. only null is optional */ public function __construct( public string $key, @@ -44,8 +34,73 @@ public function __construct( public string $createdAt, public string $updatedAt, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeEmail.php b/src/Appwrite/Models/AttributeEmail.php index a5163cb2..c1da0b1b 100644 --- a/src/Appwrite/Models/AttributeEmail.php +++ b/src/Appwrite/Models/AttributeEmail.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeEmail constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. * @param string $format string format. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -44,8 +34,73 @@ public function __construct( public string $createdAt, public string $updatedAt, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeEnum.php b/src/Appwrite/Models/AttributeEnum.php index ad7dcdb1..c6730f3b 100644 --- a/src/Appwrite/Models/AttributeEnum.php +++ b/src/Appwrite/Models/AttributeEnum.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeEnum constructor. * @@ -33,8 +23,8 @@ * @param string $updatedAt attribute update date in iso 8601 format. * @param array $elements array of elements in enumerated type. * @param string $format string format. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -46,8 +36,78 @@ public function __construct( public string $updatedAt, public array $elements, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('elements', $data)) { + throw new \InvalidArgumentException('Missing required field "elements" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + elements: $data['elements'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'elements' => static::serializeValue($this->elements), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeFloat.php b/src/Appwrite/Models/AttributeFloat.php index 6ac1a6f1..b319ed00 100644 --- a/src/Appwrite/Models/AttributeFloat.php +++ b/src/Appwrite/Models/AttributeFloat.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeFloat constructor. * @@ -31,10 +21,10 @@ * @param bool $required is attribute required? * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. - * @param bool|null $xarray is attribute an array? + * @param bool|null $array is attribute an array? * @param float|null $min minimum value to enforce for new documents. * @param float|null $max maximum value to enforce for new documents. - * @param float|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param float|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -44,10 +34,74 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, + public ?bool $array = null, public ?float $min = null, public ?float $max = null, - public ?float $xdefault = null + public ?float $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + min: array_key_exists('min', $data) ? $data['min'] : null, + max: array_key_exists('max', $data) ? $data['max'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'min' => static::serializeValue($this->min), + 'max' => static::serializeValue($this->max), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeInteger.php b/src/Appwrite/Models/AttributeInteger.php index a5b02dcf..540a18bb 100644 --- a/src/Appwrite/Models/AttributeInteger.php +++ b/src/Appwrite/Models/AttributeInteger.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeInteger constructor. * @@ -31,10 +21,10 @@ * @param bool $required is attribute required? * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. - * @param bool|null $xarray is attribute an array? + * @param bool|null $array is attribute an array? * @param int|null $min minimum value to enforce for new documents. * @param int|null $max maximum value to enforce for new documents. - * @param int|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param int|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -44,10 +34,74 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, + public ?bool $array = null, public ?int $min = null, public ?int $max = null, - public ?int $xdefault = null + public ?int $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + min: array_key_exists('min', $data) ? $data['min'] : null, + max: array_key_exists('max', $data) ? $data['max'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'min' => static::serializeValue($this->min), + 'max' => static::serializeValue($this->max), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeIp.php b/src/Appwrite/Models/AttributeIp.php index 53e4395d..13b19d06 100644 --- a/src/Appwrite/Models/AttributeIp.php +++ b/src/Appwrite/Models/AttributeIp.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeIp constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. * @param string $format string format. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -44,8 +34,73 @@ public function __construct( public string $createdAt, public string $updatedAt, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeLine.php b/src/Appwrite/Models/AttributeLine.php index fe2fd2d4..6867fc6c 100644 --- a/src/Appwrite/Models/AttributeLine.php +++ b/src/Appwrite/Models/AttributeLine.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeLine constructor. * @@ -31,8 +21,8 @@ * @param bool $required is attribute required? * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. - * @param bool|null $xarray is attribute an array? - * @param array|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param array|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -42,8 +32,68 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?array $xdefault = null + public ?bool $array = null, + public ?array $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeList.php b/src/Appwrite/Models/AttributeList.php index 31808ef8..bb3ee377 100644 --- a/src/Appwrite/Models/AttributeList.php +++ b/src/Appwrite/Models/AttributeList.php @@ -20,4 +20,35 @@ public function __construct( public array $attributes ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('attributes', $data)) { + throw new \InvalidArgumentException('Missing required field "attributes" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + attributes: $data['attributes'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'attributes' => static::serializeValue($this->attributes) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeLongtext.php b/src/Appwrite/Models/AttributeLongtext.php index 4324030f..6232eecd 100644 --- a/src/Appwrite/Models/AttributeLongtext.php +++ b/src/Appwrite/Models/AttributeLongtext.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeLongtext constructor. * @@ -31,8 +21,8 @@ * @param bool $required is attribute required? * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. cannot be set when attribute is required. * @param bool|null $encrypt defines whether this attribute is encrypted or not. */ public function __construct( @@ -43,9 +33,71 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeMediumtext.php b/src/Appwrite/Models/AttributeMediumtext.php index c671a767..10aee46c 100644 --- a/src/Appwrite/Models/AttributeMediumtext.php +++ b/src/Appwrite/Models/AttributeMediumtext.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeMediumtext constructor. * @@ -31,8 +21,8 @@ * @param bool $required is attribute required? * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. cannot be set when attribute is required. * @param bool|null $encrypt defines whether this attribute is encrypted or not. */ public function __construct( @@ -43,9 +33,71 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributePoint.php b/src/Appwrite/Models/AttributePoint.php index 11245736..55bfb48a 100644 --- a/src/Appwrite/Models/AttributePoint.php +++ b/src/Appwrite/Models/AttributePoint.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributePoint constructor. * @@ -31,8 +21,8 @@ * @param bool $required is attribute required? * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. - * @param bool|null $xarray is attribute an array? - * @param array|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param array|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -42,8 +32,68 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?array $xdefault = null + public ?bool $array = null, + public ?array $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributePolygon.php b/src/Appwrite/Models/AttributePolygon.php index 88c3fb02..50e512f0 100644 --- a/src/Appwrite/Models/AttributePolygon.php +++ b/src/Appwrite/Models/AttributePolygon.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributePolygon constructor. * @@ -31,8 +21,8 @@ * @param bool $required is attribute required? * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. - * @param bool|null $xarray is attribute an array? - * @param array|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param array|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -42,8 +32,68 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?array $xdefault = null + public ?bool $array = null, + public ?array $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeRelationship.php b/src/Appwrite/Models/AttributeRelationship.php index b57e248c..571a692e 100644 --- a/src/Appwrite/Models/AttributeRelationship.php +++ b/src/Appwrite/Models/AttributeRelationship.php @@ -11,15 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * AttributeRelationship constructor. * @@ -36,7 +27,7 @@ * @param string $twoWayKey the key of the two-way relationship. * @param string $onDelete how deleting the parent document will propagate to child documents. * @param string $side whether this is the parent or child side of the relationship - * @param bool|null $xarray is attribute an array? + * @param bool|null $array is attribute an array? */ public function __construct( public string $key, @@ -52,7 +43,95 @@ public function __construct( public string $twoWayKey, public string $onDelete, public string $side, - public ?bool $xarray = null + public ?bool $array = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('relatedCollection', $data)) { + throw new \InvalidArgumentException('Missing required field "relatedCollection" for ' . static::class . '.'); + } + if (!array_key_exists('relationType', $data)) { + throw new \InvalidArgumentException('Missing required field "relationType" for ' . static::class . '.'); + } + if (!array_key_exists('twoWay', $data)) { + throw new \InvalidArgumentException('Missing required field "twoWay" for ' . static::class . '.'); + } + if (!array_key_exists('twoWayKey', $data)) { + throw new \InvalidArgumentException('Missing required field "twoWayKey" for ' . static::class . '.'); + } + if (!array_key_exists('onDelete', $data)) { + throw new \InvalidArgumentException('Missing required field "onDelete" for ' . static::class . '.'); + } + if (!array_key_exists('side', $data)) { + throw new \InvalidArgumentException('Missing required field "side" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + relatedCollection: $data['relatedCollection'], + relationType: $data['relationType'], + twoWay: $data['twoWay'], + twoWayKey: $data['twoWayKey'], + onDelete: $data['onDelete'], + side: $data['side'], + array: array_key_exists('array', $data) ? $data['array'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'relatedCollection' => static::serializeValue($this->relatedCollection), + 'relationType' => static::serializeValue($this->relationType), + 'twoWay' => static::serializeValue($this->twoWay), + 'twoWayKey' => static::serializeValue($this->twoWayKey), + 'onDelete' => static::serializeValue($this->onDelete), + 'side' => static::serializeValue($this->side) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeString.php b/src/Appwrite/Models/AttributeString.php index 366855b4..306bdeaf 100644 --- a/src/Appwrite/Models/AttributeString.php +++ b/src/Appwrite/Models/AttributeString.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeString constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. * @param int $size attribute size. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. cannot be set when attribute is required. * @param bool|null $encrypt defines whether this attribute is encrypted or not. */ public function __construct( @@ -45,9 +35,76 @@ public function __construct( public string $createdAt, public string $updatedAt, public int $size, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('size', $data)) { + throw new \InvalidArgumentException('Missing required field "size" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + size: $data['size'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'size' => static::serializeValue($this->size), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeText.php b/src/Appwrite/Models/AttributeText.php index 9ba2a243..3a0556ee 100644 --- a/src/Appwrite/Models/AttributeText.php +++ b/src/Appwrite/Models/AttributeText.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeText constructor. * @@ -31,8 +21,8 @@ * @param bool $required is attribute required? * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. cannot be set when attribute is required. * @param bool|null $encrypt defines whether this attribute is encrypted or not. */ public function __construct( @@ -43,9 +33,71 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeUrl.php b/src/Appwrite/Models/AttributeUrl.php index 5dcb9fb2..d33d3b2a 100644 --- a/src/Appwrite/Models/AttributeUrl.php +++ b/src/Appwrite/Models/AttributeUrl.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeUrl constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. * @param string $format string format. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. cannot be set when attribute is required. */ public function __construct( public string $key, @@ -44,8 +34,73 @@ public function __construct( public string $createdAt, public string $updatedAt, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AttributeVarchar.php b/src/Appwrite/Models/AttributeVarchar.php index b3d0ca9d..ad4c9857 100644 --- a/src/Appwrite/Models/AttributeVarchar.php +++ b/src/Appwrite/Models/AttributeVarchar.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * AttributeVarchar constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt attribute creation date in iso 8601 format. * @param string $updatedAt attribute update date in iso 8601 format. * @param int $size attribute size. - * @param bool|null $xarray is attribute an array? - * @param string|null $xdefault default value for attribute when not provided. cannot be set when attribute is required. + * @param bool|null $array is attribute an array? + * @param string|null $default default value for attribute when not provided. cannot be set when attribute is required. * @param bool|null $encrypt defines whether this attribute is encrypted or not. */ public function __construct( @@ -45,9 +35,76 @@ public function __construct( public string $createdAt, public string $updatedAt, public int $size, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('size', $data)) { + throw new \InvalidArgumentException('Missing required field "size" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(AttributeStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + size: $data['size'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'size' => static::serializeValue($this->size), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/AuthProvider.php b/src/Appwrite/Models/AuthProvider.php new file mode 100644 index 00000000..efe6208b --- /dev/null +++ b/src/Appwrite/Models/AuthProvider.php @@ -0,0 +1,75 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('appId', $data)) { + throw new \InvalidArgumentException('Missing required field "appId" for ' . static::class . '.'); + } + if (!array_key_exists('secret', $data)) { + throw new \InvalidArgumentException('Missing required field "secret" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + name: $data['name'], + appId: $data['appId'], + secret: $data['secret'], + enabled: $data['enabled'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'name' => static::serializeValue($this->name), + 'appId' => static::serializeValue($this->appId), + 'secret' => static::serializeValue($this->secret), + 'enabled' => static::serializeValue($this->enabled) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/BackupArchive.php b/src/Appwrite/Models/BackupArchive.php index 418cb8e6..47a2b3ce 100644 --- a/src/Appwrite/Models/BackupArchive.php +++ b/src/Appwrite/Models/BackupArchive.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * BackupArchive constructor. * @@ -49,4 +40,79 @@ public function __construct( public ?string $resourceType = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('policyId', $data)) { + throw new \InvalidArgumentException('Missing required field "policyId" for ' . static::class . '.'); + } + if (!array_key_exists('size', $data)) { + throw new \InvalidArgumentException('Missing required field "size" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('startedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "startedAt" for ' . static::class . '.'); + } + if (!array_key_exists('migrationId', $data)) { + throw new \InvalidArgumentException('Missing required field "migrationId" for ' . static::class . '.'); + } + if (!array_key_exists('services', $data)) { + throw new \InvalidArgumentException('Missing required field "services" for ' . static::class . '.'); + } + if (!array_key_exists('resources', $data)) { + throw new \InvalidArgumentException('Missing required field "resources" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + policyId: $data['policyId'], + size: $data['size'], + status: $data['status'], + startedAt: $data['startedAt'], + migrationId: $data['migrationId'], + services: $data['services'], + resources: $data['resources'], + resourceId: array_key_exists('resourceId', $data) ? $data['resourceId'] : null, + resourceType: array_key_exists('resourceType', $data) ? $data['resourceType'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'policyId' => static::serializeValue($this->policyId), + 'size' => static::serializeValue($this->size), + 'status' => static::serializeValue($this->status), + 'startedAt' => static::serializeValue($this->startedAt), + 'migrationId' => static::serializeValue($this->migrationId), + 'services' => static::serializeValue($this->services), + 'resources' => static::serializeValue($this->resources), + 'resourceId' => static::serializeValue($this->resourceId), + 'resourceType' => static::serializeValue($this->resourceType) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/BackupArchiveList.php b/src/Appwrite/Models/BackupArchiveList.php index c9f7ef3a..7426257e 100644 --- a/src/Appwrite/Models/BackupArchiveList.php +++ b/src/Appwrite/Models/BackupArchiveList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'archives' => BackupArchive::class - ]; - /** * BackupArchiveList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $archives ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('archives', $data)) { + throw new \InvalidArgumentException('Missing required field "archives" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + archives: is_array($data['archives']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(BackupArchive::class, $item), + $data['archives'] + ) + : $data['archives'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'archives' => static::serializeValue($this->archives) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/BackupPolicy.php b/src/Appwrite/Models/BackupPolicy.php index bc0ea783..08a4b2ab 100644 --- a/src/Appwrite/Models/BackupPolicy.php +++ b/src/Appwrite/Models/BackupPolicy.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * BackupPolicy constructor. * @@ -47,4 +38,74 @@ public function __construct( public ?string $resourceType = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('services', $data)) { + throw new \InvalidArgumentException('Missing required field "services" for ' . static::class . '.'); + } + if (!array_key_exists('resources', $data)) { + throw new \InvalidArgumentException('Missing required field "resources" for ' . static::class . '.'); + } + if (!array_key_exists('retention', $data)) { + throw new \InvalidArgumentException('Missing required field "retention" for ' . static::class . '.'); + } + if (!array_key_exists('schedule', $data)) { + throw new \InvalidArgumentException('Missing required field "schedule" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + name: $data['name'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + services: $data['services'], + resources: $data['resources'], + retention: $data['retention'], + schedule: $data['schedule'], + enabled: $data['enabled'], + resourceId: array_key_exists('resourceId', $data) ? $data['resourceId'] : null, + resourceType: array_key_exists('resourceType', $data) ? $data['resourceType'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + 'name' => static::serializeValue($this->name), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'services' => static::serializeValue($this->services), + 'resources' => static::serializeValue($this->resources), + 'resourceId' => static::serializeValue($this->resourceId), + 'resourceType' => static::serializeValue($this->resourceType), + 'retention' => static::serializeValue($this->retention), + 'schedule' => static::serializeValue($this->schedule), + 'enabled' => static::serializeValue($this->enabled) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/BackupPolicyList.php b/src/Appwrite/Models/BackupPolicyList.php index a8c23f6f..3189b4e2 100644 --- a/src/Appwrite/Models/BackupPolicyList.php +++ b/src/Appwrite/Models/BackupPolicyList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'policies' => BackupPolicy::class - ]; - /** * BackupPolicyList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $policies ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('policies', $data)) { + throw new \InvalidArgumentException('Missing required field "policies" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + policies: is_array($data['policies']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(BackupPolicy::class, $item), + $data['policies'] + ) + : $data['policies'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'policies' => static::serializeValue($this->policies) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/BackupRestoration.php b/src/Appwrite/Models/BackupRestoration.php index 3b0fd41a..c6d4e5be 100644 --- a/src/Appwrite/Models/BackupRestoration.php +++ b/src/Appwrite/Models/BackupRestoration.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * BackupRestoration constructor. * @@ -47,4 +38,80 @@ public function __construct( public string $options ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('archiveId', $data)) { + throw new \InvalidArgumentException('Missing required field "archiveId" for ' . static::class . '.'); + } + if (!array_key_exists('policyId', $data)) { + throw new \InvalidArgumentException('Missing required field "policyId" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('startedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "startedAt" for ' . static::class . '.'); + } + if (!array_key_exists('migrationId', $data)) { + throw new \InvalidArgumentException('Missing required field "migrationId" for ' . static::class . '.'); + } + if (!array_key_exists('services', $data)) { + throw new \InvalidArgumentException('Missing required field "services" for ' . static::class . '.'); + } + if (!array_key_exists('resources', $data)) { + throw new \InvalidArgumentException('Missing required field "resources" for ' . static::class . '.'); + } + if (!array_key_exists('options', $data)) { + throw new \InvalidArgumentException('Missing required field "options" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + archiveId: $data['archiveId'], + policyId: $data['policyId'], + status: $data['status'], + startedAt: $data['startedAt'], + migrationId: $data['migrationId'], + services: $data['services'], + resources: $data['resources'], + options: $data['options'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'archiveId' => static::serializeValue($this->archiveId), + 'policyId' => static::serializeValue($this->policyId), + 'status' => static::serializeValue($this->status), + 'startedAt' => static::serializeValue($this->startedAt), + 'migrationId' => static::serializeValue($this->migrationId), + 'services' => static::serializeValue($this->services), + 'resources' => static::serializeValue($this->resources), + 'options' => static::serializeValue($this->options) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/BackupRestorationList.php b/src/Appwrite/Models/BackupRestorationList.php index c68ca750..32537e79 100644 --- a/src/Appwrite/Models/BackupRestorationList.php +++ b/src/Appwrite/Models/BackupRestorationList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'restorations' => BackupRestoration::class - ]; - /** * BackupRestorationList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $restorations ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('restorations', $data)) { + throw new \InvalidArgumentException('Missing required field "restorations" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + restorations: is_array($data['restorations']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(BackupRestoration::class, $item), + $data['restorations'] + ) + : $data['restorations'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'restorations' => static::serializeValue($this->restorations) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/BillingLimits.php b/src/Appwrite/Models/BillingLimits.php new file mode 100644 index 00000000..8f95f73e --- /dev/null +++ b/src/Appwrite/Models/BillingLimits.php @@ -0,0 +1,96 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('bandwidth', $data)) { + throw new \InvalidArgumentException('Missing required field "bandwidth" for ' . static::class . '.'); + } + if (!array_key_exists('storage', $data)) { + throw new \InvalidArgumentException('Missing required field "storage" for ' . static::class . '.'); + } + if (!array_key_exists('users', $data)) { + throw new \InvalidArgumentException('Missing required field "users" for ' . static::class . '.'); + } + if (!array_key_exists('executions', $data)) { + throw new \InvalidArgumentException('Missing required field "executions" for ' . static::class . '.'); + } + if (!array_key_exists('GBHours', $data)) { + throw new \InvalidArgumentException('Missing required field "GBHours" for ' . static::class . '.'); + } + if (!array_key_exists('imageTransformations', $data)) { + throw new \InvalidArgumentException('Missing required field "imageTransformations" for ' . static::class . '.'); + } + if (!array_key_exists('authPhone', $data)) { + throw new \InvalidArgumentException('Missing required field "authPhone" for ' . static::class . '.'); + } + if (!array_key_exists('budgetLimit', $data)) { + throw new \InvalidArgumentException('Missing required field "budgetLimit" for ' . static::class . '.'); + } + + return new static( + bandwidth: $data['bandwidth'], + storage: $data['storage'], + users: $data['users'], + executions: $data['executions'], + gBHours: $data['GBHours'], + imageTransformations: $data['imageTransformations'], + authPhone: $data['authPhone'], + budgetLimit: $data['budgetLimit'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'bandwidth' => static::serializeValue($this->bandwidth), + 'storage' => static::serializeValue($this->storage), + 'users' => static::serializeValue($this->users), + 'executions' => static::serializeValue($this->executions), + 'GBHours' => static::serializeValue($this->gBHours), + 'imageTransformations' => static::serializeValue($this->imageTransformations), + 'authPhone' => static::serializeValue($this->authPhone), + 'budgetLimit' => static::serializeValue($this->budgetLimit) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/Block.php b/src/Appwrite/Models/Block.php new file mode 100644 index 00000000..682cd510 --- /dev/null +++ b/src/Appwrite/Models/Block.php @@ -0,0 +1,69 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('resourceType', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceType" for ' . static::class . '.'); + } + if (!array_key_exists('resourceId', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceId" for ' . static::class . '.'); + } + + return new static( + createdAt: $data['$createdAt'], + resourceType: $data['resourceType'], + resourceId: $data['resourceId'], + reason: array_key_exists('reason', $data) ? $data['reason'] : null, + expiredAt: array_key_exists('expiredAt', $data) ? $data['expiredAt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$createdAt' => static::serializeValue($this->createdAt), + 'resourceType' => static::serializeValue($this->resourceType), + 'resourceId' => static::serializeValue($this->resourceId), + 'reason' => static::serializeValue($this->reason), + 'expiredAt' => static::serializeValue($this->expiredAt) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/Bucket.php b/src/Appwrite/Models/Bucket.php index 599bbf46..50a2927c 100644 --- a/src/Appwrite/Models/Bucket.php +++ b/src/Appwrite/Models/Bucket.php @@ -9,16 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'permissions' => '$permissions' - ]; - /** * Bucket constructor. * @@ -54,4 +44,95 @@ public function __construct( public int $totalSize ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('$permissions', $data)) { + throw new \InvalidArgumentException('Missing required field "$permissions" for ' . static::class . '.'); + } + if (!array_key_exists('fileSecurity', $data)) { + throw new \InvalidArgumentException('Missing required field "fileSecurity" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + if (!array_key_exists('maximumFileSize', $data)) { + throw new \InvalidArgumentException('Missing required field "maximumFileSize" for ' . static::class . '.'); + } + if (!array_key_exists('allowedFileExtensions', $data)) { + throw new \InvalidArgumentException('Missing required field "allowedFileExtensions" for ' . static::class . '.'); + } + if (!array_key_exists('compression', $data)) { + throw new \InvalidArgumentException('Missing required field "compression" for ' . static::class . '.'); + } + if (!array_key_exists('encryption', $data)) { + throw new \InvalidArgumentException('Missing required field "encryption" for ' . static::class . '.'); + } + if (!array_key_exists('antivirus', $data)) { + throw new \InvalidArgumentException('Missing required field "antivirus" for ' . static::class . '.'); + } + if (!array_key_exists('transformations', $data)) { + throw new \InvalidArgumentException('Missing required field "transformations" for ' . static::class . '.'); + } + if (!array_key_exists('totalSize', $data)) { + throw new \InvalidArgumentException('Missing required field "totalSize" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + permissions: $data['$permissions'], + fileSecurity: $data['fileSecurity'], + name: $data['name'], + enabled: $data['enabled'], + maximumFileSize: $data['maximumFileSize'], + allowedFileExtensions: $data['allowedFileExtensions'], + compression: $data['compression'], + encryption: $data['encryption'], + antivirus: $data['antivirus'], + transformations: $data['transformations'], + totalSize: $data['totalSize'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + '$permissions' => static::serializeValue($this->permissions), + 'fileSecurity' => static::serializeValue($this->fileSecurity), + 'name' => static::serializeValue($this->name), + 'enabled' => static::serializeValue($this->enabled), + 'maximumFileSize' => static::serializeValue($this->maximumFileSize), + 'allowedFileExtensions' => static::serializeValue($this->allowedFileExtensions), + 'compression' => static::serializeValue($this->compression), + 'encryption' => static::serializeValue($this->encryption), + 'antivirus' => static::serializeValue($this->antivirus), + 'transformations' => static::serializeValue($this->transformations), + 'totalSize' => static::serializeValue($this->totalSize) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/BucketList.php b/src/Appwrite/Models/BucketList.php index 4870bcc8..79edabbf 100644 --- a/src/Appwrite/Models/BucketList.php +++ b/src/Appwrite/Models/BucketList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'buckets' => Bucket::class - ]; - /** * BucketList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $buckets ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('buckets', $data)) { + throw new \InvalidArgumentException('Missing required field "buckets" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + buckets: is_array($data['buckets']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Bucket::class, $item), + $data['buckets'] + ) + : $data['buckets'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'buckets' => static::serializeValue($this->buckets) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Collection.php b/src/Appwrite/Models/Collection.php index eec66ab8..a5d8af5d 100644 --- a/src/Appwrite/Models/Collection.php +++ b/src/Appwrite/Models/Collection.php @@ -9,23 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'permissions' => '$permissions' - ]; - - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'indexes' => Index::class - ]; - /** * Collection constructor. * @@ -57,4 +40,90 @@ public function __construct( public int $bytesUsed ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('$permissions', $data)) { + throw new \InvalidArgumentException('Missing required field "$permissions" for ' . static::class . '.'); + } + if (!array_key_exists('databaseId', $data)) { + throw new \InvalidArgumentException('Missing required field "databaseId" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + if (!array_key_exists('documentSecurity', $data)) { + throw new \InvalidArgumentException('Missing required field "documentSecurity" for ' . static::class . '.'); + } + if (!array_key_exists('attributes', $data)) { + throw new \InvalidArgumentException('Missing required field "attributes" for ' . static::class . '.'); + } + if (!array_key_exists('indexes', $data)) { + throw new \InvalidArgumentException('Missing required field "indexes" for ' . static::class . '.'); + } + if (!array_key_exists('bytesMax', $data)) { + throw new \InvalidArgumentException('Missing required field "bytesMax" for ' . static::class . '.'); + } + if (!array_key_exists('bytesUsed', $data)) { + throw new \InvalidArgumentException('Missing required field "bytesUsed" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + permissions: $data['$permissions'], + databaseId: $data['databaseId'], + name: $data['name'], + enabled: $data['enabled'], + documentSecurity: $data['documentSecurity'], + attributes: $data['attributes'], + indexes: is_array($data['indexes']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Index::class, $item), + $data['indexes'] + ) + : $data['indexes'], + bytesMax: $data['bytesMax'], + bytesUsed: $data['bytesUsed'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + '$permissions' => static::serializeValue($this->permissions), + 'databaseId' => static::serializeValue($this->databaseId), + 'name' => static::serializeValue($this->name), + 'enabled' => static::serializeValue($this->enabled), + 'documentSecurity' => static::serializeValue($this->documentSecurity), + 'attributes' => static::serializeValue($this->attributes), + 'indexes' => static::serializeValue($this->indexes), + 'bytesMax' => static::serializeValue($this->bytesMax), + 'bytesUsed' => static::serializeValue($this->bytesUsed) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/CollectionList.php b/src/Appwrite/Models/CollectionList.php index 3b2cf8c6..de3a804a 100644 --- a/src/Appwrite/Models/CollectionList.php +++ b/src/Appwrite/Models/CollectionList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'collections' => Collection::class - ]; - /** * CollectionList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $collections ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('collections', $data)) { + throw new \InvalidArgumentException('Missing required field "collections" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + collections: is_array($data['collections']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Collection::class, $item), + $data['collections'] + ) + : $data['collections'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'collections' => static::serializeValue($this->collections) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnBoolean.php b/src/Appwrite/Models/ColumnBoolean.php index c19edc83..174c0ce9 100644 --- a/src/Appwrite/Models/ColumnBoolean.php +++ b/src/Appwrite/Models/ColumnBoolean.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnBoolean constructor. * @@ -31,8 +21,8 @@ * @param bool $required is column required? * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. - * @param bool|null $xarray is column an array? - * @param bool|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param bool|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -42,8 +32,68 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?bool $xdefault = null + public ?bool $array = null, + public ?bool $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnDatetime.php b/src/Appwrite/Models/ColumnDatetime.php index a533d3f4..0596eda8 100644 --- a/src/Appwrite/Models/ColumnDatetime.php +++ b/src/Appwrite/Models/ColumnDatetime.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnDatetime constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. * @param string $format iso 8601 format. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. only null is optional + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. only null is optional */ public function __construct( public string $key, @@ -44,8 +34,73 @@ public function __construct( public string $createdAt, public string $updatedAt, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnEmail.php b/src/Appwrite/Models/ColumnEmail.php index d3c5957f..5d5b77dd 100644 --- a/src/Appwrite/Models/ColumnEmail.php +++ b/src/Appwrite/Models/ColumnEmail.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnEmail constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. * @param string $format string format. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -44,8 +34,73 @@ public function __construct( public string $createdAt, public string $updatedAt, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnEnum.php b/src/Appwrite/Models/ColumnEnum.php index 8c46d1a6..748df535 100644 --- a/src/Appwrite/Models/ColumnEnum.php +++ b/src/Appwrite/Models/ColumnEnum.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnEnum constructor. * @@ -33,8 +23,8 @@ * @param string $updatedAt column update date in iso 8601 format. * @param array $elements array of elements in enumerated type. * @param string $format string format. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -46,8 +36,78 @@ public function __construct( public string $updatedAt, public array $elements, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('elements', $data)) { + throw new \InvalidArgumentException('Missing required field "elements" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + elements: $data['elements'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'elements' => static::serializeValue($this->elements), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnFloat.php b/src/Appwrite/Models/ColumnFloat.php index da54de02..5ccc00ee 100644 --- a/src/Appwrite/Models/ColumnFloat.php +++ b/src/Appwrite/Models/ColumnFloat.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnFloat constructor. * @@ -31,10 +21,10 @@ * @param bool $required is column required? * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. - * @param bool|null $xarray is column an array? + * @param bool|null $array is column an array? * @param float|null $min minimum value to enforce for new documents. * @param float|null $max maximum value to enforce for new documents. - * @param float|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param float|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -44,10 +34,74 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, + public ?bool $array = null, public ?float $min = null, public ?float $max = null, - public ?float $xdefault = null + public ?float $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + min: array_key_exists('min', $data) ? $data['min'] : null, + max: array_key_exists('max', $data) ? $data['max'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'min' => static::serializeValue($this->min), + 'max' => static::serializeValue($this->max), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnIndex.php b/src/Appwrite/Models/ColumnIndex.php index 1b7ea054..d46c91d4 100644 --- a/src/Appwrite/Models/ColumnIndex.php +++ b/src/Appwrite/Models/ColumnIndex.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * ColumnIndex constructor. * @@ -45,4 +36,72 @@ public function __construct( public ?array $orders = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('columns', $data)) { + throw new \InvalidArgumentException('Missing required field "columns" for ' . static::class . '.'); + } + if (!array_key_exists('lengths', $data)) { + throw new \InvalidArgumentException('Missing required field "lengths" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + key: $data['key'], + type: $data['type'], + status: $data['status'], + error: $data['error'], + columns: $data['columns'], + lengths: $data['lengths'], + orders: array_key_exists('orders', $data) ? $data['orders'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'columns' => static::serializeValue($this->columns), + 'lengths' => static::serializeValue($this->lengths), + 'orders' => static::serializeValue($this->orders) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnIndexList.php b/src/Appwrite/Models/ColumnIndexList.php index d281069c..893e04f7 100644 --- a/src/Appwrite/Models/ColumnIndexList.php +++ b/src/Appwrite/Models/ColumnIndexList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'indexes' => ColumnIndex::class - ]; - /** * ColumnIndexList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $indexes ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('indexes', $data)) { + throw new \InvalidArgumentException('Missing required field "indexes" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + indexes: is_array($data['indexes']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(ColumnIndex::class, $item), + $data['indexes'] + ) + : $data['indexes'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'indexes' => static::serializeValue($this->indexes) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnInteger.php b/src/Appwrite/Models/ColumnInteger.php index 7d34eb96..1782d1c8 100644 --- a/src/Appwrite/Models/ColumnInteger.php +++ b/src/Appwrite/Models/ColumnInteger.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnInteger constructor. * @@ -31,10 +21,10 @@ * @param bool $required is column required? * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. - * @param bool|null $xarray is column an array? + * @param bool|null $array is column an array? * @param int|null $min minimum value to enforce for new documents. * @param int|null $max maximum value to enforce for new documents. - * @param int|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param int|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -44,10 +34,74 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, + public ?bool $array = null, public ?int $min = null, public ?int $max = null, - public ?int $xdefault = null + public ?int $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + min: array_key_exists('min', $data) ? $data['min'] : null, + max: array_key_exists('max', $data) ? $data['max'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'min' => static::serializeValue($this->min), + 'max' => static::serializeValue($this->max), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnIp.php b/src/Appwrite/Models/ColumnIp.php index 8cd23b9e..48c658dc 100644 --- a/src/Appwrite/Models/ColumnIp.php +++ b/src/Appwrite/Models/ColumnIp.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnIp constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. * @param string $format string format. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -44,8 +34,73 @@ public function __construct( public string $createdAt, public string $updatedAt, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnLine.php b/src/Appwrite/Models/ColumnLine.php index 540e9ca3..5c3b2ed0 100644 --- a/src/Appwrite/Models/ColumnLine.php +++ b/src/Appwrite/Models/ColumnLine.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnLine constructor. * @@ -31,8 +21,8 @@ * @param bool $required is column required? * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. - * @param bool|null $xarray is column an array? - * @param array|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param array|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -42,8 +32,68 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?array $xdefault = null + public ?bool $array = null, + public ?array $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnList.php b/src/Appwrite/Models/ColumnList.php index c67057ac..cccaa203 100644 --- a/src/Appwrite/Models/ColumnList.php +++ b/src/Appwrite/Models/ColumnList.php @@ -20,4 +20,35 @@ public function __construct( public array $columns ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('columns', $data)) { + throw new \InvalidArgumentException('Missing required field "columns" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + columns: $data['columns'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'columns' => static::serializeValue($this->columns) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnLongtext.php b/src/Appwrite/Models/ColumnLongtext.php index 3750a705..07961098 100644 --- a/src/Appwrite/Models/ColumnLongtext.php +++ b/src/Appwrite/Models/ColumnLongtext.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnLongtext constructor. * @@ -31,8 +21,8 @@ * @param bool $required is column required? * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. cannot be set when column is required. * @param bool|null $encrypt defines whether this column is encrypted or not. */ public function __construct( @@ -43,9 +33,71 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnMediumtext.php b/src/Appwrite/Models/ColumnMediumtext.php index 05a2f426..feb94f18 100644 --- a/src/Appwrite/Models/ColumnMediumtext.php +++ b/src/Appwrite/Models/ColumnMediumtext.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnMediumtext constructor. * @@ -31,8 +21,8 @@ * @param bool $required is column required? * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. cannot be set when column is required. * @param bool|null $encrypt defines whether this column is encrypted or not. */ public function __construct( @@ -43,9 +33,71 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnPoint.php b/src/Appwrite/Models/ColumnPoint.php index 28358482..e626d146 100644 --- a/src/Appwrite/Models/ColumnPoint.php +++ b/src/Appwrite/Models/ColumnPoint.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnPoint constructor. * @@ -31,8 +21,8 @@ * @param bool $required is column required? * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. - * @param bool|null $xarray is column an array? - * @param array|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param array|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -42,8 +32,68 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?array $xdefault = null + public ?bool $array = null, + public ?array $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnPolygon.php b/src/Appwrite/Models/ColumnPolygon.php index 63d29411..fcfb0a4f 100644 --- a/src/Appwrite/Models/ColumnPolygon.php +++ b/src/Appwrite/Models/ColumnPolygon.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnPolygon constructor. * @@ -31,8 +21,8 @@ * @param bool $required is column required? * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. - * @param bool|null $xarray is column an array? - * @param array|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param array|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -42,8 +32,68 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?array $xdefault = null + public ?bool $array = null, + public ?array $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnRelationship.php b/src/Appwrite/Models/ColumnRelationship.php index 593f3f90..05ea8fa2 100644 --- a/src/Appwrite/Models/ColumnRelationship.php +++ b/src/Appwrite/Models/ColumnRelationship.php @@ -11,15 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * ColumnRelationship constructor. * @@ -36,7 +27,7 @@ * @param string $twoWayKey the key of the two-way relationship. * @param string $onDelete how deleting the parent document will propagate to child documents. * @param string $side whether this is the parent or child side of the relationship - * @param bool|null $xarray is column an array? + * @param bool|null $array is column an array? */ public function __construct( public string $key, @@ -52,7 +43,95 @@ public function __construct( public string $twoWayKey, public string $onDelete, public string $side, - public ?bool $xarray = null + public ?bool $array = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('relatedTable', $data)) { + throw new \InvalidArgumentException('Missing required field "relatedTable" for ' . static::class . '.'); + } + if (!array_key_exists('relationType', $data)) { + throw new \InvalidArgumentException('Missing required field "relationType" for ' . static::class . '.'); + } + if (!array_key_exists('twoWay', $data)) { + throw new \InvalidArgumentException('Missing required field "twoWay" for ' . static::class . '.'); + } + if (!array_key_exists('twoWayKey', $data)) { + throw new \InvalidArgumentException('Missing required field "twoWayKey" for ' . static::class . '.'); + } + if (!array_key_exists('onDelete', $data)) { + throw new \InvalidArgumentException('Missing required field "onDelete" for ' . static::class . '.'); + } + if (!array_key_exists('side', $data)) { + throw new \InvalidArgumentException('Missing required field "side" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + relatedTable: $data['relatedTable'], + relationType: $data['relationType'], + twoWay: $data['twoWay'], + twoWayKey: $data['twoWayKey'], + onDelete: $data['onDelete'], + side: $data['side'], + array: array_key_exists('array', $data) ? $data['array'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'relatedTable' => static::serializeValue($this->relatedTable), + 'relationType' => static::serializeValue($this->relationType), + 'twoWay' => static::serializeValue($this->twoWay), + 'twoWayKey' => static::serializeValue($this->twoWayKey), + 'onDelete' => static::serializeValue($this->onDelete), + 'side' => static::serializeValue($this->side) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnString.php b/src/Appwrite/Models/ColumnString.php index 98149268..f93426f7 100644 --- a/src/Appwrite/Models/ColumnString.php +++ b/src/Appwrite/Models/ColumnString.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnString constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. * @param int $size column size. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. cannot be set when column is required. * @param bool|null $encrypt defines whether this column is encrypted or not. */ public function __construct( @@ -45,9 +35,76 @@ public function __construct( public string $createdAt, public string $updatedAt, public int $size, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('size', $data)) { + throw new \InvalidArgumentException('Missing required field "size" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + size: $data['size'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'size' => static::serializeValue($this->size), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnText.php b/src/Appwrite/Models/ColumnText.php index b4b03824..69cd4745 100644 --- a/src/Appwrite/Models/ColumnText.php +++ b/src/Appwrite/Models/ColumnText.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnText constructor. * @@ -31,8 +21,8 @@ * @param bool $required is column required? * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. cannot be set when column is required. * @param bool|null $encrypt defines whether this column is encrypted or not. */ public function __construct( @@ -43,9 +33,71 @@ public function __construct( public bool $required, public string $createdAt, public string $updatedAt, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnUrl.php b/src/Appwrite/Models/ColumnUrl.php index 3c1d807b..60d849e3 100644 --- a/src/Appwrite/Models/ColumnUrl.php +++ b/src/Appwrite/Models/ColumnUrl.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnUrl constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. * @param string $format string format. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. cannot be set when column is required. */ public function __construct( public string $key, @@ -44,8 +34,73 @@ public function __construct( public string $createdAt, public string $updatedAt, public string $format, - public ?bool $xarray = null, - public ?string $xdefault = null + public ?bool $array = null, + public ?string $default = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('format', $data)) { + throw new \InvalidArgumentException('Missing required field "format" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + format: $data['format'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'format' => static::serializeValue($this->format), + 'default' => static::serializeValue($this->default) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ColumnVarchar.php b/src/Appwrite/Models/ColumnVarchar.php index ec5807b3..467b20bd 100644 --- a/src/Appwrite/Models/ColumnVarchar.php +++ b/src/Appwrite/Models/ColumnVarchar.php @@ -11,16 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'xarray' => 'array', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'xdefault' => 'default' - ]; - /** * ColumnVarchar constructor. * @@ -32,8 +22,8 @@ * @param string $createdAt column creation date in iso 8601 format. * @param string $updatedAt column update date in iso 8601 format. * @param int $size column size. - * @param bool|null $xarray is column an array? - * @param string|null $xdefault default value for column when not provided. cannot be set when column is required. + * @param bool|null $array is column an array? + * @param string|null $default default value for column when not provided. cannot be set when column is required. * @param bool|null $encrypt defines whether this column is encrypted or not. */ public function __construct( @@ -45,9 +35,76 @@ public function __construct( public string $createdAt, public string $updatedAt, public int $size, - public ?bool $xarray = null, - public ?string $xdefault = null, + public ?bool $array = null, + public ?string $default = null, public ?bool $encrypt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('required', $data)) { + throw new \InvalidArgumentException('Missing required field "required" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('size', $data)) { + throw new \InvalidArgumentException('Missing required field "size" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(ColumnStatus::class, $data['status']), + error: $data['error'], + required: $data['required'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + size: $data['size'], + array: array_key_exists('array', $data) ? $data['array'] : null, + default: array_key_exists('default', $data) ? $data['default'] : null, + encrypt: array_key_exists('encrypt', $data) ? $data['encrypt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'required' => static::serializeValue($this->required), + 'array' => static::serializeValue($this->array), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'size' => static::serializeValue($this->size), + 'default' => static::serializeValue($this->default), + 'encrypt' => static::serializeValue($this->encrypt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Continent.php b/src/Appwrite/Models/Continent.php index a0fcdce1..ce841743 100644 --- a/src/Appwrite/Models/Continent.php +++ b/src/Appwrite/Models/Continent.php @@ -20,4 +20,35 @@ public function __construct( public string $code ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException('Missing required field "code" for ' . static::class . '.'); + } + + return new static( + name: $data['name'], + code: $data['code'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'name' => static::serializeValue($this->name), + 'code' => static::serializeValue($this->code) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ContinentList.php b/src/Appwrite/Models/ContinentList.php index 23e1e975..33d61231 100644 --- a/src/Appwrite/Models/ContinentList.php +++ b/src/Appwrite/Models/ContinentList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'continents' => Continent::class - ]; - /** * ContinentList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $continents ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('continents', $data)) { + throw new \InvalidArgumentException('Missing required field "continents" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + continents: is_array($data['continents']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Continent::class, $item), + $data['continents'] + ) + : $data['continents'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'continents' => static::serializeValue($this->continents) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Country.php b/src/Appwrite/Models/Country.php index 6e5bc152..942ce59c 100644 --- a/src/Appwrite/Models/Country.php +++ b/src/Appwrite/Models/Country.php @@ -20,4 +20,35 @@ public function __construct( public string $code ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException('Missing required field "code" for ' . static::class . '.'); + } + + return new static( + name: $data['name'], + code: $data['code'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'name' => static::serializeValue($this->name), + 'code' => static::serializeValue($this->code) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/CountryList.php b/src/Appwrite/Models/CountryList.php index c5ba88f2..ee4b1eb5 100644 --- a/src/Appwrite/Models/CountryList.php +++ b/src/Appwrite/Models/CountryList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'countries' => Country::class - ]; - /** * CountryList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $countries ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('countries', $data)) { + throw new \InvalidArgumentException('Missing required field "countries" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + countries: is_array($data['countries']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Country::class, $item), + $data['countries'] + ) + : $data['countries'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'countries' => static::serializeValue($this->countries) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Currency.php b/src/Appwrite/Models/Currency.php index 851c0741..97aa3d91 100644 --- a/src/Appwrite/Models/Currency.php +++ b/src/Appwrite/Models/Currency.php @@ -30,4 +30,60 @@ public function __construct( public string $namePlural ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('symbol', $data)) { + throw new \InvalidArgumentException('Missing required field "symbol" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('symbolNative', $data)) { + throw new \InvalidArgumentException('Missing required field "symbolNative" for ' . static::class . '.'); + } + if (!array_key_exists('decimalDigits', $data)) { + throw new \InvalidArgumentException('Missing required field "decimalDigits" for ' . static::class . '.'); + } + if (!array_key_exists('rounding', $data)) { + throw new \InvalidArgumentException('Missing required field "rounding" for ' . static::class . '.'); + } + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException('Missing required field "code" for ' . static::class . '.'); + } + if (!array_key_exists('namePlural', $data)) { + throw new \InvalidArgumentException('Missing required field "namePlural" for ' . static::class . '.'); + } + + return new static( + symbol: $data['symbol'], + name: $data['name'], + symbolNative: $data['symbolNative'], + decimalDigits: $data['decimalDigits'], + rounding: $data['rounding'], + code: $data['code'], + namePlural: $data['namePlural'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'symbol' => static::serializeValue($this->symbol), + 'name' => static::serializeValue($this->name), + 'symbolNative' => static::serializeValue($this->symbolNative), + 'decimalDigits' => static::serializeValue($this->decimalDigits), + 'rounding' => static::serializeValue($this->rounding), + 'code' => static::serializeValue($this->code), + 'namePlural' => static::serializeValue($this->namePlural) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/CurrencyList.php b/src/Appwrite/Models/CurrencyList.php index fc8ad78f..42fa537a 100644 --- a/src/Appwrite/Models/CurrencyList.php +++ b/src/Appwrite/Models/CurrencyList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'currencies' => Currency::class - ]; - /** * CurrencyList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $currencies ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('currencies', $data)) { + throw new \InvalidArgumentException('Missing required field "currencies" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + currencies: is_array($data['currencies']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Currency::class, $item), + $data['currencies'] + ) + : $data['currencies'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'currencies' => static::serializeValue($this->currencies) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Database.php b/src/Appwrite/Models/Database.php index 96c180dc..4eb1ee39 100644 --- a/src/Appwrite/Models/Database.php +++ b/src/Appwrite/Models/Database.php @@ -11,23 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'policies' => Index::class, - 'archives' => Collection::class - ]; - /** * Database constructor. * @@ -51,4 +34,75 @@ public function __construct( public array $archives ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('policies', $data)) { + throw new \InvalidArgumentException('Missing required field "policies" for ' . static::class . '.'); + } + if (!array_key_exists('archives', $data)) { + throw new \InvalidArgumentException('Missing required field "archives" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + name: $data['name'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + enabled: $data['enabled'], + type: static::hydrateTypedValue(DatabaseType::class, $data['type']), + policies: is_array($data['policies']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Index::class, $item), + $data['policies'] + ) + : $data['policies'], + archives: is_array($data['archives']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Collection::class, $item), + $data['archives'] + ) + : $data['archives'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + 'name' => static::serializeValue($this->name), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'enabled' => static::serializeValue($this->enabled), + 'type' => static::serializeValue($this->type), + 'policies' => static::serializeValue($this->policies), + 'archives' => static::serializeValue($this->archives) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/DatabaseList.php b/src/Appwrite/Models/DatabaseList.php index dba3959e..bb164284 100644 --- a/src/Appwrite/Models/DatabaseList.php +++ b/src/Appwrite/Models/DatabaseList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'databases' => Database::class - ]; - /** * DatabaseList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $databases ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('databases', $data)) { + throw new \InvalidArgumentException('Missing required field "databases" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + databases: is_array($data['databases']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Database::class, $item), + $data['databases'] + ) + : $data['databases'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'databases' => static::serializeValue($this->databases) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Deployment.php b/src/Appwrite/Models/Deployment.php index 6843ec2b..702be010 100644 --- a/src/Appwrite/Models/Deployment.php +++ b/src/Appwrite/Models/Deployment.php @@ -11,15 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Deployment constructor. * @@ -81,4 +72,160 @@ public function __construct( public string $providerBranchUrl ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('resourceId', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceId" for ' . static::class . '.'); + } + if (!array_key_exists('resourceType', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceType" for ' . static::class . '.'); + } + if (!array_key_exists('entrypoint', $data)) { + throw new \InvalidArgumentException('Missing required field "entrypoint" for ' . static::class . '.'); + } + if (!array_key_exists('sourceSize', $data)) { + throw new \InvalidArgumentException('Missing required field "sourceSize" for ' . static::class . '.'); + } + if (!array_key_exists('buildSize', $data)) { + throw new \InvalidArgumentException('Missing required field "buildSize" for ' . static::class . '.'); + } + if (!array_key_exists('totalSize', $data)) { + throw new \InvalidArgumentException('Missing required field "totalSize" for ' . static::class . '.'); + } + if (!array_key_exists('buildId', $data)) { + throw new \InvalidArgumentException('Missing required field "buildId" for ' . static::class . '.'); + } + if (!array_key_exists('activate', $data)) { + throw new \InvalidArgumentException('Missing required field "activate" for ' . static::class . '.'); + } + if (!array_key_exists('screenshotLight', $data)) { + throw new \InvalidArgumentException('Missing required field "screenshotLight" for ' . static::class . '.'); + } + if (!array_key_exists('screenshotDark', $data)) { + throw new \InvalidArgumentException('Missing required field "screenshotDark" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('buildLogs', $data)) { + throw new \InvalidArgumentException('Missing required field "buildLogs" for ' . static::class . '.'); + } + if (!array_key_exists('buildDuration', $data)) { + throw new \InvalidArgumentException('Missing required field "buildDuration" for ' . static::class . '.'); + } + if (!array_key_exists('providerRepositoryName', $data)) { + throw new \InvalidArgumentException('Missing required field "providerRepositoryName" for ' . static::class . '.'); + } + if (!array_key_exists('providerRepositoryOwner', $data)) { + throw new \InvalidArgumentException('Missing required field "providerRepositoryOwner" for ' . static::class . '.'); + } + if (!array_key_exists('providerRepositoryUrl', $data)) { + throw new \InvalidArgumentException('Missing required field "providerRepositoryUrl" for ' . static::class . '.'); + } + if (!array_key_exists('providerCommitHash', $data)) { + throw new \InvalidArgumentException('Missing required field "providerCommitHash" for ' . static::class . '.'); + } + if (!array_key_exists('providerCommitAuthorUrl', $data)) { + throw new \InvalidArgumentException('Missing required field "providerCommitAuthorUrl" for ' . static::class . '.'); + } + if (!array_key_exists('providerCommitAuthor', $data)) { + throw new \InvalidArgumentException('Missing required field "providerCommitAuthor" for ' . static::class . '.'); + } + if (!array_key_exists('providerCommitMessage', $data)) { + throw new \InvalidArgumentException('Missing required field "providerCommitMessage" for ' . static::class . '.'); + } + if (!array_key_exists('providerCommitUrl', $data)) { + throw new \InvalidArgumentException('Missing required field "providerCommitUrl" for ' . static::class . '.'); + } + if (!array_key_exists('providerBranch', $data)) { + throw new \InvalidArgumentException('Missing required field "providerBranch" for ' . static::class . '.'); + } + if (!array_key_exists('providerBranchUrl', $data)) { + throw new \InvalidArgumentException('Missing required field "providerBranchUrl" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + type: $data['type'], + resourceId: $data['resourceId'], + resourceType: $data['resourceType'], + entrypoint: $data['entrypoint'], + sourceSize: $data['sourceSize'], + buildSize: $data['buildSize'], + totalSize: $data['totalSize'], + buildId: $data['buildId'], + activate: $data['activate'], + screenshotLight: $data['screenshotLight'], + screenshotDark: $data['screenshotDark'], + status: static::hydrateTypedValue(DeploymentStatus::class, $data['status']), + buildLogs: $data['buildLogs'], + buildDuration: $data['buildDuration'], + providerRepositoryName: $data['providerRepositoryName'], + providerRepositoryOwner: $data['providerRepositoryOwner'], + providerRepositoryUrl: $data['providerRepositoryUrl'], + providerCommitHash: $data['providerCommitHash'], + providerCommitAuthorUrl: $data['providerCommitAuthorUrl'], + providerCommitAuthor: $data['providerCommitAuthor'], + providerCommitMessage: $data['providerCommitMessage'], + providerCommitUrl: $data['providerCommitUrl'], + providerBranch: $data['providerBranch'], + providerBranchUrl: $data['providerBranchUrl'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'type' => static::serializeValue($this->type), + 'resourceId' => static::serializeValue($this->resourceId), + 'resourceType' => static::serializeValue($this->resourceType), + 'entrypoint' => static::serializeValue($this->entrypoint), + 'sourceSize' => static::serializeValue($this->sourceSize), + 'buildSize' => static::serializeValue($this->buildSize), + 'totalSize' => static::serializeValue($this->totalSize), + 'buildId' => static::serializeValue($this->buildId), + 'activate' => static::serializeValue($this->activate), + 'screenshotLight' => static::serializeValue($this->screenshotLight), + 'screenshotDark' => static::serializeValue($this->screenshotDark), + 'status' => static::serializeValue($this->status), + 'buildLogs' => static::serializeValue($this->buildLogs), + 'buildDuration' => static::serializeValue($this->buildDuration), + 'providerRepositoryName' => static::serializeValue($this->providerRepositoryName), + 'providerRepositoryOwner' => static::serializeValue($this->providerRepositoryOwner), + 'providerRepositoryUrl' => static::serializeValue($this->providerRepositoryUrl), + 'providerCommitHash' => static::serializeValue($this->providerCommitHash), + 'providerCommitAuthorUrl' => static::serializeValue($this->providerCommitAuthorUrl), + 'providerCommitAuthor' => static::serializeValue($this->providerCommitAuthor), + 'providerCommitMessage' => static::serializeValue($this->providerCommitMessage), + 'providerCommitUrl' => static::serializeValue($this->providerCommitUrl), + 'providerBranch' => static::serializeValue($this->providerBranch), + 'providerBranchUrl' => static::serializeValue($this->providerBranchUrl) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/DeploymentList.php b/src/Appwrite/Models/DeploymentList.php index 8343b615..adb27646 100644 --- a/src/Appwrite/Models/DeploymentList.php +++ b/src/Appwrite/Models/DeploymentList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'deployments' => Deployment::class - ]; - /** * DeploymentList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $deployments ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('deployments', $data)) { + throw new \InvalidArgumentException('Missing required field "deployments" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + deployments: is_array($data['deployments']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Deployment::class, $item), + $data['deployments'] + ) + : $data['deployments'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'deployments' => static::serializeValue($this->deployments) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/DevKey.php b/src/Appwrite/Models/DevKey.php new file mode 100644 index 00000000..24aa9908 --- /dev/null +++ b/src/Appwrite/Models/DevKey.php @@ -0,0 +1,96 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('expire', $data)) { + throw new \InvalidArgumentException('Missing required field "expire" for ' . static::class . '.'); + } + if (!array_key_exists('secret', $data)) { + throw new \InvalidArgumentException('Missing required field "secret" for ' . static::class . '.'); + } + if (!array_key_exists('accessedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "accessedAt" for ' . static::class . '.'); + } + if (!array_key_exists('sdks', $data)) { + throw new \InvalidArgumentException('Missing required field "sdks" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + expire: $data['expire'], + secret: $data['secret'], + accessedAt: $data['accessedAt'], + sdks: $data['sdks'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'expire' => static::serializeValue($this->expire), + 'secret' => static::serializeValue($this->secret), + 'accessedAt' => static::serializeValue($this->accessedAt), + 'sdks' => static::serializeValue($this->sdks) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/Document.php b/src/Appwrite/Models/Document.php index a45464ae..0aa44b25 100644 --- a/src/Appwrite/Models/Document.php +++ b/src/Appwrite/Models/Document.php @@ -9,19 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'sequence' => '$sequence', - 'collectionId' => '$collectionId', - 'databaseId' => '$databaseId', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'permissions' => '$permissions' - ]; - private const ADDITIONAL_PROPERTIES = true; /** @@ -47,4 +34,78 @@ public function __construct( public array $data = [] ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$sequence', $data)) { + throw new \InvalidArgumentException('Missing required field "$sequence" for ' . static::class . '.'); + } + if (!array_key_exists('$collectionId', $data)) { + throw new \InvalidArgumentException('Missing required field "$collectionId" for ' . static::class . '.'); + } + if (!array_key_exists('$databaseId', $data)) { + throw new \InvalidArgumentException('Missing required field "$databaseId" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('$permissions', $data)) { + throw new \InvalidArgumentException('Missing required field "$permissions" for ' . static::class . '.'); + } + + $additionalProperties = static::extractAdditionalPropertiesFromFields( + $data, + [ + '$id', + '$sequence', + '$collectionId', + '$databaseId', + '$createdAt', + '$updatedAt', + '$permissions' + ] + ); + + return new static( + id: $data['$id'], + sequence: $data['$sequence'], + collectionId: $data['$collectionId'], + databaseId: $data['$databaseId'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + permissions: $data['$permissions'], + data: $additionalProperties + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$sequence' => static::serializeValue($this->sequence), + '$collectionId' => static::serializeValue($this->collectionId), + '$databaseId' => static::serializeValue($this->databaseId), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + '$permissions' => static::serializeValue($this->permissions) + ]; + + foreach (static::serializeAdditionalProperties($this->data) as $field => $value) { + $result[$field] = $value; + } + + return $result; + } } diff --git a/src/Appwrite/Models/DocumentList.php b/src/Appwrite/Models/DocumentList.php index 681aba2e..04611e46 100644 --- a/src/Appwrite/Models/DocumentList.php +++ b/src/Appwrite/Models/DocumentList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'documents' => Document::class - ]; - /** * DocumentList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $documents ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('documents', $data)) { + throw new \InvalidArgumentException('Missing required field "documents" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + documents: is_array($data['documents']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Document::class, $item), + $data['documents'] + ) + : $data['documents'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'documents' => static::serializeValue($this->documents) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Execution.php b/src/Appwrite/Models/Execution.php index fae1e525..877f42a7 100644 --- a/src/Appwrite/Models/Execution.php +++ b/src/Appwrite/Models/Execution.php @@ -12,24 +12,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'permissions' => '$permissions' - ]; - - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'requestHeaders' => Headers::class, - 'responseHeaders' => Headers::class - ]; - /** * Execution constructor. * @@ -73,4 +55,122 @@ public function __construct( public ?string $scheduledAt = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('$permissions', $data)) { + throw new \InvalidArgumentException('Missing required field "$permissions" for ' . static::class . '.'); + } + if (!array_key_exists('functionId', $data)) { + throw new \InvalidArgumentException('Missing required field "functionId" for ' . static::class . '.'); + } + if (!array_key_exists('deploymentId', $data)) { + throw new \InvalidArgumentException('Missing required field "deploymentId" for ' . static::class . '.'); + } + if (!array_key_exists('trigger', $data)) { + throw new \InvalidArgumentException('Missing required field "trigger" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('requestMethod', $data)) { + throw new \InvalidArgumentException('Missing required field "requestMethod" for ' . static::class . '.'); + } + if (!array_key_exists('requestPath', $data)) { + throw new \InvalidArgumentException('Missing required field "requestPath" for ' . static::class . '.'); + } + if (!array_key_exists('requestHeaders', $data)) { + throw new \InvalidArgumentException('Missing required field "requestHeaders" for ' . static::class . '.'); + } + if (!array_key_exists('responseStatusCode', $data)) { + throw new \InvalidArgumentException('Missing required field "responseStatusCode" for ' . static::class . '.'); + } + if (!array_key_exists('responseBody', $data)) { + throw new \InvalidArgumentException('Missing required field "responseBody" for ' . static::class . '.'); + } + if (!array_key_exists('responseHeaders', $data)) { + throw new \InvalidArgumentException('Missing required field "responseHeaders" for ' . static::class . '.'); + } + if (!array_key_exists('logs', $data)) { + throw new \InvalidArgumentException('Missing required field "logs" for ' . static::class . '.'); + } + if (!array_key_exists('errors', $data)) { + throw new \InvalidArgumentException('Missing required field "errors" for ' . static::class . '.'); + } + if (!array_key_exists('duration', $data)) { + throw new \InvalidArgumentException('Missing required field "duration" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + permissions: $data['$permissions'], + functionId: $data['functionId'], + deploymentId: $data['deploymentId'], + trigger: static::hydrateTypedValue(ExecutionTrigger::class, $data['trigger']), + status: static::hydrateTypedValue(ExecutionStatus::class, $data['status']), + requestMethod: $data['requestMethod'], + requestPath: $data['requestPath'], + requestHeaders: is_array($data['requestHeaders']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Headers::class, $item), + $data['requestHeaders'] + ) + : $data['requestHeaders'], + responseStatusCode: $data['responseStatusCode'], + responseBody: $data['responseBody'], + responseHeaders: is_array($data['responseHeaders']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Headers::class, $item), + $data['responseHeaders'] + ) + : $data['responseHeaders'], + logs: $data['logs'], + errors: $data['errors'], + duration: $data['duration'], + scheduledAt: array_key_exists('scheduledAt', $data) ? $data['scheduledAt'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + '$permissions' => static::serializeValue($this->permissions), + 'functionId' => static::serializeValue($this->functionId), + 'deploymentId' => static::serializeValue($this->deploymentId), + 'trigger' => static::serializeValue($this->trigger), + 'status' => static::serializeValue($this->status), + 'requestMethod' => static::serializeValue($this->requestMethod), + 'requestPath' => static::serializeValue($this->requestPath), + 'requestHeaders' => static::serializeValue($this->requestHeaders), + 'responseStatusCode' => static::serializeValue($this->responseStatusCode), + 'responseBody' => static::serializeValue($this->responseBody), + 'responseHeaders' => static::serializeValue($this->responseHeaders), + 'logs' => static::serializeValue($this->logs), + 'errors' => static::serializeValue($this->errors), + 'duration' => static::serializeValue($this->duration), + 'scheduledAt' => static::serializeValue($this->scheduledAt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ExecutionList.php b/src/Appwrite/Models/ExecutionList.php index 98c60e5e..c9b4b04a 100644 --- a/src/Appwrite/Models/ExecutionList.php +++ b/src/Appwrite/Models/ExecutionList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'executions' => Execution::class - ]; - /** * ExecutionList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $executions ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('executions', $data)) { + throw new \InvalidArgumentException('Missing required field "executions" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + executions: is_array($data['executions']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Execution::class, $item), + $data['executions'] + ) + : $data['executions'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'executions' => static::serializeValue($this->executions) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/File.php b/src/Appwrite/Models/File.php index 6ed5914b..b2bbc9a8 100644 --- a/src/Appwrite/Models/File.php +++ b/src/Appwrite/Models/File.php @@ -9,16 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'permissions' => '$permissions' - ]; - /** * File constructor. * @@ -52,4 +42,90 @@ public function __construct( public string $compression ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('bucketId', $data)) { + throw new \InvalidArgumentException('Missing required field "bucketId" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('$permissions', $data)) { + throw new \InvalidArgumentException('Missing required field "$permissions" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('signature', $data)) { + throw new \InvalidArgumentException('Missing required field "signature" for ' . static::class . '.'); + } + if (!array_key_exists('mimeType', $data)) { + throw new \InvalidArgumentException('Missing required field "mimeType" for ' . static::class . '.'); + } + if (!array_key_exists('sizeOriginal', $data)) { + throw new \InvalidArgumentException('Missing required field "sizeOriginal" for ' . static::class . '.'); + } + if (!array_key_exists('chunksTotal', $data)) { + throw new \InvalidArgumentException('Missing required field "chunksTotal" for ' . static::class . '.'); + } + if (!array_key_exists('chunksUploaded', $data)) { + throw new \InvalidArgumentException('Missing required field "chunksUploaded" for ' . static::class . '.'); + } + if (!array_key_exists('encryption', $data)) { + throw new \InvalidArgumentException('Missing required field "encryption" for ' . static::class . '.'); + } + if (!array_key_exists('compression', $data)) { + throw new \InvalidArgumentException('Missing required field "compression" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + bucketId: $data['bucketId'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + permissions: $data['$permissions'], + name: $data['name'], + signature: $data['signature'], + mimeType: $data['mimeType'], + sizeOriginal: $data['sizeOriginal'], + chunksTotal: $data['chunksTotal'], + chunksUploaded: $data['chunksUploaded'], + encryption: $data['encryption'], + compression: $data['compression'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + 'bucketId' => static::serializeValue($this->bucketId), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + '$permissions' => static::serializeValue($this->permissions), + 'name' => static::serializeValue($this->name), + 'signature' => static::serializeValue($this->signature), + 'mimeType' => static::serializeValue($this->mimeType), + 'sizeOriginal' => static::serializeValue($this->sizeOriginal), + 'chunksTotal' => static::serializeValue($this->chunksTotal), + 'chunksUploaded' => static::serializeValue($this->chunksUploaded), + 'encryption' => static::serializeValue($this->encryption), + 'compression' => static::serializeValue($this->compression) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/FileList.php b/src/Appwrite/Models/FileList.php index c10730bb..2232f238 100644 --- a/src/Appwrite/Models/FileList.php +++ b/src/Appwrite/Models/FileList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'files' => File::class - ]; - /** * FileList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $files ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('files', $data)) { + throw new \InvalidArgumentException('Missing required field "files" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + files: is_array($data['files']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(File::class, $item), + $data['files'] + ) + : $data['files'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'files' => static::serializeValue($this->files) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Framework.php b/src/Appwrite/Models/Framework.php index 0d670315..04230237 100644 --- a/src/Appwrite/Models/Framework.php +++ b/src/Appwrite/Models/Framework.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'adapters' => FrameworkAdapter::class - ]; - /** * Framework constructor. * @@ -33,4 +26,55 @@ public function __construct( public array $adapters ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('buildRuntime', $data)) { + throw new \InvalidArgumentException('Missing required field "buildRuntime" for ' . static::class . '.'); + } + if (!array_key_exists('runtimes', $data)) { + throw new \InvalidArgumentException('Missing required field "runtimes" for ' . static::class . '.'); + } + if (!array_key_exists('adapters', $data)) { + throw new \InvalidArgumentException('Missing required field "adapters" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + name: $data['name'], + buildRuntime: $data['buildRuntime'], + runtimes: $data['runtimes'], + adapters: is_array($data['adapters']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(FrameworkAdapter::class, $item), + $data['adapters'] + ) + : $data['adapters'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'name' => static::serializeValue($this->name), + 'buildRuntime' => static::serializeValue($this->buildRuntime), + 'runtimes' => static::serializeValue($this->runtimes), + 'adapters' => static::serializeValue($this->adapters) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/FrameworkAdapter.php b/src/Appwrite/Models/FrameworkAdapter.php index 7f79799a..a76a7110 100644 --- a/src/Appwrite/Models/FrameworkAdapter.php +++ b/src/Appwrite/Models/FrameworkAdapter.php @@ -26,4 +26,50 @@ public function __construct( public string $fallbackFile ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('installCommand', $data)) { + throw new \InvalidArgumentException('Missing required field "installCommand" for ' . static::class . '.'); + } + if (!array_key_exists('buildCommand', $data)) { + throw new \InvalidArgumentException('Missing required field "buildCommand" for ' . static::class . '.'); + } + if (!array_key_exists('outputDirectory', $data)) { + throw new \InvalidArgumentException('Missing required field "outputDirectory" for ' . static::class . '.'); + } + if (!array_key_exists('fallbackFile', $data)) { + throw new \InvalidArgumentException('Missing required field "fallbackFile" for ' . static::class . '.'); + } + + return new static( + key: $data['key'], + installCommand: $data['installCommand'], + buildCommand: $data['buildCommand'], + outputDirectory: $data['outputDirectory'], + fallbackFile: $data['fallbackFile'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'key' => static::serializeValue($this->key), + 'installCommand' => static::serializeValue($this->installCommand), + 'buildCommand' => static::serializeValue($this->buildCommand), + 'outputDirectory' => static::serializeValue($this->outputDirectory), + 'fallbackFile' => static::serializeValue($this->fallbackFile) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/FrameworkList.php b/src/Appwrite/Models/FrameworkList.php index 69044cdd..42c11864 100644 --- a/src/Appwrite/Models/FrameworkList.php +++ b/src/Appwrite/Models/FrameworkList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'frameworks' => Framework::class - ]; - /** * FrameworkList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $frameworks ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('frameworks', $data)) { + throw new \InvalidArgumentException('Missing required field "frameworks" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + frameworks: is_array($data['frameworks']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Framework::class, $item), + $data['frameworks'] + ) + : $data['frameworks'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'frameworks' => static::serializeValue($this->frameworks) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/FunctionList.php b/src/Appwrite/Models/FunctionList.php index 919073ab..c66430ec 100644 --- a/src/Appwrite/Models/FunctionList.php +++ b/src/Appwrite/Models/FunctionList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'functions' => FunctionModel::class - ]; - /** * FunctionList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $functions ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('functions', $data)) { + throw new \InvalidArgumentException('Missing required field "functions" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + functions: is_array($data['functions']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(FunctionModel::class, $item), + $data['functions'] + ) + : $data['functions'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'functions' => static::serializeValue($this->functions) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/FunctionModel.php b/src/Appwrite/Models/FunctionModel.php index 6bb7c680..8d51da29 100644 --- a/src/Appwrite/Models/FunctionModel.php +++ b/src/Appwrite/Models/FunctionModel.php @@ -9,22 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'vars' => Variable::class - ]; - /** * Function constructor. * @@ -92,4 +76,180 @@ public function __construct( public string $runtimeSpecification ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('execute', $data)) { + throw new \InvalidArgumentException('Missing required field "execute" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + if (!array_key_exists('live', $data)) { + throw new \InvalidArgumentException('Missing required field "live" for ' . static::class . '.'); + } + if (!array_key_exists('logging', $data)) { + throw new \InvalidArgumentException('Missing required field "logging" for ' . static::class . '.'); + } + if (!array_key_exists('runtime', $data)) { + throw new \InvalidArgumentException('Missing required field "runtime" for ' . static::class . '.'); + } + if (!array_key_exists('deploymentRetention', $data)) { + throw new \InvalidArgumentException('Missing required field "deploymentRetention" for ' . static::class . '.'); + } + if (!array_key_exists('deploymentId', $data)) { + throw new \InvalidArgumentException('Missing required field "deploymentId" for ' . static::class . '.'); + } + if (!array_key_exists('deploymentCreatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "deploymentCreatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('latestDeploymentId', $data)) { + throw new \InvalidArgumentException('Missing required field "latestDeploymentId" for ' . static::class . '.'); + } + if (!array_key_exists('latestDeploymentCreatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "latestDeploymentCreatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('latestDeploymentStatus', $data)) { + throw new \InvalidArgumentException('Missing required field "latestDeploymentStatus" for ' . static::class . '.'); + } + if (!array_key_exists('scopes', $data)) { + throw new \InvalidArgumentException('Missing required field "scopes" for ' . static::class . '.'); + } + if (!array_key_exists('vars', $data)) { + throw new \InvalidArgumentException('Missing required field "vars" for ' . static::class . '.'); + } + if (!array_key_exists('events', $data)) { + throw new \InvalidArgumentException('Missing required field "events" for ' . static::class . '.'); + } + if (!array_key_exists('schedule', $data)) { + throw new \InvalidArgumentException('Missing required field "schedule" for ' . static::class . '.'); + } + if (!array_key_exists('timeout', $data)) { + throw new \InvalidArgumentException('Missing required field "timeout" for ' . static::class . '.'); + } + if (!array_key_exists('entrypoint', $data)) { + throw new \InvalidArgumentException('Missing required field "entrypoint" for ' . static::class . '.'); + } + if (!array_key_exists('commands', $data)) { + throw new \InvalidArgumentException('Missing required field "commands" for ' . static::class . '.'); + } + if (!array_key_exists('version', $data)) { + throw new \InvalidArgumentException('Missing required field "version" for ' . static::class . '.'); + } + if (!array_key_exists('installationId', $data)) { + throw new \InvalidArgumentException('Missing required field "installationId" for ' . static::class . '.'); + } + if (!array_key_exists('providerRepositoryId', $data)) { + throw new \InvalidArgumentException('Missing required field "providerRepositoryId" for ' . static::class . '.'); + } + if (!array_key_exists('providerBranch', $data)) { + throw new \InvalidArgumentException('Missing required field "providerBranch" for ' . static::class . '.'); + } + if (!array_key_exists('providerRootDirectory', $data)) { + throw new \InvalidArgumentException('Missing required field "providerRootDirectory" for ' . static::class . '.'); + } + if (!array_key_exists('providerSilentMode', $data)) { + throw new \InvalidArgumentException('Missing required field "providerSilentMode" for ' . static::class . '.'); + } + if (!array_key_exists('buildSpecification', $data)) { + throw new \InvalidArgumentException('Missing required field "buildSpecification" for ' . static::class . '.'); + } + if (!array_key_exists('runtimeSpecification', $data)) { + throw new \InvalidArgumentException('Missing required field "runtimeSpecification" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + execute: $data['execute'], + name: $data['name'], + enabled: $data['enabled'], + live: $data['live'], + logging: $data['logging'], + runtime: $data['runtime'], + deploymentRetention: $data['deploymentRetention'], + deploymentId: $data['deploymentId'], + deploymentCreatedAt: $data['deploymentCreatedAt'], + latestDeploymentId: $data['latestDeploymentId'], + latestDeploymentCreatedAt: $data['latestDeploymentCreatedAt'], + latestDeploymentStatus: $data['latestDeploymentStatus'], + scopes: $data['scopes'], + vars: is_array($data['vars']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Variable::class, $item), + $data['vars'] + ) + : $data['vars'], + events: $data['events'], + schedule: $data['schedule'], + timeout: $data['timeout'], + entrypoint: $data['entrypoint'], + commands: $data['commands'], + version: $data['version'], + installationId: $data['installationId'], + providerRepositoryId: $data['providerRepositoryId'], + providerBranch: $data['providerBranch'], + providerRootDirectory: $data['providerRootDirectory'], + providerSilentMode: $data['providerSilentMode'], + buildSpecification: $data['buildSpecification'], + runtimeSpecification: $data['runtimeSpecification'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'execute' => static::serializeValue($this->execute), + 'name' => static::serializeValue($this->name), + 'enabled' => static::serializeValue($this->enabled), + 'live' => static::serializeValue($this->live), + 'logging' => static::serializeValue($this->logging), + 'runtime' => static::serializeValue($this->runtime), + 'deploymentRetention' => static::serializeValue($this->deploymentRetention), + 'deploymentId' => static::serializeValue($this->deploymentId), + 'deploymentCreatedAt' => static::serializeValue($this->deploymentCreatedAt), + 'latestDeploymentId' => static::serializeValue($this->latestDeploymentId), + 'latestDeploymentCreatedAt' => static::serializeValue($this->latestDeploymentCreatedAt), + 'latestDeploymentStatus' => static::serializeValue($this->latestDeploymentStatus), + 'scopes' => static::serializeValue($this->scopes), + 'vars' => static::serializeValue($this->vars), + 'events' => static::serializeValue($this->events), + 'schedule' => static::serializeValue($this->schedule), + 'timeout' => static::serializeValue($this->timeout), + 'entrypoint' => static::serializeValue($this->entrypoint), + 'commands' => static::serializeValue($this->commands), + 'version' => static::serializeValue($this->version), + 'installationId' => static::serializeValue($this->installationId), + 'providerRepositoryId' => static::serializeValue($this->providerRepositoryId), + 'providerBranch' => static::serializeValue($this->providerBranch), + 'providerRootDirectory' => static::serializeValue($this->providerRootDirectory), + 'providerSilentMode' => static::serializeValue($this->providerSilentMode), + 'buildSpecification' => static::serializeValue($this->buildSpecification), + 'runtimeSpecification' => static::serializeValue($this->runtimeSpecification) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Headers.php b/src/Appwrite/Models/Headers.php index 323b7bc1..afd48cef 100644 --- a/src/Appwrite/Models/Headers.php +++ b/src/Appwrite/Models/Headers.php @@ -20,4 +20,35 @@ public function __construct( public string $value ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('value', $data)) { + throw new \InvalidArgumentException('Missing required field "value" for ' . static::class . '.'); + } + + return new static( + name: $data['name'], + value: $data['value'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'name' => static::serializeValue($this->name), + 'value' => static::serializeValue($this->value) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/HealthAntivirus.php b/src/Appwrite/Models/HealthAntivirus.php index 8e03510a..31a47bbd 100644 --- a/src/Appwrite/Models/HealthAntivirus.php +++ b/src/Appwrite/Models/HealthAntivirus.php @@ -22,4 +22,35 @@ public function __construct( public HealthAntivirusStatus $status ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('version', $data)) { + throw new \InvalidArgumentException('Missing required field "version" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + + return new static( + version: $data['version'], + status: static::hydrateTypedValue(HealthAntivirusStatus::class, $data['status']) + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'version' => static::serializeValue($this->version), + 'status' => static::serializeValue($this->status) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/HealthCertificate.php b/src/Appwrite/Models/HealthCertificate.php index 25d49aa3..bad516ff 100644 --- a/src/Appwrite/Models/HealthCertificate.php +++ b/src/Appwrite/Models/HealthCertificate.php @@ -28,4 +28,55 @@ public function __construct( public string $signatureTypeSN ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('subjectSN', $data)) { + throw new \InvalidArgumentException('Missing required field "subjectSN" for ' . static::class . '.'); + } + if (!array_key_exists('issuerOrganisation', $data)) { + throw new \InvalidArgumentException('Missing required field "issuerOrganisation" for ' . static::class . '.'); + } + if (!array_key_exists('validFrom', $data)) { + throw new \InvalidArgumentException('Missing required field "validFrom" for ' . static::class . '.'); + } + if (!array_key_exists('validTo', $data)) { + throw new \InvalidArgumentException('Missing required field "validTo" for ' . static::class . '.'); + } + if (!array_key_exists('signatureTypeSN', $data)) { + throw new \InvalidArgumentException('Missing required field "signatureTypeSN" for ' . static::class . '.'); + } + + return new static( + name: $data['name'], + subjectSN: $data['subjectSN'], + issuerOrganisation: $data['issuerOrganisation'], + validFrom: $data['validFrom'], + validTo: $data['validTo'], + signatureTypeSN: $data['signatureTypeSN'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'name' => static::serializeValue($this->name), + 'subjectSN' => static::serializeValue($this->subjectSN), + 'issuerOrganisation' => static::serializeValue($this->issuerOrganisation), + 'validFrom' => static::serializeValue($this->validFrom), + 'validTo' => static::serializeValue($this->validTo), + 'signatureTypeSN' => static::serializeValue($this->signatureTypeSN) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/HealthQueue.php b/src/Appwrite/Models/HealthQueue.php index eef71d7c..f709a229 100644 --- a/src/Appwrite/Models/HealthQueue.php +++ b/src/Appwrite/Models/HealthQueue.php @@ -18,4 +18,30 @@ public function __construct( public int $size ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('size', $data)) { + throw new \InvalidArgumentException('Missing required field "size" for ' . static::class . '.'); + } + + return new static( + size: $data['size'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'size' => static::serializeValue($this->size) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/HealthStatus.php b/src/Appwrite/Models/HealthStatus.php index d7305e5a..6238a2eb 100644 --- a/src/Appwrite/Models/HealthStatus.php +++ b/src/Appwrite/Models/HealthStatus.php @@ -24,4 +24,40 @@ public function __construct( public HealthCheckStatus $status ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('ping', $data)) { + throw new \InvalidArgumentException('Missing required field "ping" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + + return new static( + name: $data['name'], + ping: $data['ping'], + status: static::hydrateTypedValue(HealthCheckStatus::class, $data['status']) + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'name' => static::serializeValue($this->name), + 'ping' => static::serializeValue($this->ping), + 'status' => static::serializeValue($this->status) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/HealthStatusList.php b/src/Appwrite/Models/HealthStatusList.php index 652f2e02..4b13218d 100644 --- a/src/Appwrite/Models/HealthStatusList.php +++ b/src/Appwrite/Models/HealthStatusList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'statuses' => HealthStatus::class - ]; - /** * HealthStatusList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $statuses ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('statuses', $data)) { + throw new \InvalidArgumentException('Missing required field "statuses" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + statuses: is_array($data['statuses']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(HealthStatus::class, $item), + $data['statuses'] + ) + : $data['statuses'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'statuses' => static::serializeValue($this->statuses) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/HealthTime.php b/src/Appwrite/Models/HealthTime.php index 0cb511ae..c3036d1e 100644 --- a/src/Appwrite/Models/HealthTime.php +++ b/src/Appwrite/Models/HealthTime.php @@ -22,4 +22,40 @@ public function __construct( public int $diff ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('remoteTime', $data)) { + throw new \InvalidArgumentException('Missing required field "remoteTime" for ' . static::class . '.'); + } + if (!array_key_exists('localTime', $data)) { + throw new \InvalidArgumentException('Missing required field "localTime" for ' . static::class . '.'); + } + if (!array_key_exists('diff', $data)) { + throw new \InvalidArgumentException('Missing required field "diff" for ' . static::class . '.'); + } + + return new static( + remoteTime: $data['remoteTime'], + localTime: $data['localTime'], + diff: $data['diff'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'remoteTime' => static::serializeValue($this->remoteTime), + 'localTime' => static::serializeValue($this->localTime), + 'diff' => static::serializeValue($this->diff) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Identity.php b/src/Appwrite/Models/Identity.php index aeab1a90..16920c7e 100644 --- a/src/Appwrite/Models/Identity.php +++ b/src/Appwrite/Models/Identity.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Identity constructor. * @@ -45,4 +36,75 @@ public function __construct( public string $providerRefreshToken ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('userId', $data)) { + throw new \InvalidArgumentException('Missing required field "userId" for ' . static::class . '.'); + } + if (!array_key_exists('provider', $data)) { + throw new \InvalidArgumentException('Missing required field "provider" for ' . static::class . '.'); + } + if (!array_key_exists('providerUid', $data)) { + throw new \InvalidArgumentException('Missing required field "providerUid" for ' . static::class . '.'); + } + if (!array_key_exists('providerEmail', $data)) { + throw new \InvalidArgumentException('Missing required field "providerEmail" for ' . static::class . '.'); + } + if (!array_key_exists('providerAccessToken', $data)) { + throw new \InvalidArgumentException('Missing required field "providerAccessToken" for ' . static::class . '.'); + } + if (!array_key_exists('providerAccessTokenExpiry', $data)) { + throw new \InvalidArgumentException('Missing required field "providerAccessTokenExpiry" for ' . static::class . '.'); + } + if (!array_key_exists('providerRefreshToken', $data)) { + throw new \InvalidArgumentException('Missing required field "providerRefreshToken" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + userId: $data['userId'], + provider: $data['provider'], + providerUid: $data['providerUid'], + providerEmail: $data['providerEmail'], + providerAccessToken: $data['providerAccessToken'], + providerAccessTokenExpiry: $data['providerAccessTokenExpiry'], + providerRefreshToken: $data['providerRefreshToken'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'userId' => static::serializeValue($this->userId), + 'provider' => static::serializeValue($this->provider), + 'providerUid' => static::serializeValue($this->providerUid), + 'providerEmail' => static::serializeValue($this->providerEmail), + 'providerAccessToken' => static::serializeValue($this->providerAccessToken), + 'providerAccessTokenExpiry' => static::serializeValue($this->providerAccessTokenExpiry), + 'providerRefreshToken' => static::serializeValue($this->providerRefreshToken) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/IdentityList.php b/src/Appwrite/Models/IdentityList.php index 5855e4f9..dece9ec9 100644 --- a/src/Appwrite/Models/IdentityList.php +++ b/src/Appwrite/Models/IdentityList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'identities' => Identity::class - ]; - /** * IdentityList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $identities ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('identities', $data)) { + throw new \InvalidArgumentException('Missing required field "identities" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + identities: is_array($data['identities']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Identity::class, $item), + $data['identities'] + ) + : $data['identities'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'identities' => static::serializeValue($this->identities) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Index.php b/src/Appwrite/Models/Index.php index 4dcff6f8..39383747 100644 --- a/src/Appwrite/Models/Index.php +++ b/src/Appwrite/Models/Index.php @@ -11,15 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Index constructor. * @@ -47,4 +38,72 @@ public function __construct( public ?array $orders = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('error', $data)) { + throw new \InvalidArgumentException('Missing required field "error" for ' . static::class . '.'); + } + if (!array_key_exists('attributes', $data)) { + throw new \InvalidArgumentException('Missing required field "attributes" for ' . static::class . '.'); + } + if (!array_key_exists('lengths', $data)) { + throw new \InvalidArgumentException('Missing required field "lengths" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + key: $data['key'], + type: $data['type'], + status: static::hydrateTypedValue(IndexStatus::class, $data['status']), + error: $data['error'], + attributes: $data['attributes'], + lengths: $data['lengths'], + orders: array_key_exists('orders', $data) ? $data['orders'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'key' => static::serializeValue($this->key), + 'type' => static::serializeValue($this->type), + 'status' => static::serializeValue($this->status), + 'error' => static::serializeValue($this->error), + 'attributes' => static::serializeValue($this->attributes), + 'lengths' => static::serializeValue($this->lengths), + 'orders' => static::serializeValue($this->orders) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/IndexList.php b/src/Appwrite/Models/IndexList.php index c57f4f14..126f3b92 100644 --- a/src/Appwrite/Models/IndexList.php +++ b/src/Appwrite/Models/IndexList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'indexes' => Index::class - ]; - /** * IndexList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $indexes ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('indexes', $data)) { + throw new \InvalidArgumentException('Missing required field "indexes" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + indexes: is_array($data['indexes']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Index::class, $item), + $data['indexes'] + ) + : $data['indexes'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'indexes' => static::serializeValue($this->indexes) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Jwt.php b/src/Appwrite/Models/Jwt.php index 1aa624b5..80fcac52 100644 --- a/src/Appwrite/Models/Jwt.php +++ b/src/Appwrite/Models/Jwt.php @@ -18,4 +18,30 @@ public function __construct( public string $jwt ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('jwt', $data)) { + throw new \InvalidArgumentException('Missing required field "jwt" for ' . static::class . '.'); + } + + return new static( + jwt: $data['jwt'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'jwt' => static::serializeValue($this->jwt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Key.php b/src/Appwrite/Models/Key.php new file mode 100644 index 00000000..3f2802ea --- /dev/null +++ b/src/Appwrite/Models/Key.php @@ -0,0 +1,103 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('expire', $data)) { + throw new \InvalidArgumentException('Missing required field "expire" for ' . static::class . '.'); + } + if (!array_key_exists('scopes', $data)) { + throw new \InvalidArgumentException('Missing required field "scopes" for ' . static::class . '.'); + } + if (!array_key_exists('secret', $data)) { + throw new \InvalidArgumentException('Missing required field "secret" for ' . static::class . '.'); + } + if (!array_key_exists('accessedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "accessedAt" for ' . static::class . '.'); + } + if (!array_key_exists('sdks', $data)) { + throw new \InvalidArgumentException('Missing required field "sdks" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + expire: $data['expire'], + scopes: $data['scopes'], + secret: $data['secret'], + accessedAt: $data['accessedAt'], + sdks: $data['sdks'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'expire' => static::serializeValue($this->expire), + 'scopes' => static::serializeValue($this->scopes), + 'secret' => static::serializeValue($this->secret), + 'accessedAt' => static::serializeValue($this->accessedAt), + 'sdks' => static::serializeValue($this->sdks) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/KeyList.php b/src/Appwrite/Models/KeyList.php new file mode 100644 index 00000000..3c297404 --- /dev/null +++ b/src/Appwrite/Models/KeyList.php @@ -0,0 +1,59 @@ + $keys list of keys. + */ + public function __construct( + public int $total, + public array $keys + ) { + } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('keys', $data)) { + throw new \InvalidArgumentException('Missing required field "keys" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + keys: is_array($data['keys']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Key::class, $item), + $data['keys'] + ) + : $data['keys'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'keys' => static::serializeValue($this->keys) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/Language.php b/src/Appwrite/Models/Language.php index 39de049f..56ae4b3e 100644 --- a/src/Appwrite/Models/Language.php +++ b/src/Appwrite/Models/Language.php @@ -22,4 +22,40 @@ public function __construct( public string $nativeName ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException('Missing required field "code" for ' . static::class . '.'); + } + if (!array_key_exists('nativeName', $data)) { + throw new \InvalidArgumentException('Missing required field "nativeName" for ' . static::class . '.'); + } + + return new static( + name: $data['name'], + code: $data['code'], + nativeName: $data['nativeName'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'name' => static::serializeValue($this->name), + 'code' => static::serializeValue($this->code), + 'nativeName' => static::serializeValue($this->nativeName) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/LanguageList.php b/src/Appwrite/Models/LanguageList.php index 97b62245..3756bb22 100644 --- a/src/Appwrite/Models/LanguageList.php +++ b/src/Appwrite/Models/LanguageList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'languages' => Language::class - ]; - /** * LanguageList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $languages ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('languages', $data)) { + throw new \InvalidArgumentException('Missing required field "languages" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + languages: is_array($data['languages']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Language::class, $item), + $data['languages'] + ) + : $data['languages'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'languages' => static::serializeValue($this->languages) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Locale.php b/src/Appwrite/Models/Locale.php index 9ca5981e..183919af 100644 --- a/src/Appwrite/Models/Locale.php +++ b/src/Appwrite/Models/Locale.php @@ -30,4 +30,60 @@ public function __construct( public string $currency ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('ip', $data)) { + throw new \InvalidArgumentException('Missing required field "ip" for ' . static::class . '.'); + } + if (!array_key_exists('countryCode', $data)) { + throw new \InvalidArgumentException('Missing required field "countryCode" for ' . static::class . '.'); + } + if (!array_key_exists('country', $data)) { + throw new \InvalidArgumentException('Missing required field "country" for ' . static::class . '.'); + } + if (!array_key_exists('continentCode', $data)) { + throw new \InvalidArgumentException('Missing required field "continentCode" for ' . static::class . '.'); + } + if (!array_key_exists('continent', $data)) { + throw new \InvalidArgumentException('Missing required field "continent" for ' . static::class . '.'); + } + if (!array_key_exists('eu', $data)) { + throw new \InvalidArgumentException('Missing required field "eu" for ' . static::class . '.'); + } + if (!array_key_exists('currency', $data)) { + throw new \InvalidArgumentException('Missing required field "currency" for ' . static::class . '.'); + } + + return new static( + ip: $data['ip'], + countryCode: $data['countryCode'], + country: $data['country'], + continentCode: $data['continentCode'], + continent: $data['continent'], + eu: $data['eu'], + currency: $data['currency'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'ip' => static::serializeValue($this->ip), + 'countryCode' => static::serializeValue($this->countryCode), + 'country' => static::serializeValue($this->country), + 'continentCode' => static::serializeValue($this->continentCode), + 'continent' => static::serializeValue($this->continent), + 'eu' => static::serializeValue($this->eu), + 'currency' => static::serializeValue($this->currency) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/LocaleCode.php b/src/Appwrite/Models/LocaleCode.php index c29a3db7..6969516c 100644 --- a/src/Appwrite/Models/LocaleCode.php +++ b/src/Appwrite/Models/LocaleCode.php @@ -20,4 +20,35 @@ public function __construct( public string $name ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException('Missing required field "code" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + + return new static( + code: $data['code'], + name: $data['name'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'code' => static::serializeValue($this->code), + 'name' => static::serializeValue($this->name) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/LocaleCodeList.php b/src/Appwrite/Models/LocaleCodeList.php index 655e70f4..147f5180 100644 --- a/src/Appwrite/Models/LocaleCodeList.php +++ b/src/Appwrite/Models/LocaleCodeList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'localeCodes' => LocaleCode::class - ]; - /** * LocaleCodeList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $localeCodes ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('localeCodes', $data)) { + throw new \InvalidArgumentException('Missing required field "localeCodes" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + localeCodes: is_array($data['localeCodes']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(LocaleCode::class, $item), + $data['localeCodes'] + ) + : $data['localeCodes'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'localeCodes' => static::serializeValue($this->localeCodes) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Log.php b/src/Appwrite/Models/Log.php index bd6faf04..f3f74cee 100644 --- a/src/Appwrite/Models/Log.php +++ b/src/Appwrite/Models/Log.php @@ -17,6 +17,7 @@ * @param string $userEmail user email of the actor recorded for this log. during impersonation, this is the original impersonator. * @param string $userName user name of the actor recorded for this log. during impersonation, this is the original impersonator. * @param string $mode api mode when event triggered. + * @param string $userType user type who triggered the audit log. possible values: user, admin, guest, keyproject, keyaccount, keyorganization. * @param string $ip ip session in use when the session was created. * @param string $time log creation date in iso 8601 format. * @param string $osCode operating system code name. view list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). @@ -40,6 +41,7 @@ public function __construct( public string $userEmail, public string $userName, public string $mode, + public string $userType, public string $ip, public string $time, public string $osCode, @@ -58,4 +60,135 @@ public function __construct( public string $countryName ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('event', $data)) { + throw new \InvalidArgumentException('Missing required field "event" for ' . static::class . '.'); + } + if (!array_key_exists('userId', $data)) { + throw new \InvalidArgumentException('Missing required field "userId" for ' . static::class . '.'); + } + if (!array_key_exists('userEmail', $data)) { + throw new \InvalidArgumentException('Missing required field "userEmail" for ' . static::class . '.'); + } + if (!array_key_exists('userName', $data)) { + throw new \InvalidArgumentException('Missing required field "userName" for ' . static::class . '.'); + } + if (!array_key_exists('mode', $data)) { + throw new \InvalidArgumentException('Missing required field "mode" for ' . static::class . '.'); + } + if (!array_key_exists('userType', $data)) { + throw new \InvalidArgumentException('Missing required field "userType" for ' . static::class . '.'); + } + if (!array_key_exists('ip', $data)) { + throw new \InvalidArgumentException('Missing required field "ip" for ' . static::class . '.'); + } + if (!array_key_exists('time', $data)) { + throw new \InvalidArgumentException('Missing required field "time" for ' . static::class . '.'); + } + if (!array_key_exists('osCode', $data)) { + throw new \InvalidArgumentException('Missing required field "osCode" for ' . static::class . '.'); + } + if (!array_key_exists('osName', $data)) { + throw new \InvalidArgumentException('Missing required field "osName" for ' . static::class . '.'); + } + if (!array_key_exists('osVersion', $data)) { + throw new \InvalidArgumentException('Missing required field "osVersion" for ' . static::class . '.'); + } + if (!array_key_exists('clientType', $data)) { + throw new \InvalidArgumentException('Missing required field "clientType" for ' . static::class . '.'); + } + if (!array_key_exists('clientCode', $data)) { + throw new \InvalidArgumentException('Missing required field "clientCode" for ' . static::class . '.'); + } + if (!array_key_exists('clientName', $data)) { + throw new \InvalidArgumentException('Missing required field "clientName" for ' . static::class . '.'); + } + if (!array_key_exists('clientVersion', $data)) { + throw new \InvalidArgumentException('Missing required field "clientVersion" for ' . static::class . '.'); + } + if (!array_key_exists('clientEngine', $data)) { + throw new \InvalidArgumentException('Missing required field "clientEngine" for ' . static::class . '.'); + } + if (!array_key_exists('clientEngineVersion', $data)) { + throw new \InvalidArgumentException('Missing required field "clientEngineVersion" for ' . static::class . '.'); + } + if (!array_key_exists('deviceName', $data)) { + throw new \InvalidArgumentException('Missing required field "deviceName" for ' . static::class . '.'); + } + if (!array_key_exists('deviceBrand', $data)) { + throw new \InvalidArgumentException('Missing required field "deviceBrand" for ' . static::class . '.'); + } + if (!array_key_exists('deviceModel', $data)) { + throw new \InvalidArgumentException('Missing required field "deviceModel" for ' . static::class . '.'); + } + if (!array_key_exists('countryCode', $data)) { + throw new \InvalidArgumentException('Missing required field "countryCode" for ' . static::class . '.'); + } + if (!array_key_exists('countryName', $data)) { + throw new \InvalidArgumentException('Missing required field "countryName" for ' . static::class . '.'); + } + + return new static( + event: $data['event'], + userId: $data['userId'], + userEmail: $data['userEmail'], + userName: $data['userName'], + mode: $data['mode'], + userType: $data['userType'], + ip: $data['ip'], + time: $data['time'], + osCode: $data['osCode'], + osName: $data['osName'], + osVersion: $data['osVersion'], + clientType: $data['clientType'], + clientCode: $data['clientCode'], + clientName: $data['clientName'], + clientVersion: $data['clientVersion'], + clientEngine: $data['clientEngine'], + clientEngineVersion: $data['clientEngineVersion'], + deviceName: $data['deviceName'], + deviceBrand: $data['deviceBrand'], + deviceModel: $data['deviceModel'], + countryCode: $data['countryCode'], + countryName: $data['countryName'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'event' => static::serializeValue($this->event), + 'userId' => static::serializeValue($this->userId), + 'userEmail' => static::serializeValue($this->userEmail), + 'userName' => static::serializeValue($this->userName), + 'mode' => static::serializeValue($this->mode), + 'userType' => static::serializeValue($this->userType), + 'ip' => static::serializeValue($this->ip), + 'time' => static::serializeValue($this->time), + 'osCode' => static::serializeValue($this->osCode), + 'osName' => static::serializeValue($this->osName), + 'osVersion' => static::serializeValue($this->osVersion), + 'clientType' => static::serializeValue($this->clientType), + 'clientCode' => static::serializeValue($this->clientCode), + 'clientName' => static::serializeValue($this->clientName), + 'clientVersion' => static::serializeValue($this->clientVersion), + 'clientEngine' => static::serializeValue($this->clientEngine), + 'clientEngineVersion' => static::serializeValue($this->clientEngineVersion), + 'deviceName' => static::serializeValue($this->deviceName), + 'deviceBrand' => static::serializeValue($this->deviceBrand), + 'deviceModel' => static::serializeValue($this->deviceModel), + 'countryCode' => static::serializeValue($this->countryCode), + 'countryName' => static::serializeValue($this->countryName) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/LogList.php b/src/Appwrite/Models/LogList.php index 0ad04d73..16291a55 100644 --- a/src/Appwrite/Models/LogList.php +++ b/src/Appwrite/Models/LogList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'logs' => Log::class - ]; - /** * LogList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $logs ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('logs', $data)) { + throw new \InvalidArgumentException('Missing required field "logs" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + logs: is_array($data['logs']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Log::class, $item), + $data['logs'] + ) + : $data['logs'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'logs' => static::serializeValue($this->logs) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Membership.php b/src/Appwrite/Models/Membership.php index 0f460ee7..e7264c28 100644 --- a/src/Appwrite/Models/Membership.php +++ b/src/Appwrite/Models/Membership.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Membership constructor. * @@ -51,4 +42,90 @@ public function __construct( public array $roles ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('userId', $data)) { + throw new \InvalidArgumentException('Missing required field "userId" for ' . static::class . '.'); + } + if (!array_key_exists('userName', $data)) { + throw new \InvalidArgumentException('Missing required field "userName" for ' . static::class . '.'); + } + if (!array_key_exists('userEmail', $data)) { + throw new \InvalidArgumentException('Missing required field "userEmail" for ' . static::class . '.'); + } + if (!array_key_exists('teamId', $data)) { + throw new \InvalidArgumentException('Missing required field "teamId" for ' . static::class . '.'); + } + if (!array_key_exists('teamName', $data)) { + throw new \InvalidArgumentException('Missing required field "teamName" for ' . static::class . '.'); + } + if (!array_key_exists('invited', $data)) { + throw new \InvalidArgumentException('Missing required field "invited" for ' . static::class . '.'); + } + if (!array_key_exists('joined', $data)) { + throw new \InvalidArgumentException('Missing required field "joined" for ' . static::class . '.'); + } + if (!array_key_exists('confirm', $data)) { + throw new \InvalidArgumentException('Missing required field "confirm" for ' . static::class . '.'); + } + if (!array_key_exists('mfa', $data)) { + throw new \InvalidArgumentException('Missing required field "mfa" for ' . static::class . '.'); + } + if (!array_key_exists('roles', $data)) { + throw new \InvalidArgumentException('Missing required field "roles" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + userId: $data['userId'], + userName: $data['userName'], + userEmail: $data['userEmail'], + teamId: $data['teamId'], + teamName: $data['teamName'], + invited: $data['invited'], + joined: $data['joined'], + confirm: $data['confirm'], + mfa: $data['mfa'], + roles: $data['roles'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'userId' => static::serializeValue($this->userId), + 'userName' => static::serializeValue($this->userName), + 'userEmail' => static::serializeValue($this->userEmail), + 'teamId' => static::serializeValue($this->teamId), + 'teamName' => static::serializeValue($this->teamName), + 'invited' => static::serializeValue($this->invited), + 'joined' => static::serializeValue($this->joined), + 'confirm' => static::serializeValue($this->confirm), + 'mfa' => static::serializeValue($this->mfa), + 'roles' => static::serializeValue($this->roles) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/MembershipList.php b/src/Appwrite/Models/MembershipList.php index 10371556..eb747649 100644 --- a/src/Appwrite/Models/MembershipList.php +++ b/src/Appwrite/Models/MembershipList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'memberships' => Membership::class - ]; - /** * MembershipList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $memberships ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('memberships', $data)) { + throw new \InvalidArgumentException('Missing required field "memberships" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + memberships: is_array($data['memberships']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Membership::class, $item), + $data['memberships'] + ) + : $data['memberships'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'memberships' => static::serializeValue($this->memberships) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Message.php b/src/Appwrite/Models/Message.php index f9233ae2..fd11026e 100644 --- a/src/Appwrite/Models/Message.php +++ b/src/Appwrite/Models/Message.php @@ -11,15 +11,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Message constructor. * @@ -53,4 +44,81 @@ public function __construct( public ?array $deliveryErrors = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('providerType', $data)) { + throw new \InvalidArgumentException('Missing required field "providerType" for ' . static::class . '.'); + } + if (!array_key_exists('topics', $data)) { + throw new \InvalidArgumentException('Missing required field "topics" for ' . static::class . '.'); + } + if (!array_key_exists('users', $data)) { + throw new \InvalidArgumentException('Missing required field "users" for ' . static::class . '.'); + } + if (!array_key_exists('targets', $data)) { + throw new \InvalidArgumentException('Missing required field "targets" for ' . static::class . '.'); + } + if (!array_key_exists('deliveredTotal', $data)) { + throw new \InvalidArgumentException('Missing required field "deliveredTotal" for ' . static::class . '.'); + } + if (!array_key_exists('data', $data)) { + throw new \InvalidArgumentException('Missing required field "data" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + providerType: $data['providerType'], + topics: $data['topics'], + users: $data['users'], + targets: $data['targets'], + deliveredTotal: $data['deliveredTotal'], + data: $data['data'], + status: static::hydrateTypedValue(MessageStatus::class, $data['status']), + scheduledAt: array_key_exists('scheduledAt', $data) ? $data['scheduledAt'] : null, + deliveredAt: array_key_exists('deliveredAt', $data) ? $data['deliveredAt'] : null, + deliveryErrors: array_key_exists('deliveryErrors', $data) ? $data['deliveryErrors'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'providerType' => static::serializeValue($this->providerType), + 'topics' => static::serializeValue($this->topics), + 'users' => static::serializeValue($this->users), + 'targets' => static::serializeValue($this->targets), + 'scheduledAt' => static::serializeValue($this->scheduledAt), + 'deliveredAt' => static::serializeValue($this->deliveredAt), + 'deliveryErrors' => static::serializeValue($this->deliveryErrors), + 'deliveredTotal' => static::serializeValue($this->deliveredTotal), + 'data' => static::serializeValue($this->data), + 'status' => static::serializeValue($this->status) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/MessageList.php b/src/Appwrite/Models/MessageList.php index f583a876..acc5788e 100644 --- a/src/Appwrite/Models/MessageList.php +++ b/src/Appwrite/Models/MessageList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'messages' => Message::class - ]; - /** * MessageList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $messages ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('messages', $data)) { + throw new \InvalidArgumentException('Missing required field "messages" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + messages: is_array($data['messages']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Message::class, $item), + $data['messages'] + ) + : $data['messages'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'messages' => static::serializeValue($this->messages) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/MfaChallenge.php b/src/Appwrite/Models/MfaChallenge.php index 26d8f64d..695d72dc 100644 --- a/src/Appwrite/Models/MfaChallenge.php +++ b/src/Appwrite/Models/MfaChallenge.php @@ -9,14 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt' - ]; - /** * MfaChallenge constructor. * @@ -32,4 +24,45 @@ public function __construct( public string $expire ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('userId', $data)) { + throw new \InvalidArgumentException('Missing required field "userId" for ' . static::class . '.'); + } + if (!array_key_exists('expire', $data)) { + throw new \InvalidArgumentException('Missing required field "expire" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + userId: $data['userId'], + expire: $data['expire'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + 'userId' => static::serializeValue($this->userId), + 'expire' => static::serializeValue($this->expire) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/MfaFactors.php b/src/Appwrite/Models/MfaFactors.php index 7f54889f..bdfd41a7 100644 --- a/src/Appwrite/Models/MfaFactors.php +++ b/src/Appwrite/Models/MfaFactors.php @@ -24,4 +24,45 @@ public function __construct( public bool $recoveryCode ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('totp', $data)) { + throw new \InvalidArgumentException('Missing required field "totp" for ' . static::class . '.'); + } + if (!array_key_exists('phone', $data)) { + throw new \InvalidArgumentException('Missing required field "phone" for ' . static::class . '.'); + } + if (!array_key_exists('email', $data)) { + throw new \InvalidArgumentException('Missing required field "email" for ' . static::class . '.'); + } + if (!array_key_exists('recoveryCode', $data)) { + throw new \InvalidArgumentException('Missing required field "recoveryCode" for ' . static::class . '.'); + } + + return new static( + totp: $data['totp'], + phone: $data['phone'], + email: $data['email'], + recoveryCode: $data['recoveryCode'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'totp' => static::serializeValue($this->totp), + 'phone' => static::serializeValue($this->phone), + 'email' => static::serializeValue($this->email), + 'recoveryCode' => static::serializeValue($this->recoveryCode) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/MfaRecoveryCodes.php b/src/Appwrite/Models/MfaRecoveryCodes.php index bdcb6214..c63cfb5b 100644 --- a/src/Appwrite/Models/MfaRecoveryCodes.php +++ b/src/Appwrite/Models/MfaRecoveryCodes.php @@ -18,4 +18,30 @@ public function __construct( public array $recoveryCodes ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('recoveryCodes', $data)) { + throw new \InvalidArgumentException('Missing required field "recoveryCodes" for ' . static::class . '.'); + } + + return new static( + recoveryCodes: $data['recoveryCodes'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'recoveryCodes' => static::serializeValue($this->recoveryCodes) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/MfaType.php b/src/Appwrite/Models/MfaType.php index 40b34c9a..051c9c32 100644 --- a/src/Appwrite/Models/MfaType.php +++ b/src/Appwrite/Models/MfaType.php @@ -20,4 +20,35 @@ public function __construct( public string $uri ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('secret', $data)) { + throw new \InvalidArgumentException('Missing required field "secret" for ' . static::class . '.'); + } + if (!array_key_exists('uri', $data)) { + throw new \InvalidArgumentException('Missing required field "uri" for ' . static::class . '.'); + } + + return new static( + secret: $data['secret'], + uri: $data['uri'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'secret' => static::serializeValue($this->secret), + 'uri' => static::serializeValue($this->uri) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/MockNumber.php b/src/Appwrite/Models/MockNumber.php new file mode 100644 index 00000000..64f341b3 --- /dev/null +++ b/src/Appwrite/Models/MockNumber.php @@ -0,0 +1,54 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('phone', $data)) { + throw new \InvalidArgumentException('Missing required field "phone" for ' . static::class . '.'); + } + if (!array_key_exists('otp', $data)) { + throw new \InvalidArgumentException('Missing required field "otp" for ' . static::class . '.'); + } + + return new static( + phone: $data['phone'], + otp: $data['otp'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'phone' => static::serializeValue($this->phone), + 'otp' => static::serializeValue($this->otp) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/Phone.php b/src/Appwrite/Models/Phone.php index 97c98d2a..f8c56c24 100644 --- a/src/Appwrite/Models/Phone.php +++ b/src/Appwrite/Models/Phone.php @@ -22,4 +22,40 @@ public function __construct( public string $countryName ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException('Missing required field "code" for ' . static::class . '.'); + } + if (!array_key_exists('countryCode', $data)) { + throw new \InvalidArgumentException('Missing required field "countryCode" for ' . static::class . '.'); + } + if (!array_key_exists('countryName', $data)) { + throw new \InvalidArgumentException('Missing required field "countryName" for ' . static::class . '.'); + } + + return new static( + code: $data['code'], + countryCode: $data['countryCode'], + countryName: $data['countryName'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'code' => static::serializeValue($this->code), + 'countryCode' => static::serializeValue($this->countryCode), + 'countryName' => static::serializeValue($this->countryName) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/PhoneList.php b/src/Appwrite/Models/PhoneList.php index f0bda4fa..afa2e30e 100644 --- a/src/Appwrite/Models/PhoneList.php +++ b/src/Appwrite/Models/PhoneList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'phones' => Phone::class - ]; - /** * PhoneList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $phones ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('phones', $data)) { + throw new \InvalidArgumentException('Missing required field "phones" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + phones: is_array($data['phones']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Phone::class, $item), + $data['phones'] + ) + : $data['phones'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'phones' => static::serializeValue($this->phones) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/PlatformAndroid.php b/src/Appwrite/Models/PlatformAndroid.php new file mode 100644 index 00000000..3994c7ca --- /dev/null +++ b/src/Appwrite/Models/PlatformAndroid.php @@ -0,0 +1,84 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('applicationId', $data)) { + throw new \InvalidArgumentException('Missing required field "applicationId" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + type: static::hydrateTypedValue(PlatformType::class, $data['type']), + applicationId: $data['applicationId'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'type' => static::serializeValue($this->type), + 'applicationId' => static::serializeValue($this->applicationId) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/PlatformApple.php b/src/Appwrite/Models/PlatformApple.php new file mode 100644 index 00000000..5919d10d --- /dev/null +++ b/src/Appwrite/Models/PlatformApple.php @@ -0,0 +1,84 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('bundleIdentifier', $data)) { + throw new \InvalidArgumentException('Missing required field "bundleIdentifier" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + type: static::hydrateTypedValue(PlatformType::class, $data['type']), + bundleIdentifier: $data['bundleIdentifier'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'type' => static::serializeValue($this->type), + 'bundleIdentifier' => static::serializeValue($this->bundleIdentifier) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/PlatformLinux.php b/src/Appwrite/Models/PlatformLinux.php new file mode 100644 index 00000000..5a456a12 --- /dev/null +++ b/src/Appwrite/Models/PlatformLinux.php @@ -0,0 +1,84 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('packageName', $data)) { + throw new \InvalidArgumentException('Missing required field "packageName" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + type: static::hydrateTypedValue(PlatformType::class, $data['type']), + packageName: $data['packageName'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'type' => static::serializeValue($this->type), + 'packageName' => static::serializeValue($this->packageName) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/PlatformList.php b/src/Appwrite/Models/PlatformList.php new file mode 100644 index 00000000..cd6653f0 --- /dev/null +++ b/src/Appwrite/Models/PlatformList.php @@ -0,0 +1,54 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('platforms', $data)) { + throw new \InvalidArgumentException('Missing required field "platforms" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + platforms: $data['platforms'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'platforms' => static::serializeValue($this->platforms) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/PlatformWeb.php b/src/Appwrite/Models/PlatformWeb.php new file mode 100644 index 00000000..f21bf514 --- /dev/null +++ b/src/Appwrite/Models/PlatformWeb.php @@ -0,0 +1,84 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('hostname', $data)) { + throw new \InvalidArgumentException('Missing required field "hostname" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + type: static::hydrateTypedValue(PlatformType::class, $data['type']), + hostname: $data['hostname'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'type' => static::serializeValue($this->type), + 'hostname' => static::serializeValue($this->hostname) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/PlatformWindows.php b/src/Appwrite/Models/PlatformWindows.php new file mode 100644 index 00000000..3e5ec245 --- /dev/null +++ b/src/Appwrite/Models/PlatformWindows.php @@ -0,0 +1,84 @@ + $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('packageIdentifierName', $data)) { + throw new \InvalidArgumentException('Missing required field "packageIdentifierName" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + type: static::hydrateTypedValue(PlatformType::class, $data['type']), + packageIdentifierName: $data['packageIdentifierName'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'type' => static::serializeValue($this->type), + 'packageIdentifierName' => static::serializeValue($this->packageIdentifierName) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/Preferences.php b/src/Appwrite/Models/Preferences.php index 9b8abe4f..f52607cf 100644 --- a/src/Appwrite/Models/Preferences.php +++ b/src/Appwrite/Models/Preferences.php @@ -20,4 +20,36 @@ public function __construct( public array $data = [] ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + + $additionalProperties = static::extractAdditionalPropertiesFromFields( + $data, + [ + ] + ); + + return new static( + data: $additionalProperties + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + ]; + + foreach (static::serializeAdditionalProperties($this->data) as $field => $value) { + $result[$field] = $value; + } + + return $result; + } } diff --git a/src/Appwrite/Models/Project.php b/src/Appwrite/Models/Project.php new file mode 100644 index 00000000..dea878a4 --- /dev/null +++ b/src/Appwrite/Models/Project.php @@ -0,0 +1,616 @@ + $authMockNumbers an array of mock numbers and their corresponding verification codes (otps). + * @param bool $authSessionAlerts whether or not to send session alert emails to users. + * @param bool $authMembershipsUserName whether or not to show user names in the teams membership response. + * @param bool $authMembershipsUserEmail whether or not to show user emails in the teams membership response. + * @param bool $authMembershipsMfa whether or not to show user mfa status in the teams membership response. + * @param bool $authInvalidateSessions whether or not all existing sessions should be invalidated on password change + * @param list $oAuthProviders list of auth providers. + * @param array $platforms list of platforms. + * @param list $webhooks list of webhooks. + * @param list $keys list of api keys. + * @param list $devKeys list of dev keys. + * @param bool $smtpEnabled status for custom smtp + * @param string $smtpSenderName smtp sender name + * @param string $smtpSenderEmail smtp sender email + * @param string $smtpReplyTo smtp reply to email + * @param string $smtpHost smtp server host name + * @param int $smtpPort smtp server port + * @param string $smtpUsername smtp server username + * @param string $smtpPassword smtp server password + * @param string $smtpSecure smtp server secure protocol + * @param int $pingCount number of times the ping was received for this project. + * @param string $pingedAt last ping datetime in iso 8601 format. + * @param array $labels labels for the project. + * @param string $status project status + * @param bool $authEmailPassword email/password auth method status + * @param bool $authUsersAuthMagicURL magic url auth method status + * @param bool $authEmailOtp email (otp) auth method status + * @param bool $authAnonymous anonymous auth method status + * @param bool $authInvites invites auth method status + * @param bool $authJWT jwt auth method status + * @param bool $authPhone phone auth method status + * @param bool $serviceStatusForAccount account service status + * @param bool $serviceStatusForAvatars avatars service status + * @param bool $serviceStatusForDatabases databases (legacy) service status + * @param bool $serviceStatusForTablesdb tablesdb service status + * @param bool $serviceStatusForLocale locale service status + * @param bool $serviceStatusForHealth health service status + * @param bool $serviceStatusForProject project service status + * @param bool $serviceStatusForStorage storage service status + * @param bool $serviceStatusForTeams teams service status + * @param bool $serviceStatusForUsers users service status + * @param bool $serviceStatusForVcs vcs service status + * @param bool $serviceStatusForSites sites service status + * @param bool $serviceStatusForFunctions functions service status + * @param bool $serviceStatusForProxy proxy service status + * @param bool $serviceStatusForGraphql graphql service status + * @param bool $serviceStatusForMigrations migrations service status + * @param bool $serviceStatusForMessaging messaging service status + * @param bool $protocolStatusForRest rest protocol status + * @param bool $protocolStatusForGraphql graphql protocol status + * @param bool $protocolStatusForWebsocket websocket protocol status + * @param string $region project region + * @param BillingLimits $billingLimits billing limits reached + * @param list $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. + */ + public function __construct( + public string $id, + public string $createdAt, + public string $updatedAt, + public string $name, + public string $description, + public string $teamId, + public string $logo, + public string $url, + public string $legalName, + public string $legalCountry, + public string $legalState, + public string $legalCity, + public string $legalAddress, + public string $legalTaxId, + public int $authDuration, + public int $authLimit, + public int $authSessionsLimit, + public int $authPasswordHistory, + public bool $authPasswordDictionary, + public bool $authPersonalDataCheck, + public bool $authDisposableEmails, + public bool $authCanonicalEmails, + public bool $authFreeEmails, + public array $authMockNumbers, + public bool $authSessionAlerts, + public bool $authMembershipsUserName, + public bool $authMembershipsUserEmail, + public bool $authMembershipsMfa, + public bool $authInvalidateSessions, + public array $oAuthProviders, + public array $platforms, + public array $webhooks, + public array $keys, + public array $devKeys, + public bool $smtpEnabled, + public string $smtpSenderName, + public string $smtpSenderEmail, + public string $smtpReplyTo, + public string $smtpHost, + public int $smtpPort, + public string $smtpUsername, + public string $smtpPassword, + public string $smtpSecure, + public int $pingCount, + public string $pingedAt, + public array $labels, + public string $status, + public bool $authEmailPassword, + public bool $authUsersAuthMagicURL, + public bool $authEmailOtp, + public bool $authAnonymous, + public bool $authInvites, + public bool $authJWT, + public bool $authPhone, + public bool $serviceStatusForAccount, + public bool $serviceStatusForAvatars, + public bool $serviceStatusForDatabases, + public bool $serviceStatusForTablesdb, + public bool $serviceStatusForLocale, + public bool $serviceStatusForHealth, + public bool $serviceStatusForProject, + public bool $serviceStatusForStorage, + public bool $serviceStatusForTeams, + public bool $serviceStatusForUsers, + public bool $serviceStatusForVcs, + public bool $serviceStatusForSites, + public bool $serviceStatusForFunctions, + public bool $serviceStatusForProxy, + public bool $serviceStatusForGraphql, + public bool $serviceStatusForMigrations, + public bool $serviceStatusForMessaging, + public bool $protocolStatusForRest, + public bool $protocolStatusForGraphql, + public bool $protocolStatusForWebsocket, + public string $region, + public BillingLimits $billingLimits, + public array $blocks, + public string $consoleAccessedAt + ) { + } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('description', $data)) { + throw new \InvalidArgumentException('Missing required field "description" for ' . static::class . '.'); + } + if (!array_key_exists('teamId', $data)) { + throw new \InvalidArgumentException('Missing required field "teamId" for ' . static::class . '.'); + } + if (!array_key_exists('logo', $data)) { + throw new \InvalidArgumentException('Missing required field "logo" for ' . static::class . '.'); + } + if (!array_key_exists('url', $data)) { + throw new \InvalidArgumentException('Missing required field "url" for ' . static::class . '.'); + } + if (!array_key_exists('legalName', $data)) { + throw new \InvalidArgumentException('Missing required field "legalName" for ' . static::class . '.'); + } + if (!array_key_exists('legalCountry', $data)) { + throw new \InvalidArgumentException('Missing required field "legalCountry" for ' . static::class . '.'); + } + if (!array_key_exists('legalState', $data)) { + throw new \InvalidArgumentException('Missing required field "legalState" for ' . static::class . '.'); + } + if (!array_key_exists('legalCity', $data)) { + throw new \InvalidArgumentException('Missing required field "legalCity" for ' . static::class . '.'); + } + if (!array_key_exists('legalAddress', $data)) { + throw new \InvalidArgumentException('Missing required field "legalAddress" for ' . static::class . '.'); + } + if (!array_key_exists('legalTaxId', $data)) { + throw new \InvalidArgumentException('Missing required field "legalTaxId" for ' . static::class . '.'); + } + if (!array_key_exists('authDuration', $data)) { + throw new \InvalidArgumentException('Missing required field "authDuration" for ' . static::class . '.'); + } + if (!array_key_exists('authLimit', $data)) { + throw new \InvalidArgumentException('Missing required field "authLimit" for ' . static::class . '.'); + } + if (!array_key_exists('authSessionsLimit', $data)) { + throw new \InvalidArgumentException('Missing required field "authSessionsLimit" for ' . static::class . '.'); + } + if (!array_key_exists('authPasswordHistory', $data)) { + throw new \InvalidArgumentException('Missing required field "authPasswordHistory" for ' . static::class . '.'); + } + if (!array_key_exists('authPasswordDictionary', $data)) { + throw new \InvalidArgumentException('Missing required field "authPasswordDictionary" for ' . static::class . '.'); + } + if (!array_key_exists('authPersonalDataCheck', $data)) { + throw new \InvalidArgumentException('Missing required field "authPersonalDataCheck" for ' . static::class . '.'); + } + if (!array_key_exists('authDisposableEmails', $data)) { + throw new \InvalidArgumentException('Missing required field "authDisposableEmails" for ' . static::class . '.'); + } + if (!array_key_exists('authCanonicalEmails', $data)) { + throw new \InvalidArgumentException('Missing required field "authCanonicalEmails" for ' . static::class . '.'); + } + if (!array_key_exists('authFreeEmails', $data)) { + throw new \InvalidArgumentException('Missing required field "authFreeEmails" for ' . static::class . '.'); + } + if (!array_key_exists('authMockNumbers', $data)) { + throw new \InvalidArgumentException('Missing required field "authMockNumbers" for ' . static::class . '.'); + } + if (!array_key_exists('authSessionAlerts', $data)) { + throw new \InvalidArgumentException('Missing required field "authSessionAlerts" for ' . static::class . '.'); + } + if (!array_key_exists('authMembershipsUserName', $data)) { + throw new \InvalidArgumentException('Missing required field "authMembershipsUserName" for ' . static::class . '.'); + } + if (!array_key_exists('authMembershipsUserEmail', $data)) { + throw new \InvalidArgumentException('Missing required field "authMembershipsUserEmail" for ' . static::class . '.'); + } + if (!array_key_exists('authMembershipsMfa', $data)) { + throw new \InvalidArgumentException('Missing required field "authMembershipsMfa" for ' . static::class . '.'); + } + if (!array_key_exists('authInvalidateSessions', $data)) { + throw new \InvalidArgumentException('Missing required field "authInvalidateSessions" for ' . static::class . '.'); + } + if (!array_key_exists('oAuthProviders', $data)) { + throw new \InvalidArgumentException('Missing required field "oAuthProviders" for ' . static::class . '.'); + } + if (!array_key_exists('platforms', $data)) { + throw new \InvalidArgumentException('Missing required field "platforms" for ' . static::class . '.'); + } + if (!array_key_exists('webhooks', $data)) { + throw new \InvalidArgumentException('Missing required field "webhooks" for ' . static::class . '.'); + } + if (!array_key_exists('keys', $data)) { + throw new \InvalidArgumentException('Missing required field "keys" for ' . static::class . '.'); + } + if (!array_key_exists('devKeys', $data)) { + throw new \InvalidArgumentException('Missing required field "devKeys" for ' . static::class . '.'); + } + if (!array_key_exists('smtpEnabled', $data)) { + throw new \InvalidArgumentException('Missing required field "smtpEnabled" for ' . static::class . '.'); + } + if (!array_key_exists('smtpSenderName', $data)) { + throw new \InvalidArgumentException('Missing required field "smtpSenderName" for ' . static::class . '.'); + } + if (!array_key_exists('smtpSenderEmail', $data)) { + throw new \InvalidArgumentException('Missing required field "smtpSenderEmail" for ' . static::class . '.'); + } + if (!array_key_exists('smtpReplyTo', $data)) { + throw new \InvalidArgumentException('Missing required field "smtpReplyTo" for ' . static::class . '.'); + } + if (!array_key_exists('smtpHost', $data)) { + throw new \InvalidArgumentException('Missing required field "smtpHost" for ' . static::class . '.'); + } + if (!array_key_exists('smtpPort', $data)) { + throw new \InvalidArgumentException('Missing required field "smtpPort" for ' . static::class . '.'); + } + if (!array_key_exists('smtpUsername', $data)) { + throw new \InvalidArgumentException('Missing required field "smtpUsername" for ' . static::class . '.'); + } + if (!array_key_exists('smtpPassword', $data)) { + throw new \InvalidArgumentException('Missing required field "smtpPassword" for ' . static::class . '.'); + } + if (!array_key_exists('smtpSecure', $data)) { + throw new \InvalidArgumentException('Missing required field "smtpSecure" for ' . static::class . '.'); + } + if (!array_key_exists('pingCount', $data)) { + throw new \InvalidArgumentException('Missing required field "pingCount" for ' . static::class . '.'); + } + if (!array_key_exists('pingedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "pingedAt" for ' . static::class . '.'); + } + if (!array_key_exists('labels', $data)) { + throw new \InvalidArgumentException('Missing required field "labels" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('authEmailPassword', $data)) { + throw new \InvalidArgumentException('Missing required field "authEmailPassword" for ' . static::class . '.'); + } + if (!array_key_exists('authUsersAuthMagicURL', $data)) { + throw new \InvalidArgumentException('Missing required field "authUsersAuthMagicURL" for ' . static::class . '.'); + } + if (!array_key_exists('authEmailOtp', $data)) { + throw new \InvalidArgumentException('Missing required field "authEmailOtp" for ' . static::class . '.'); + } + if (!array_key_exists('authAnonymous', $data)) { + throw new \InvalidArgumentException('Missing required field "authAnonymous" for ' . static::class . '.'); + } + if (!array_key_exists('authInvites', $data)) { + throw new \InvalidArgumentException('Missing required field "authInvites" for ' . static::class . '.'); + } + if (!array_key_exists('authJWT', $data)) { + throw new \InvalidArgumentException('Missing required field "authJWT" for ' . static::class . '.'); + } + if (!array_key_exists('authPhone', $data)) { + throw new \InvalidArgumentException('Missing required field "authPhone" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForAccount', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForAccount" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForAvatars', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForAvatars" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForDatabases', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForDatabases" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForTablesdb', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForTablesdb" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForLocale', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForLocale" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForHealth', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForHealth" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForProject', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForProject" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForStorage', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForStorage" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForTeams', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForTeams" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForUsers', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForUsers" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForVcs', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForVcs" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForSites', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForSites" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForFunctions', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForFunctions" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForProxy', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForProxy" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForGraphql', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForGraphql" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForMigrations', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForMigrations" for ' . static::class . '.'); + } + if (!array_key_exists('serviceStatusForMessaging', $data)) { + throw new \InvalidArgumentException('Missing required field "serviceStatusForMessaging" for ' . static::class . '.'); + } + if (!array_key_exists('protocolStatusForRest', $data)) { + throw new \InvalidArgumentException('Missing required field "protocolStatusForRest" for ' . static::class . '.'); + } + if (!array_key_exists('protocolStatusForGraphql', $data)) { + throw new \InvalidArgumentException('Missing required field "protocolStatusForGraphql" for ' . static::class . '.'); + } + if (!array_key_exists('protocolStatusForWebsocket', $data)) { + throw new \InvalidArgumentException('Missing required field "protocolStatusForWebsocket" for ' . static::class . '.'); + } + if (!array_key_exists('region', $data)) { + throw new \InvalidArgumentException('Missing required field "region" for ' . static::class . '.'); + } + if (!array_key_exists('billingLimits', $data)) { + throw new \InvalidArgumentException('Missing required field "billingLimits" for ' . static::class . '.'); + } + if (!array_key_exists('blocks', $data)) { + throw new \InvalidArgumentException('Missing required field "blocks" for ' . static::class . '.'); + } + if (!array_key_exists('consoleAccessedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "consoleAccessedAt" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + description: $data['description'], + teamId: $data['teamId'], + logo: $data['logo'], + url: $data['url'], + legalName: $data['legalName'], + legalCountry: $data['legalCountry'], + legalState: $data['legalState'], + legalCity: $data['legalCity'], + legalAddress: $data['legalAddress'], + legalTaxId: $data['legalTaxId'], + authDuration: $data['authDuration'], + authLimit: $data['authLimit'], + authSessionsLimit: $data['authSessionsLimit'], + authPasswordHistory: $data['authPasswordHistory'], + authPasswordDictionary: $data['authPasswordDictionary'], + authPersonalDataCheck: $data['authPersonalDataCheck'], + authDisposableEmails: $data['authDisposableEmails'], + authCanonicalEmails: $data['authCanonicalEmails'], + authFreeEmails: $data['authFreeEmails'], + authMockNumbers: is_array($data['authMockNumbers']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(MockNumber::class, $item), + $data['authMockNumbers'] + ) + : $data['authMockNumbers'], + authSessionAlerts: $data['authSessionAlerts'], + authMembershipsUserName: $data['authMembershipsUserName'], + authMembershipsUserEmail: $data['authMembershipsUserEmail'], + authMembershipsMfa: $data['authMembershipsMfa'], + authInvalidateSessions: $data['authInvalidateSessions'], + oAuthProviders: is_array($data['oAuthProviders']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(AuthProvider::class, $item), + $data['oAuthProviders'] + ) + : $data['oAuthProviders'], + platforms: $data['platforms'], + webhooks: is_array($data['webhooks']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Webhook::class, $item), + $data['webhooks'] + ) + : $data['webhooks'], + keys: is_array($data['keys']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Key::class, $item), + $data['keys'] + ) + : $data['keys'], + devKeys: is_array($data['devKeys']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(DevKey::class, $item), + $data['devKeys'] + ) + : $data['devKeys'], + smtpEnabled: $data['smtpEnabled'], + smtpSenderName: $data['smtpSenderName'], + smtpSenderEmail: $data['smtpSenderEmail'], + smtpReplyTo: $data['smtpReplyTo'], + smtpHost: $data['smtpHost'], + smtpPort: $data['smtpPort'], + smtpUsername: $data['smtpUsername'], + smtpPassword: $data['smtpPassword'], + smtpSecure: $data['smtpSecure'], + pingCount: $data['pingCount'], + pingedAt: $data['pingedAt'], + labels: $data['labels'], + status: $data['status'], + authEmailPassword: $data['authEmailPassword'], + authUsersAuthMagicURL: $data['authUsersAuthMagicURL'], + authEmailOtp: $data['authEmailOtp'], + authAnonymous: $data['authAnonymous'], + authInvites: $data['authInvites'], + authJWT: $data['authJWT'], + authPhone: $data['authPhone'], + serviceStatusForAccount: $data['serviceStatusForAccount'], + serviceStatusForAvatars: $data['serviceStatusForAvatars'], + serviceStatusForDatabases: $data['serviceStatusForDatabases'], + serviceStatusForTablesdb: $data['serviceStatusForTablesdb'], + serviceStatusForLocale: $data['serviceStatusForLocale'], + serviceStatusForHealth: $data['serviceStatusForHealth'], + serviceStatusForProject: $data['serviceStatusForProject'], + serviceStatusForStorage: $data['serviceStatusForStorage'], + serviceStatusForTeams: $data['serviceStatusForTeams'], + serviceStatusForUsers: $data['serviceStatusForUsers'], + serviceStatusForVcs: $data['serviceStatusForVcs'], + serviceStatusForSites: $data['serviceStatusForSites'], + serviceStatusForFunctions: $data['serviceStatusForFunctions'], + serviceStatusForProxy: $data['serviceStatusForProxy'], + serviceStatusForGraphql: $data['serviceStatusForGraphql'], + serviceStatusForMigrations: $data['serviceStatusForMigrations'], + serviceStatusForMessaging: $data['serviceStatusForMessaging'], + protocolStatusForRest: $data['protocolStatusForRest'], + protocolStatusForGraphql: $data['protocolStatusForGraphql'], + protocolStatusForWebsocket: $data['protocolStatusForWebsocket'], + region: $data['region'], + billingLimits: static::hydrateTypedValue(BillingLimits::class, $data['billingLimits']), + blocks: is_array($data['blocks']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Block::class, $item), + $data['blocks'] + ) + : $data['blocks'], + consoleAccessedAt: $data['consoleAccessedAt'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'description' => static::serializeValue($this->description), + 'teamId' => static::serializeValue($this->teamId), + 'logo' => static::serializeValue($this->logo), + 'url' => static::serializeValue($this->url), + 'legalName' => static::serializeValue($this->legalName), + 'legalCountry' => static::serializeValue($this->legalCountry), + 'legalState' => static::serializeValue($this->legalState), + 'legalCity' => static::serializeValue($this->legalCity), + 'legalAddress' => static::serializeValue($this->legalAddress), + 'legalTaxId' => static::serializeValue($this->legalTaxId), + 'authDuration' => static::serializeValue($this->authDuration), + 'authLimit' => static::serializeValue($this->authLimit), + 'authSessionsLimit' => static::serializeValue($this->authSessionsLimit), + 'authPasswordHistory' => static::serializeValue($this->authPasswordHistory), + 'authPasswordDictionary' => static::serializeValue($this->authPasswordDictionary), + 'authPersonalDataCheck' => static::serializeValue($this->authPersonalDataCheck), + 'authDisposableEmails' => static::serializeValue($this->authDisposableEmails), + 'authCanonicalEmails' => static::serializeValue($this->authCanonicalEmails), + 'authFreeEmails' => static::serializeValue($this->authFreeEmails), + 'authMockNumbers' => static::serializeValue($this->authMockNumbers), + 'authSessionAlerts' => static::serializeValue($this->authSessionAlerts), + 'authMembershipsUserName' => static::serializeValue($this->authMembershipsUserName), + 'authMembershipsUserEmail' => static::serializeValue($this->authMembershipsUserEmail), + 'authMembershipsMfa' => static::serializeValue($this->authMembershipsMfa), + 'authInvalidateSessions' => static::serializeValue($this->authInvalidateSessions), + 'oAuthProviders' => static::serializeValue($this->oAuthProviders), + 'platforms' => static::serializeValue($this->platforms), + 'webhooks' => static::serializeValue($this->webhooks), + 'keys' => static::serializeValue($this->keys), + 'devKeys' => static::serializeValue($this->devKeys), + 'smtpEnabled' => static::serializeValue($this->smtpEnabled), + 'smtpSenderName' => static::serializeValue($this->smtpSenderName), + 'smtpSenderEmail' => static::serializeValue($this->smtpSenderEmail), + 'smtpReplyTo' => static::serializeValue($this->smtpReplyTo), + 'smtpHost' => static::serializeValue($this->smtpHost), + 'smtpPort' => static::serializeValue($this->smtpPort), + 'smtpUsername' => static::serializeValue($this->smtpUsername), + 'smtpPassword' => static::serializeValue($this->smtpPassword), + 'smtpSecure' => static::serializeValue($this->smtpSecure), + 'pingCount' => static::serializeValue($this->pingCount), + 'pingedAt' => static::serializeValue($this->pingedAt), + 'labels' => static::serializeValue($this->labels), + 'status' => static::serializeValue($this->status), + 'authEmailPassword' => static::serializeValue($this->authEmailPassword), + 'authUsersAuthMagicURL' => static::serializeValue($this->authUsersAuthMagicURL), + 'authEmailOtp' => static::serializeValue($this->authEmailOtp), + 'authAnonymous' => static::serializeValue($this->authAnonymous), + 'authInvites' => static::serializeValue($this->authInvites), + 'authJWT' => static::serializeValue($this->authJWT), + 'authPhone' => static::serializeValue($this->authPhone), + 'serviceStatusForAccount' => static::serializeValue($this->serviceStatusForAccount), + 'serviceStatusForAvatars' => static::serializeValue($this->serviceStatusForAvatars), + 'serviceStatusForDatabases' => static::serializeValue($this->serviceStatusForDatabases), + 'serviceStatusForTablesdb' => static::serializeValue($this->serviceStatusForTablesdb), + 'serviceStatusForLocale' => static::serializeValue($this->serviceStatusForLocale), + 'serviceStatusForHealth' => static::serializeValue($this->serviceStatusForHealth), + 'serviceStatusForProject' => static::serializeValue($this->serviceStatusForProject), + 'serviceStatusForStorage' => static::serializeValue($this->serviceStatusForStorage), + 'serviceStatusForTeams' => static::serializeValue($this->serviceStatusForTeams), + 'serviceStatusForUsers' => static::serializeValue($this->serviceStatusForUsers), + 'serviceStatusForVcs' => static::serializeValue($this->serviceStatusForVcs), + 'serviceStatusForSites' => static::serializeValue($this->serviceStatusForSites), + 'serviceStatusForFunctions' => static::serializeValue($this->serviceStatusForFunctions), + 'serviceStatusForProxy' => static::serializeValue($this->serviceStatusForProxy), + 'serviceStatusForGraphql' => static::serializeValue($this->serviceStatusForGraphql), + 'serviceStatusForMigrations' => static::serializeValue($this->serviceStatusForMigrations), + 'serviceStatusForMessaging' => static::serializeValue($this->serviceStatusForMessaging), + 'protocolStatusForRest' => static::serializeValue($this->protocolStatusForRest), + 'protocolStatusForGraphql' => static::serializeValue($this->protocolStatusForGraphql), + 'protocolStatusForWebsocket' => static::serializeValue($this->protocolStatusForWebsocket), + 'region' => static::serializeValue($this->region), + 'billingLimits' => static::serializeValue($this->billingLimits), + 'blocks' => static::serializeValue($this->blocks), + 'consoleAccessedAt' => static::serializeValue($this->consoleAccessedAt) + ]; + + return $result; + } +} diff --git a/src/Appwrite/Models/Provider.php b/src/Appwrite/Models/Provider.php index 013ea20b..0d40ad77 100644 --- a/src/Appwrite/Models/Provider.php +++ b/src/Appwrite/Models/Provider.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Provider constructor. * @@ -43,4 +34,67 @@ public function __construct( public ?array $options = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('provider', $data)) { + throw new \InvalidArgumentException('Missing required field "provider" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + if (!array_key_exists('type', $data)) { + throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.'); + } + if (!array_key_exists('credentials', $data)) { + throw new \InvalidArgumentException('Missing required field "credentials" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + provider: $data['provider'], + enabled: $data['enabled'], + type: $data['type'], + credentials: $data['credentials'], + options: array_key_exists('options', $data) ? $data['options'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'provider' => static::serializeValue($this->provider), + 'enabled' => static::serializeValue($this->enabled), + 'type' => static::serializeValue($this->type), + 'credentials' => static::serializeValue($this->credentials), + 'options' => static::serializeValue($this->options) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ProviderList.php b/src/Appwrite/Models/ProviderList.php index a7f28a19..0d71729c 100644 --- a/src/Appwrite/Models/ProviderList.php +++ b/src/Appwrite/Models/ProviderList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'providers' => Provider::class - ]; - /** * ProviderList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $providers ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('providers', $data)) { + throw new \InvalidArgumentException('Missing required field "providers" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + providers: is_array($data['providers']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Provider::class, $item), + $data['providers'] + ) + : $data['providers'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'providers' => static::serializeValue($this->providers) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ResourceToken.php b/src/Appwrite/Models/ResourceToken.php index 3eb90f26..5938f2e5 100644 --- a/src/Appwrite/Models/ResourceToken.php +++ b/src/Appwrite/Models/ResourceToken.php @@ -9,14 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt' - ]; - /** * ResourceToken constructor. * @@ -38,4 +30,60 @@ public function __construct( public string $accessedAt ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('resourceId', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceId" for ' . static::class . '.'); + } + if (!array_key_exists('resourceType', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceType" for ' . static::class . '.'); + } + if (!array_key_exists('expire', $data)) { + throw new \InvalidArgumentException('Missing required field "expire" for ' . static::class . '.'); + } + if (!array_key_exists('secret', $data)) { + throw new \InvalidArgumentException('Missing required field "secret" for ' . static::class . '.'); + } + if (!array_key_exists('accessedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "accessedAt" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + resourceId: $data['resourceId'], + resourceType: $data['resourceType'], + expire: $data['expire'], + secret: $data['secret'], + accessedAt: $data['accessedAt'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + 'resourceId' => static::serializeValue($this->resourceId), + 'resourceType' => static::serializeValue($this->resourceType), + 'expire' => static::serializeValue($this->expire), + 'secret' => static::serializeValue($this->secret), + 'accessedAt' => static::serializeValue($this->accessedAt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/ResourceTokenList.php b/src/Appwrite/Models/ResourceTokenList.php index 478060d1..9b43db3f 100644 --- a/src/Appwrite/Models/ResourceTokenList.php +++ b/src/Appwrite/Models/ResourceTokenList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'tokens' => ResourceToken::class - ]; - /** * ResourceTokenList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $tokens ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('tokens', $data)) { + throw new \InvalidArgumentException('Missing required field "tokens" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + tokens: is_array($data['tokens']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(ResourceToken::class, $item), + $data['tokens'] + ) + : $data['tokens'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'tokens' => static::serializeValue($this->tokens) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Row.php b/src/Appwrite/Models/Row.php index a0bb523e..4a1749f4 100644 --- a/src/Appwrite/Models/Row.php +++ b/src/Appwrite/Models/Row.php @@ -9,19 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'sequence' => '$sequence', - 'tableId' => '$tableId', - 'databaseId' => '$databaseId', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'permissions' => '$permissions' - ]; - private const ADDITIONAL_PROPERTIES = true; /** @@ -47,4 +34,78 @@ public function __construct( public array $data = [] ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$sequence', $data)) { + throw new \InvalidArgumentException('Missing required field "$sequence" for ' . static::class . '.'); + } + if (!array_key_exists('$tableId', $data)) { + throw new \InvalidArgumentException('Missing required field "$tableId" for ' . static::class . '.'); + } + if (!array_key_exists('$databaseId', $data)) { + throw new \InvalidArgumentException('Missing required field "$databaseId" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('$permissions', $data)) { + throw new \InvalidArgumentException('Missing required field "$permissions" for ' . static::class . '.'); + } + + $additionalProperties = static::extractAdditionalPropertiesFromFields( + $data, + [ + '$id', + '$sequence', + '$tableId', + '$databaseId', + '$createdAt', + '$updatedAt', + '$permissions' + ] + ); + + return new static( + id: $data['$id'], + sequence: $data['$sequence'], + tableId: $data['$tableId'], + databaseId: $data['$databaseId'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + permissions: $data['$permissions'], + data: $additionalProperties + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$sequence' => static::serializeValue($this->sequence), + '$tableId' => static::serializeValue($this->tableId), + '$databaseId' => static::serializeValue($this->databaseId), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + '$permissions' => static::serializeValue($this->permissions) + ]; + + foreach (static::serializeAdditionalProperties($this->data) as $field => $value) { + $result[$field] = $value; + } + + return $result; + } } diff --git a/src/Appwrite/Models/RowList.php b/src/Appwrite/Models/RowList.php index c22695be..4591004c 100644 --- a/src/Appwrite/Models/RowList.php +++ b/src/Appwrite/Models/RowList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'rows' => Row::class - ]; - /** * RowList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $rows ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('rows', $data)) { + throw new \InvalidArgumentException('Missing required field "rows" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + rows: is_array($data['rows']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Row::class, $item), + $data['rows'] + ) + : $data['rows'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'rows' => static::serializeValue($this->rows) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Runtime.php b/src/Appwrite/Models/Runtime.php index 5d8d0dee..fd311d20 100644 --- a/src/Appwrite/Models/Runtime.php +++ b/src/Appwrite/Models/Runtime.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id' - ]; - /** * Runtime constructor. * @@ -39,4 +32,65 @@ public function __construct( public array $supports ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('version', $data)) { + throw new \InvalidArgumentException('Missing required field "version" for ' . static::class . '.'); + } + if (!array_key_exists('base', $data)) { + throw new \InvalidArgumentException('Missing required field "base" for ' . static::class . '.'); + } + if (!array_key_exists('image', $data)) { + throw new \InvalidArgumentException('Missing required field "image" for ' . static::class . '.'); + } + if (!array_key_exists('logo', $data)) { + throw new \InvalidArgumentException('Missing required field "logo" for ' . static::class . '.'); + } + if (!array_key_exists('supports', $data)) { + throw new \InvalidArgumentException('Missing required field "supports" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + key: $data['key'], + name: $data['name'], + version: $data['version'], + base: $data['base'], + image: $data['image'], + logo: $data['logo'], + supports: $data['supports'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + 'key' => static::serializeValue($this->key), + 'name' => static::serializeValue($this->name), + 'version' => static::serializeValue($this->version), + 'base' => static::serializeValue($this->base), + 'image' => static::serializeValue($this->image), + 'logo' => static::serializeValue($this->logo), + 'supports' => static::serializeValue($this->supports) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/RuntimeList.php b/src/Appwrite/Models/RuntimeList.php index 53daa1ad..183567b3 100644 --- a/src/Appwrite/Models/RuntimeList.php +++ b/src/Appwrite/Models/RuntimeList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'runtimes' => Runtime::class - ]; - /** * RuntimeList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $runtimes ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('runtimes', $data)) { + throw new \InvalidArgumentException('Missing required field "runtimes" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + runtimes: is_array($data['runtimes']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Runtime::class, $item), + $data['runtimes'] + ) + : $data['runtimes'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'runtimes' => static::serializeValue($this->runtimes) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Session.php b/src/Appwrite/Models/Session.php index 03425ccb..0713ee5e 100644 --- a/src/Appwrite/Models/Session.php +++ b/src/Appwrite/Models/Session.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Session constructor. * @@ -83,4 +74,170 @@ public function __construct( public string $mfaUpdatedAt ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('userId', $data)) { + throw new \InvalidArgumentException('Missing required field "userId" for ' . static::class . '.'); + } + if (!array_key_exists('expire', $data)) { + throw new \InvalidArgumentException('Missing required field "expire" for ' . static::class . '.'); + } + if (!array_key_exists('provider', $data)) { + throw new \InvalidArgumentException('Missing required field "provider" for ' . static::class . '.'); + } + if (!array_key_exists('providerUid', $data)) { + throw new \InvalidArgumentException('Missing required field "providerUid" for ' . static::class . '.'); + } + if (!array_key_exists('providerAccessToken', $data)) { + throw new \InvalidArgumentException('Missing required field "providerAccessToken" for ' . static::class . '.'); + } + if (!array_key_exists('providerAccessTokenExpiry', $data)) { + throw new \InvalidArgumentException('Missing required field "providerAccessTokenExpiry" for ' . static::class . '.'); + } + if (!array_key_exists('providerRefreshToken', $data)) { + throw new \InvalidArgumentException('Missing required field "providerRefreshToken" for ' . static::class . '.'); + } + if (!array_key_exists('ip', $data)) { + throw new \InvalidArgumentException('Missing required field "ip" for ' . static::class . '.'); + } + if (!array_key_exists('osCode', $data)) { + throw new \InvalidArgumentException('Missing required field "osCode" for ' . static::class . '.'); + } + if (!array_key_exists('osName', $data)) { + throw new \InvalidArgumentException('Missing required field "osName" for ' . static::class . '.'); + } + if (!array_key_exists('osVersion', $data)) { + throw new \InvalidArgumentException('Missing required field "osVersion" for ' . static::class . '.'); + } + if (!array_key_exists('clientType', $data)) { + throw new \InvalidArgumentException('Missing required field "clientType" for ' . static::class . '.'); + } + if (!array_key_exists('clientCode', $data)) { + throw new \InvalidArgumentException('Missing required field "clientCode" for ' . static::class . '.'); + } + if (!array_key_exists('clientName', $data)) { + throw new \InvalidArgumentException('Missing required field "clientName" for ' . static::class . '.'); + } + if (!array_key_exists('clientVersion', $data)) { + throw new \InvalidArgumentException('Missing required field "clientVersion" for ' . static::class . '.'); + } + if (!array_key_exists('clientEngine', $data)) { + throw new \InvalidArgumentException('Missing required field "clientEngine" for ' . static::class . '.'); + } + if (!array_key_exists('clientEngineVersion', $data)) { + throw new \InvalidArgumentException('Missing required field "clientEngineVersion" for ' . static::class . '.'); + } + if (!array_key_exists('deviceName', $data)) { + throw new \InvalidArgumentException('Missing required field "deviceName" for ' . static::class . '.'); + } + if (!array_key_exists('deviceBrand', $data)) { + throw new \InvalidArgumentException('Missing required field "deviceBrand" for ' . static::class . '.'); + } + if (!array_key_exists('deviceModel', $data)) { + throw new \InvalidArgumentException('Missing required field "deviceModel" for ' . static::class . '.'); + } + if (!array_key_exists('countryCode', $data)) { + throw new \InvalidArgumentException('Missing required field "countryCode" for ' . static::class . '.'); + } + if (!array_key_exists('countryName', $data)) { + throw new \InvalidArgumentException('Missing required field "countryName" for ' . static::class . '.'); + } + if (!array_key_exists('current', $data)) { + throw new \InvalidArgumentException('Missing required field "current" for ' . static::class . '.'); + } + if (!array_key_exists('factors', $data)) { + throw new \InvalidArgumentException('Missing required field "factors" for ' . static::class . '.'); + } + if (!array_key_exists('secret', $data)) { + throw new \InvalidArgumentException('Missing required field "secret" for ' . static::class . '.'); + } + if (!array_key_exists('mfaUpdatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "mfaUpdatedAt" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + userId: $data['userId'], + expire: $data['expire'], + provider: $data['provider'], + providerUid: $data['providerUid'], + providerAccessToken: $data['providerAccessToken'], + providerAccessTokenExpiry: $data['providerAccessTokenExpiry'], + providerRefreshToken: $data['providerRefreshToken'], + ip: $data['ip'], + osCode: $data['osCode'], + osName: $data['osName'], + osVersion: $data['osVersion'], + clientType: $data['clientType'], + clientCode: $data['clientCode'], + clientName: $data['clientName'], + clientVersion: $data['clientVersion'], + clientEngine: $data['clientEngine'], + clientEngineVersion: $data['clientEngineVersion'], + deviceName: $data['deviceName'], + deviceBrand: $data['deviceBrand'], + deviceModel: $data['deviceModel'], + countryCode: $data['countryCode'], + countryName: $data['countryName'], + current: $data['current'], + factors: $data['factors'], + secret: $data['secret'], + mfaUpdatedAt: $data['mfaUpdatedAt'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'userId' => static::serializeValue($this->userId), + 'expire' => static::serializeValue($this->expire), + 'provider' => static::serializeValue($this->provider), + 'providerUid' => static::serializeValue($this->providerUid), + 'providerAccessToken' => static::serializeValue($this->providerAccessToken), + 'providerAccessTokenExpiry' => static::serializeValue($this->providerAccessTokenExpiry), + 'providerRefreshToken' => static::serializeValue($this->providerRefreshToken), + 'ip' => static::serializeValue($this->ip), + 'osCode' => static::serializeValue($this->osCode), + 'osName' => static::serializeValue($this->osName), + 'osVersion' => static::serializeValue($this->osVersion), + 'clientType' => static::serializeValue($this->clientType), + 'clientCode' => static::serializeValue($this->clientCode), + 'clientName' => static::serializeValue($this->clientName), + 'clientVersion' => static::serializeValue($this->clientVersion), + 'clientEngine' => static::serializeValue($this->clientEngine), + 'clientEngineVersion' => static::serializeValue($this->clientEngineVersion), + 'deviceName' => static::serializeValue($this->deviceName), + 'deviceBrand' => static::serializeValue($this->deviceBrand), + 'deviceModel' => static::serializeValue($this->deviceModel), + 'countryCode' => static::serializeValue($this->countryCode), + 'countryName' => static::serializeValue($this->countryName), + 'current' => static::serializeValue($this->current), + 'factors' => static::serializeValue($this->factors), + 'secret' => static::serializeValue($this->secret), + 'mfaUpdatedAt' => static::serializeValue($this->mfaUpdatedAt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/SessionList.php b/src/Appwrite/Models/SessionList.php index 1e788df3..4acd0772 100644 --- a/src/Appwrite/Models/SessionList.php +++ b/src/Appwrite/Models/SessionList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'sessions' => Session::class - ]; - /** * SessionList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $sessions ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('sessions', $data)) { + throw new \InvalidArgumentException('Missing required field "sessions" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + sessions: is_array($data['sessions']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Session::class, $item), + $data['sessions'] + ) + : $data['sessions'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'sessions' => static::serializeValue($this->sessions) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Site.php b/src/Appwrite/Models/Site.php index 616ee4c5..6b34636f 100644 --- a/src/Appwrite/Models/Site.php +++ b/src/Appwrite/Models/Site.php @@ -9,22 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'vars' => Variable::class - ]; - /** * Site constructor. * @@ -96,4 +80,190 @@ public function __construct( public string $fallbackFile ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + if (!array_key_exists('live', $data)) { + throw new \InvalidArgumentException('Missing required field "live" for ' . static::class . '.'); + } + if (!array_key_exists('logging', $data)) { + throw new \InvalidArgumentException('Missing required field "logging" for ' . static::class . '.'); + } + if (!array_key_exists('framework', $data)) { + throw new \InvalidArgumentException('Missing required field "framework" for ' . static::class . '.'); + } + if (!array_key_exists('deploymentRetention', $data)) { + throw new \InvalidArgumentException('Missing required field "deploymentRetention" for ' . static::class . '.'); + } + if (!array_key_exists('deploymentId', $data)) { + throw new \InvalidArgumentException('Missing required field "deploymentId" for ' . static::class . '.'); + } + if (!array_key_exists('deploymentCreatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "deploymentCreatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('deploymentScreenshotLight', $data)) { + throw new \InvalidArgumentException('Missing required field "deploymentScreenshotLight" for ' . static::class . '.'); + } + if (!array_key_exists('deploymentScreenshotDark', $data)) { + throw new \InvalidArgumentException('Missing required field "deploymentScreenshotDark" for ' . static::class . '.'); + } + if (!array_key_exists('latestDeploymentId', $data)) { + throw new \InvalidArgumentException('Missing required field "latestDeploymentId" for ' . static::class . '.'); + } + if (!array_key_exists('latestDeploymentCreatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "latestDeploymentCreatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('latestDeploymentStatus', $data)) { + throw new \InvalidArgumentException('Missing required field "latestDeploymentStatus" for ' . static::class . '.'); + } + if (!array_key_exists('vars', $data)) { + throw new \InvalidArgumentException('Missing required field "vars" for ' . static::class . '.'); + } + if (!array_key_exists('timeout', $data)) { + throw new \InvalidArgumentException('Missing required field "timeout" for ' . static::class . '.'); + } + if (!array_key_exists('installCommand', $data)) { + throw new \InvalidArgumentException('Missing required field "installCommand" for ' . static::class . '.'); + } + if (!array_key_exists('buildCommand', $data)) { + throw new \InvalidArgumentException('Missing required field "buildCommand" for ' . static::class . '.'); + } + if (!array_key_exists('startCommand', $data)) { + throw new \InvalidArgumentException('Missing required field "startCommand" for ' . static::class . '.'); + } + if (!array_key_exists('outputDirectory', $data)) { + throw new \InvalidArgumentException('Missing required field "outputDirectory" for ' . static::class . '.'); + } + if (!array_key_exists('installationId', $data)) { + throw new \InvalidArgumentException('Missing required field "installationId" for ' . static::class . '.'); + } + if (!array_key_exists('providerRepositoryId', $data)) { + throw new \InvalidArgumentException('Missing required field "providerRepositoryId" for ' . static::class . '.'); + } + if (!array_key_exists('providerBranch', $data)) { + throw new \InvalidArgumentException('Missing required field "providerBranch" for ' . static::class . '.'); + } + if (!array_key_exists('providerRootDirectory', $data)) { + throw new \InvalidArgumentException('Missing required field "providerRootDirectory" for ' . static::class . '.'); + } + if (!array_key_exists('providerSilentMode', $data)) { + throw new \InvalidArgumentException('Missing required field "providerSilentMode" for ' . static::class . '.'); + } + if (!array_key_exists('buildSpecification', $data)) { + throw new \InvalidArgumentException('Missing required field "buildSpecification" for ' . static::class . '.'); + } + if (!array_key_exists('runtimeSpecification', $data)) { + throw new \InvalidArgumentException('Missing required field "runtimeSpecification" for ' . static::class . '.'); + } + if (!array_key_exists('buildRuntime', $data)) { + throw new \InvalidArgumentException('Missing required field "buildRuntime" for ' . static::class . '.'); + } + if (!array_key_exists('adapter', $data)) { + throw new \InvalidArgumentException('Missing required field "adapter" for ' . static::class . '.'); + } + if (!array_key_exists('fallbackFile', $data)) { + throw new \InvalidArgumentException('Missing required field "fallbackFile" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + enabled: $data['enabled'], + live: $data['live'], + logging: $data['logging'], + framework: $data['framework'], + deploymentRetention: $data['deploymentRetention'], + deploymentId: $data['deploymentId'], + deploymentCreatedAt: $data['deploymentCreatedAt'], + deploymentScreenshotLight: $data['deploymentScreenshotLight'], + deploymentScreenshotDark: $data['deploymentScreenshotDark'], + latestDeploymentId: $data['latestDeploymentId'], + latestDeploymentCreatedAt: $data['latestDeploymentCreatedAt'], + latestDeploymentStatus: $data['latestDeploymentStatus'], + vars: is_array($data['vars']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Variable::class, $item), + $data['vars'] + ) + : $data['vars'], + timeout: $data['timeout'], + installCommand: $data['installCommand'], + buildCommand: $data['buildCommand'], + startCommand: $data['startCommand'], + outputDirectory: $data['outputDirectory'], + installationId: $data['installationId'], + providerRepositoryId: $data['providerRepositoryId'], + providerBranch: $data['providerBranch'], + providerRootDirectory: $data['providerRootDirectory'], + providerSilentMode: $data['providerSilentMode'], + buildSpecification: $data['buildSpecification'], + runtimeSpecification: $data['runtimeSpecification'], + buildRuntime: $data['buildRuntime'], + adapter: $data['adapter'], + fallbackFile: $data['fallbackFile'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'enabled' => static::serializeValue($this->enabled), + 'live' => static::serializeValue($this->live), + 'logging' => static::serializeValue($this->logging), + 'framework' => static::serializeValue($this->framework), + 'deploymentRetention' => static::serializeValue($this->deploymentRetention), + 'deploymentId' => static::serializeValue($this->deploymentId), + 'deploymentCreatedAt' => static::serializeValue($this->deploymentCreatedAt), + 'deploymentScreenshotLight' => static::serializeValue($this->deploymentScreenshotLight), + 'deploymentScreenshotDark' => static::serializeValue($this->deploymentScreenshotDark), + 'latestDeploymentId' => static::serializeValue($this->latestDeploymentId), + 'latestDeploymentCreatedAt' => static::serializeValue($this->latestDeploymentCreatedAt), + 'latestDeploymentStatus' => static::serializeValue($this->latestDeploymentStatus), + 'vars' => static::serializeValue($this->vars), + 'timeout' => static::serializeValue($this->timeout), + 'installCommand' => static::serializeValue($this->installCommand), + 'buildCommand' => static::serializeValue($this->buildCommand), + 'startCommand' => static::serializeValue($this->startCommand), + 'outputDirectory' => static::serializeValue($this->outputDirectory), + 'installationId' => static::serializeValue($this->installationId), + 'providerRepositoryId' => static::serializeValue($this->providerRepositoryId), + 'providerBranch' => static::serializeValue($this->providerBranch), + 'providerRootDirectory' => static::serializeValue($this->providerRootDirectory), + 'providerSilentMode' => static::serializeValue($this->providerSilentMode), + 'buildSpecification' => static::serializeValue($this->buildSpecification), + 'runtimeSpecification' => static::serializeValue($this->runtimeSpecification), + 'buildRuntime' => static::serializeValue($this->buildRuntime), + 'adapter' => static::serializeValue($this->adapter), + 'fallbackFile' => static::serializeValue($this->fallbackFile) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/SiteList.php b/src/Appwrite/Models/SiteList.php index 54b2e6e3..93eac7b2 100644 --- a/src/Appwrite/Models/SiteList.php +++ b/src/Appwrite/Models/SiteList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'sites' => Site::class - ]; - /** * SiteList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $sites ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('sites', $data)) { + throw new \InvalidArgumentException('Missing required field "sites" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + sites: is_array($data['sites']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Site::class, $item), + $data['sites'] + ) + : $data['sites'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'sites' => static::serializeValue($this->sites) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Specification.php b/src/Appwrite/Models/Specification.php index a74f53c6..d2b7d058 100644 --- a/src/Appwrite/Models/Specification.php +++ b/src/Appwrite/Models/Specification.php @@ -24,4 +24,45 @@ public function __construct( public string $slug ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('memory', $data)) { + throw new \InvalidArgumentException('Missing required field "memory" for ' . static::class . '.'); + } + if (!array_key_exists('cpus', $data)) { + throw new \InvalidArgumentException('Missing required field "cpus" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + if (!array_key_exists('slug', $data)) { + throw new \InvalidArgumentException('Missing required field "slug" for ' . static::class . '.'); + } + + return new static( + memory: $data['memory'], + cpus: $data['cpus'], + enabled: $data['enabled'], + slug: $data['slug'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'memory' => static::serializeValue($this->memory), + 'cpus' => static::serializeValue($this->cpus), + 'enabled' => static::serializeValue($this->enabled), + 'slug' => static::serializeValue($this->slug) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/SpecificationList.php b/src/Appwrite/Models/SpecificationList.php index 554bb9f8..ac2442d7 100644 --- a/src/Appwrite/Models/SpecificationList.php +++ b/src/Appwrite/Models/SpecificationList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'specifications' => Specification::class - ]; - /** * SpecificationList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $specifications ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('specifications', $data)) { + throw new \InvalidArgumentException('Missing required field "specifications" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + specifications: is_array($data['specifications']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Specification::class, $item), + $data['specifications'] + ) + : $data['specifications'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'specifications' => static::serializeValue($this->specifications) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Subscriber.php b/src/Appwrite/Models/Subscriber.php index 718c8f5c..15793254 100644 --- a/src/Appwrite/Models/Subscriber.php +++ b/src/Appwrite/Models/Subscriber.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Subscriber constructor. * @@ -43,4 +34,70 @@ public function __construct( public string $providerType ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('targetId', $data)) { + throw new \InvalidArgumentException('Missing required field "targetId" for ' . static::class . '.'); + } + if (!array_key_exists('target', $data)) { + throw new \InvalidArgumentException('Missing required field "target" for ' . static::class . '.'); + } + if (!array_key_exists('userId', $data)) { + throw new \InvalidArgumentException('Missing required field "userId" for ' . static::class . '.'); + } + if (!array_key_exists('userName', $data)) { + throw new \InvalidArgumentException('Missing required field "userName" for ' . static::class . '.'); + } + if (!array_key_exists('topicId', $data)) { + throw new \InvalidArgumentException('Missing required field "topicId" for ' . static::class . '.'); + } + if (!array_key_exists('providerType', $data)) { + throw new \InvalidArgumentException('Missing required field "providerType" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + targetId: $data['targetId'], + target: static::hydrateTypedValue(Target::class, $data['target']), + userId: $data['userId'], + userName: $data['userName'], + topicId: $data['topicId'], + providerType: $data['providerType'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'targetId' => static::serializeValue($this->targetId), + 'target' => static::serializeValue($this->target), + 'userId' => static::serializeValue($this->userId), + 'userName' => static::serializeValue($this->userName), + 'topicId' => static::serializeValue($this->topicId), + 'providerType' => static::serializeValue($this->providerType) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/SubscriberList.php b/src/Appwrite/Models/SubscriberList.php index 886e7478..458f5798 100644 --- a/src/Appwrite/Models/SubscriberList.php +++ b/src/Appwrite/Models/SubscriberList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'subscribers' => Subscriber::class - ]; - /** * SubscriberList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $subscribers ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('subscribers', $data)) { + throw new \InvalidArgumentException('Missing required field "subscribers" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + subscribers: is_array($data['subscribers']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Subscriber::class, $item), + $data['subscribers'] + ) + : $data['subscribers'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'subscribers' => static::serializeValue($this->subscribers) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Table.php b/src/Appwrite/Models/Table.php index cd7c8004..c8b6a60f 100644 --- a/src/Appwrite/Models/Table.php +++ b/src/Appwrite/Models/Table.php @@ -9,23 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt', - 'permissions' => '$permissions' - ]; - - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'indexes' => ColumnIndex::class - ]; - /** * Table constructor. * @@ -57,4 +40,90 @@ public function __construct( public int $bytesUsed ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('$permissions', $data)) { + throw new \InvalidArgumentException('Missing required field "$permissions" for ' . static::class . '.'); + } + if (!array_key_exists('databaseId', $data)) { + throw new \InvalidArgumentException('Missing required field "databaseId" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + if (!array_key_exists('rowSecurity', $data)) { + throw new \InvalidArgumentException('Missing required field "rowSecurity" for ' . static::class . '.'); + } + if (!array_key_exists('columns', $data)) { + throw new \InvalidArgumentException('Missing required field "columns" for ' . static::class . '.'); + } + if (!array_key_exists('indexes', $data)) { + throw new \InvalidArgumentException('Missing required field "indexes" for ' . static::class . '.'); + } + if (!array_key_exists('bytesMax', $data)) { + throw new \InvalidArgumentException('Missing required field "bytesMax" for ' . static::class . '.'); + } + if (!array_key_exists('bytesUsed', $data)) { + throw new \InvalidArgumentException('Missing required field "bytesUsed" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + permissions: $data['$permissions'], + databaseId: $data['databaseId'], + name: $data['name'], + enabled: $data['enabled'], + rowSecurity: $data['rowSecurity'], + columns: $data['columns'], + indexes: is_array($data['indexes']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(ColumnIndex::class, $item), + $data['indexes'] + ) + : $data['indexes'], + bytesMax: $data['bytesMax'], + bytesUsed: $data['bytesUsed'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + '$permissions' => static::serializeValue($this->permissions), + 'databaseId' => static::serializeValue($this->databaseId), + 'name' => static::serializeValue($this->name), + 'enabled' => static::serializeValue($this->enabled), + 'rowSecurity' => static::serializeValue($this->rowSecurity), + 'columns' => static::serializeValue($this->columns), + 'indexes' => static::serializeValue($this->indexes), + 'bytesMax' => static::serializeValue($this->bytesMax), + 'bytesUsed' => static::serializeValue($this->bytesUsed) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/TableList.php b/src/Appwrite/Models/TableList.php index 96b3e66e..587fbfae 100644 --- a/src/Appwrite/Models/TableList.php +++ b/src/Appwrite/Models/TableList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'tables' => Table::class - ]; - /** * TableList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $tables ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('tables', $data)) { + throw new \InvalidArgumentException('Missing required field "tables" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + tables: is_array($data['tables']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Table::class, $item), + $data['tables'] + ) + : $data['tables'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'tables' => static::serializeValue($this->tables) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Target.php b/src/Appwrite/Models/Target.php index f1d6a053..b00b2298 100644 --- a/src/Appwrite/Models/Target.php +++ b/src/Appwrite/Models/Target.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Target constructor. * @@ -43,4 +34,67 @@ public function __construct( public ?string $providerId = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('userId', $data)) { + throw new \InvalidArgumentException('Missing required field "userId" for ' . static::class . '.'); + } + if (!array_key_exists('providerType', $data)) { + throw new \InvalidArgumentException('Missing required field "providerType" for ' . static::class . '.'); + } + if (!array_key_exists('identifier', $data)) { + throw new \InvalidArgumentException('Missing required field "identifier" for ' . static::class . '.'); + } + if (!array_key_exists('expired', $data)) { + throw new \InvalidArgumentException('Missing required field "expired" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + userId: $data['userId'], + providerType: $data['providerType'], + identifier: $data['identifier'], + expired: $data['expired'], + providerId: array_key_exists('providerId', $data) ? $data['providerId'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'userId' => static::serializeValue($this->userId), + 'providerId' => static::serializeValue($this->providerId), + 'providerType' => static::serializeValue($this->providerType), + 'identifier' => static::serializeValue($this->identifier), + 'expired' => static::serializeValue($this->expired) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/TargetList.php b/src/Appwrite/Models/TargetList.php index 93a3d15a..d4db0a5f 100644 --- a/src/Appwrite/Models/TargetList.php +++ b/src/Appwrite/Models/TargetList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'targets' => Target::class - ]; - /** * TargetList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $targets ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('targets', $data)) { + throw new \InvalidArgumentException('Missing required field "targets" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + targets: is_array($data['targets']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Target::class, $item), + $data['targets'] + ) + : $data['targets'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'targets' => static::serializeValue($this->targets) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Team.php b/src/Appwrite/Models/Team.php index a6e4d989..73e1c130 100644 --- a/src/Appwrite/Models/Team.php +++ b/src/Appwrite/Models/Team.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Team constructor. * @@ -37,4 +28,55 @@ public function __construct( public Preferences $prefs ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('prefs', $data)) { + throw new \InvalidArgumentException('Missing required field "prefs" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + total: $data['total'], + prefs: static::hydrateTypedValue(Preferences::class, $data['prefs']) + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'total' => static::serializeValue($this->total), + 'prefs' => static::serializeValue($this->prefs) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/TeamList.php b/src/Appwrite/Models/TeamList.php index 9bc36451..61db8d1c 100644 --- a/src/Appwrite/Models/TeamList.php +++ b/src/Appwrite/Models/TeamList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'teams' => Team::class - ]; - /** * TeamList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $teams ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('teams', $data)) { + throw new \InvalidArgumentException('Missing required field "teams" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + teams: is_array($data['teams']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Team::class, $item), + $data['teams'] + ) + : $data['teams'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'teams' => static::serializeValue($this->teams) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Token.php b/src/Appwrite/Models/Token.php index bb843d51..55288933 100644 --- a/src/Appwrite/Models/Token.php +++ b/src/Appwrite/Models/Token.php @@ -9,14 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt' - ]; - /** * Token constructor. * @@ -36,4 +28,55 @@ public function __construct( public string $phrase ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('userId', $data)) { + throw new \InvalidArgumentException('Missing required field "userId" for ' . static::class . '.'); + } + if (!array_key_exists('secret', $data)) { + throw new \InvalidArgumentException('Missing required field "secret" for ' . static::class . '.'); + } + if (!array_key_exists('expire', $data)) { + throw new \InvalidArgumentException('Missing required field "expire" for ' . static::class . '.'); + } + if (!array_key_exists('phrase', $data)) { + throw new \InvalidArgumentException('Missing required field "phrase" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + userId: $data['userId'], + secret: $data['secret'], + expire: $data['expire'], + phrase: $data['phrase'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + 'userId' => static::serializeValue($this->userId), + 'secret' => static::serializeValue($this->secret), + 'expire' => static::serializeValue($this->expire), + 'phrase' => static::serializeValue($this->phrase) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Topic.php b/src/Appwrite/Models/Topic.php index ef39b201..d10df72b 100644 --- a/src/Appwrite/Models/Topic.php +++ b/src/Appwrite/Models/Topic.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Topic constructor. * @@ -41,4 +32,65 @@ public function __construct( public array $subscribe ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('emailTotal', $data)) { + throw new \InvalidArgumentException('Missing required field "emailTotal" for ' . static::class . '.'); + } + if (!array_key_exists('smsTotal', $data)) { + throw new \InvalidArgumentException('Missing required field "smsTotal" for ' . static::class . '.'); + } + if (!array_key_exists('pushTotal', $data)) { + throw new \InvalidArgumentException('Missing required field "pushTotal" for ' . static::class . '.'); + } + if (!array_key_exists('subscribe', $data)) { + throw new \InvalidArgumentException('Missing required field "subscribe" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + emailTotal: $data['emailTotal'], + smsTotal: $data['smsTotal'], + pushTotal: $data['pushTotal'], + subscribe: $data['subscribe'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'emailTotal' => static::serializeValue($this->emailTotal), + 'smsTotal' => static::serializeValue($this->smsTotal), + 'pushTotal' => static::serializeValue($this->pushTotal), + 'subscribe' => static::serializeValue($this->subscribe) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/TopicList.php b/src/Appwrite/Models/TopicList.php index 421acfdd..e8c184e5 100644 --- a/src/Appwrite/Models/TopicList.php +++ b/src/Appwrite/Models/TopicList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'topics' => Topic::class - ]; - /** * TopicList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $topics ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('topics', $data)) { + throw new \InvalidArgumentException('Missing required field "topics" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + topics: is_array($data['topics']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Topic::class, $item), + $data['topics'] + ) + : $data['topics'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'topics' => static::serializeValue($this->topics) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Transaction.php b/src/Appwrite/Models/Transaction.php index 7fc65f39..010651f7 100644 --- a/src/Appwrite/Models/Transaction.php +++ b/src/Appwrite/Models/Transaction.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Transaction constructor. * @@ -37,4 +28,55 @@ public function __construct( public string $expiresAt ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('operations', $data)) { + throw new \InvalidArgumentException('Missing required field "operations" for ' . static::class . '.'); + } + if (!array_key_exists('expiresAt', $data)) { + throw new \InvalidArgumentException('Missing required field "expiresAt" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + status: $data['status'], + operations: $data['operations'], + expiresAt: $data['expiresAt'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'status' => static::serializeValue($this->status), + 'operations' => static::serializeValue($this->operations), + 'expiresAt' => static::serializeValue($this->expiresAt) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/TransactionList.php b/src/Appwrite/Models/TransactionList.php index b3ce209f..9ee090e5 100644 --- a/src/Appwrite/Models/TransactionList.php +++ b/src/Appwrite/Models/TransactionList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'transactions' => Transaction::class - ]; - /** * TransactionList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $transactions ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('transactions', $data)) { + throw new \InvalidArgumentException('Missing required field "transactions" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + transactions: is_array($data['transactions']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Transaction::class, $item), + $data['transactions'] + ) + : $data['transactions'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'transactions' => static::serializeValue($this->transactions) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/User.php b/src/Appwrite/Models/User.php index ad759c6b..2688bf50 100644 --- a/src/Appwrite/Models/User.php +++ b/src/Appwrite/Models/User.php @@ -9,22 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'targets' => Target::class - ]; - /** * User constructor. * @@ -74,4 +58,120 @@ public function __construct( public ?string $impersonatorUserId = null ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('registration', $data)) { + throw new \InvalidArgumentException('Missing required field "registration" for ' . static::class . '.'); + } + if (!array_key_exists('status', $data)) { + throw new \InvalidArgumentException('Missing required field "status" for ' . static::class . '.'); + } + if (!array_key_exists('labels', $data)) { + throw new \InvalidArgumentException('Missing required field "labels" for ' . static::class . '.'); + } + if (!array_key_exists('passwordUpdate', $data)) { + throw new \InvalidArgumentException('Missing required field "passwordUpdate" for ' . static::class . '.'); + } + if (!array_key_exists('email', $data)) { + throw new \InvalidArgumentException('Missing required field "email" for ' . static::class . '.'); + } + if (!array_key_exists('phone', $data)) { + throw new \InvalidArgumentException('Missing required field "phone" for ' . static::class . '.'); + } + if (!array_key_exists('emailVerification', $data)) { + throw new \InvalidArgumentException('Missing required field "emailVerification" for ' . static::class . '.'); + } + if (!array_key_exists('phoneVerification', $data)) { + throw new \InvalidArgumentException('Missing required field "phoneVerification" for ' . static::class . '.'); + } + if (!array_key_exists('mfa', $data)) { + throw new \InvalidArgumentException('Missing required field "mfa" for ' . static::class . '.'); + } + if (!array_key_exists('prefs', $data)) { + throw new \InvalidArgumentException('Missing required field "prefs" for ' . static::class . '.'); + } + if (!array_key_exists('targets', $data)) { + throw new \InvalidArgumentException('Missing required field "targets" for ' . static::class . '.'); + } + if (!array_key_exists('accessedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "accessedAt" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + registration: $data['registration'], + status: $data['status'], + labels: $data['labels'], + passwordUpdate: $data['passwordUpdate'], + email: $data['email'], + phone: $data['phone'], + emailVerification: $data['emailVerification'], + phoneVerification: $data['phoneVerification'], + mfa: $data['mfa'], + prefs: static::hydrateTypedValue(Preferences::class, $data['prefs']), + targets: is_array($data['targets']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Target::class, $item), + $data['targets'] + ) + : $data['targets'], + accessedAt: $data['accessedAt'], + password: array_key_exists('password', $data) ? $data['password'] : null, + hash: array_key_exists('hash', $data) ? $data['hash'] : null, + hashOptions: array_key_exists('hashOptions', $data) ? $data['hashOptions'] : null, + impersonator: array_key_exists('impersonator', $data) ? $data['impersonator'] : null, + impersonatorUserId: array_key_exists('impersonatorUserId', $data) ? $data['impersonatorUserId'] : null + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'password' => static::serializeValue($this->password), + 'hash' => static::serializeValue($this->hash), + 'hashOptions' => static::serializeValue($this->hashOptions), + 'registration' => static::serializeValue($this->registration), + 'status' => static::serializeValue($this->status), + 'labels' => static::serializeValue($this->labels), + 'passwordUpdate' => static::serializeValue($this->passwordUpdate), + 'email' => static::serializeValue($this->email), + 'phone' => static::serializeValue($this->phone), + 'emailVerification' => static::serializeValue($this->emailVerification), + 'phoneVerification' => static::serializeValue($this->phoneVerification), + 'mfa' => static::serializeValue($this->mfa), + 'prefs' => static::serializeValue($this->prefs), + 'targets' => static::serializeValue($this->targets), + 'accessedAt' => static::serializeValue($this->accessedAt), + 'impersonator' => static::serializeValue($this->impersonator), + 'impersonatorUserId' => static::serializeValue($this->impersonatorUserId) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/UserList.php b/src/Appwrite/Models/UserList.php index d77ad82c..89ba62de 100644 --- a/src/Appwrite/Models/UserList.php +++ b/src/Appwrite/Models/UserList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'users' => User::class - ]; - /** * UserList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $users ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('users', $data)) { + throw new \InvalidArgumentException('Missing required field "users" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + users: is_array($data['users']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(User::class, $item), + $data['users'] + ) + : $data['users'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'users' => static::serializeValue($this->users) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Variable.php b/src/Appwrite/Models/Variable.php index c609eef2..c6d097b7 100644 --- a/src/Appwrite/Models/Variable.php +++ b/src/Appwrite/Models/Variable.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Variable constructor. * @@ -41,4 +32,65 @@ public function __construct( public string $resourceId ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('key', $data)) { + throw new \InvalidArgumentException('Missing required field "key" for ' . static::class . '.'); + } + if (!array_key_exists('value', $data)) { + throw new \InvalidArgumentException('Missing required field "value" for ' . static::class . '.'); + } + if (!array_key_exists('secret', $data)) { + throw new \InvalidArgumentException('Missing required field "secret" for ' . static::class . '.'); + } + if (!array_key_exists('resourceType', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceType" for ' . static::class . '.'); + } + if (!array_key_exists('resourceId', $data)) { + throw new \InvalidArgumentException('Missing required field "resourceId" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + key: $data['key'], + value: $data['value'], + secret: $data['secret'], + resourceType: $data['resourceType'], + resourceId: $data['resourceId'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'key' => static::serializeValue($this->key), + 'value' => static::serializeValue($this->value), + 'secret' => static::serializeValue($this->secret), + 'resourceType' => static::serializeValue($this->resourceType), + 'resourceId' => static::serializeValue($this->resourceId) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/VariableList.php b/src/Appwrite/Models/VariableList.php index 8298e2a6..c56ae8d7 100644 --- a/src/Appwrite/Models/VariableList.php +++ b/src/Appwrite/Models/VariableList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'variables' => Variable::class - ]; - /** * VariableList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $variables ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('variables', $data)) { + throw new \InvalidArgumentException('Missing required field "variables" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + variables: is_array($data['variables']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Variable::class, $item), + $data['variables'] + ) + : $data['variables'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'variables' => static::serializeValue($this->variables) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/Webhook.php b/src/Appwrite/Models/Webhook.php index 5ffb3fa7..9a1f089e 100644 --- a/src/Appwrite/Models/Webhook.php +++ b/src/Appwrite/Models/Webhook.php @@ -9,15 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const FIELD_MAP = [ - 'id' => '$id', - 'createdAt' => '$createdAt', - 'updatedAt' => '$updatedAt' - ]; - /** * Webhook constructor. * @@ -27,10 +18,10 @@ * @param string $name webhook name. * @param string $url webhook url endpoint. * @param array $events webhook trigger events. - * @param bool $security indicated if ssl / tls certificate verification is enabled. - * @param string $httpUser http basic authentication username. - * @param string $httpPass http basic authentication password. - * @param string $signatureKey signature key which can be used to validated incoming + * @param bool $tls indicates if ssl / tls certificate verification is enabled. + * @param string $authUsername http basic authentication username. + * @param string $authPassword http basic authentication password. + * @param string $secret signature key which can be used to validate incoming webhook payloads. only returned on creation and secret rotation. * @param bool $enabled indicates if this webhook is enabled. * @param string $logs webhook error logs from the most recent failure. * @param int $attempts number of consecutive failed webhook attempts. @@ -42,13 +33,99 @@ public function __construct( public string $name, public string $url, public array $events, - public bool $security, - public string $httpUser, - public string $httpPass, - public string $signatureKey, + public bool $tls, + public string $authUsername, + public string $authPassword, + public string $secret, public bool $enabled, public string $logs, public int $attempts ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('$id', $data)) { + throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.'); + } + if (!array_key_exists('$createdAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.'); + } + if (!array_key_exists('$updatedAt', $data)) { + throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.'); + } + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.'); + } + if (!array_key_exists('url', $data)) { + throw new \InvalidArgumentException('Missing required field "url" for ' . static::class . '.'); + } + if (!array_key_exists('events', $data)) { + throw new \InvalidArgumentException('Missing required field "events" for ' . static::class . '.'); + } + if (!array_key_exists('tls', $data)) { + throw new \InvalidArgumentException('Missing required field "tls" for ' . static::class . '.'); + } + if (!array_key_exists('authUsername', $data)) { + throw new \InvalidArgumentException('Missing required field "authUsername" for ' . static::class . '.'); + } + if (!array_key_exists('authPassword', $data)) { + throw new \InvalidArgumentException('Missing required field "authPassword" for ' . static::class . '.'); + } + if (!array_key_exists('secret', $data)) { + throw new \InvalidArgumentException('Missing required field "secret" for ' . static::class . '.'); + } + if (!array_key_exists('enabled', $data)) { + throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.'); + } + if (!array_key_exists('logs', $data)) { + throw new \InvalidArgumentException('Missing required field "logs" for ' . static::class . '.'); + } + if (!array_key_exists('attempts', $data)) { + throw new \InvalidArgumentException('Missing required field "attempts" for ' . static::class . '.'); + } + + return new static( + id: $data['$id'], + createdAt: $data['$createdAt'], + updatedAt: $data['$updatedAt'], + name: $data['name'], + url: $data['url'], + events: $data['events'], + tls: $data['tls'], + authUsername: $data['authUsername'], + authPassword: $data['authPassword'], + secret: $data['secret'], + enabled: $data['enabled'], + logs: $data['logs'], + attempts: $data['attempts'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + '$id' => static::serializeValue($this->id), + '$createdAt' => static::serializeValue($this->createdAt), + '$updatedAt' => static::serializeValue($this->updatedAt), + 'name' => static::serializeValue($this->name), + 'url' => static::serializeValue($this->url), + 'events' => static::serializeValue($this->events), + 'tls' => static::serializeValue($this->tls), + 'authUsername' => static::serializeValue($this->authUsername), + 'authPassword' => static::serializeValue($this->authPassword), + 'secret' => static::serializeValue($this->secret), + 'enabled' => static::serializeValue($this->enabled), + 'logs' => static::serializeValue($this->logs), + 'attempts' => static::serializeValue($this->attempts) + ]; + + return $result; + } } diff --git a/src/Appwrite/Models/WebhookList.php b/src/Appwrite/Models/WebhookList.php index 83cfe2bf..a15aa5cf 100644 --- a/src/Appwrite/Models/WebhookList.php +++ b/src/Appwrite/Models/WebhookList.php @@ -9,13 +9,6 @@ { use ArraySerializable; - /** - * @var array - */ - private const ARRAY_TYPES = [ - 'webhooks' => Webhook::class - ]; - /** * WebhookList constructor. * @@ -27,4 +20,40 @@ public function __construct( public array $webhooks ) { } + + /** + * @param array $data + */ + public static function from(array $data): static + { + if (!array_key_exists('total', $data)) { + throw new \InvalidArgumentException('Missing required field "total" for ' . static::class . '.'); + } + if (!array_key_exists('webhooks', $data)) { + throw new \InvalidArgumentException('Missing required field "webhooks" for ' . static::class . '.'); + } + + return new static( + total: $data['total'], + webhooks: is_array($data['webhooks']) + ? array_map( + static fn (mixed $item): mixed => static::hydrateTypedValue(Webhook::class, $item), + $data['webhooks'] + ) + : $data['webhooks'] + ); + } + + /** + * @return array + */ + public function toArray(): array + { + $result = [ + 'total' => static::serializeValue($this->total), + 'webhooks' => static::serializeValue($this->webhooks) + ]; + + return $result; + } } diff --git a/src/Appwrite/Service.php b/src/Appwrite/Service.php index 03a65427..1ccc56a6 100644 --- a/src/Appwrite/Service.php +++ b/src/Appwrite/Service.php @@ -10,78 +10,4 @@ public function __construct(Client $client) { $this->client = $client; } - - /** - * @param mixed $response - * @param array $models - * @param array, all: array}> $dispatch - * @return mixed - */ - protected function parseResponse(mixed $response, array $models = [], array $dispatch = []): mixed - { - if (!is_array($response) || empty($models)) { - return $response; - } - - if (count($models) === 1) { - return $this->hydrateModel($models[0], $response); - } - - if (empty($dispatch)) { - throw new \UnexpectedValueException('Unable to match response to any expected response model.'); - } - - $bestModel = null; - $bestScore = -1; - - foreach ($dispatch as $model => $metadata) { - $requiredFields = $metadata['required'] ?? []; - $allFields = $metadata['all'] ?? []; - $missingRequiredField = false; - - foreach ($requiredFields as $field) { - if (!array_key_exists($field, $response)) { - $missingRequiredField = true; - break; - } - } - - if ($missingRequiredField) { - continue; - } - - $score = 0; - - foreach ($allFields as $field) { - if (array_key_exists($field, $response)) { - $score++; - } - } - - if ($score > $bestScore) { - $bestScore = $score; - $bestModel = $model; - } - } - - if ($bestScore < 0 || $bestModel === null) { - throw new \UnexpectedValueException('Unable to match response to any expected response model.'); - } - - return $this->hydrateModel($bestModel, $response); - } - - /** - * @param class-string $model - * @param array $response - * @return mixed - */ - protected function hydrateModel(string $model, array $response): mixed - { - if (!method_exists($model, 'from')) { - return $response; - } - - return $model::from($response); - } } diff --git a/src/Appwrite/Services/Account.php b/src/Appwrite/Services/Account.php index 78eb9029..42ceabbb 100644 --- a/src/Appwrite/Services/Account.php +++ b/src/Appwrite/Services/Account.php @@ -42,10 +42,11 @@ public function get(): \Appwrite\Models\User $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -92,10 +93,11 @@ public function create(string $userId, string $email, string $password, ?string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -136,10 +138,11 @@ public function updateEmail(string $email, string $password): \Appwrite\Models\U $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -178,10 +181,11 @@ public function listIdentities(?array $queries = null, ?bool $total = null): \Ap $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\IdentityList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\IdentityList::from($response); } @@ -252,10 +256,11 @@ public function createJWT(?int $duration = null): \Appwrite\Models\Jwt $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Jwt::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Jwt::from($response); } @@ -295,10 +300,11 @@ public function listLogs(?array $queries = null, ?bool $total = null): \Appwrite $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\LogList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\LogList::from($response); } @@ -330,10 +336,11 @@ public function updateMFA(bool $mfa): \Appwrite\Models\User $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -368,10 +375,11 @@ public function createMFAAuthenticator(AuthenticatorType $type): \Appwrite\Model $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaType::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaType::from($response); } @@ -407,10 +415,11 @@ public function updateMFAAuthenticator(AuthenticatorType $type, string $otp): \A $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -476,10 +485,11 @@ public function createMFAChallenge(AuthenticationFactor $factor): \Appwrite\Mode $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaChallenge::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaChallenge::from($response); } @@ -517,10 +527,11 @@ public function updateMFAChallenge(string $challengeId, string $otp): \Appwrite\ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Session::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Session::from($response); } @@ -549,10 +560,11 @@ public function listMFAFactors(): \Appwrite\Models\MfaFactors $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaFactors::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaFactors::from($response); } @@ -584,10 +596,11 @@ public function getMFARecoveryCodes(): \Appwrite\Models\MfaRecoveryCodes $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaRecoveryCodes::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaRecoveryCodes::from($response); } @@ -621,10 +634,11 @@ public function createMFARecoveryCodes(): \Appwrite\Models\MfaRecoveryCodes $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaRecoveryCodes::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaRecoveryCodes::from($response); } @@ -657,10 +671,11 @@ public function updateMFARecoveryCodes(): \Appwrite\Models\MfaRecoveryCodes $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaRecoveryCodes::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaRecoveryCodes::from($response); } @@ -692,10 +707,11 @@ public function updateName(string $name): \Appwrite\Models\User $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -734,10 +750,11 @@ public function updatePassword(string $password, ?string $oldPassword = null): \ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -775,10 +792,11 @@ public function updatePhone(string $phone, string $password): \Appwrite\Models\U $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -807,10 +825,11 @@ public function getPrefs(): \Appwrite\Models\Preferences $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Preferences::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Preferences::from($response); } @@ -844,10 +863,11 @@ public function updatePrefs(array $prefs): \Appwrite\Models\User $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -888,10 +908,11 @@ public function createRecovery(string $email, string $url): \Appwrite\Models\Tok $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -936,10 +957,11 @@ public function updateRecovery(string $userId, string $secret, string $password) $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -969,10 +991,11 @@ public function listSessions(): \Appwrite\Models\SessionList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\SessionList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\SessionList::from($response); } @@ -1039,10 +1062,11 @@ public function createAnonymousSession(): \Appwrite\Models\Session $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Session::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Session::from($response); } @@ -1081,10 +1105,11 @@ public function createEmailPasswordSession(string $email, string $password): \Ap $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Session::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Session::from($response); } @@ -1123,10 +1148,11 @@ public function updateMagicURLSession(string $userId, string $secret): \Appwrite $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Session::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Session::from($response); } @@ -1165,10 +1191,11 @@ public function updatePhoneSession(string $userId, string $secret): \Appwrite\Mo $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Session::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Session::from($response); } @@ -1204,10 +1231,11 @@ public function createSession(string $userId, string $secret): \Appwrite\Models\ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Session::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Session::from($response); } @@ -1239,10 +1267,11 @@ public function getSession(string $sessionId): \Appwrite\Models\Session $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Session::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Session::from($response); } @@ -1276,10 +1305,11 @@ public function updateSession(string $sessionId): \Appwrite\Models\Session $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Session::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Session::from($response); } @@ -1347,10 +1377,11 @@ public function updateStatus(): \Appwrite\Models\User $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -1402,10 +1433,11 @@ public function createEmailToken(string $userId, string $email, ?bool $phrase = $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -1462,10 +1494,11 @@ public function createMagicURLToken(string $userId, string $email, ?string $url $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -1567,10 +1600,11 @@ public function createPhoneToken(string $userId, string $phone): \Appwrite\Model $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -1616,10 +1650,11 @@ public function createEmailVerification(string $url): \Appwrite\Models\Token $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -1668,10 +1703,11 @@ public function createVerification(string $url): \Appwrite\Models\Token $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -1708,10 +1744,11 @@ public function updateEmailVerification(string $userId, string $secret): \Appwri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -1751,10 +1788,11 @@ public function updateVerification(string $userId, string $secret): \Appwrite\Mo $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -1791,10 +1829,11 @@ public function createPhoneVerification(): \Appwrite\Models\Token $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -1831,10 +1870,11 @@ public function updatePhoneVerification(string $userId, string $secret): \Appwri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } } diff --git a/src/Appwrite/Services/Activities.php b/src/Appwrite/Services/Activities.php index 5d09bcb6..5e4c84dd 100644 --- a/src/Appwrite/Services/Activities.php +++ b/src/Appwrite/Services/Activities.php @@ -44,10 +44,11 @@ public function listEvents(?string $queries = null): \Appwrite\Models\ActivityEv $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ActivityEventList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ActivityEventList::from($response); } @@ -79,10 +80,11 @@ public function getEvent(string $eventId): \Appwrite\Models\ActivityEvent $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ActivityEvent::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ActivityEvent::from($response); } } diff --git a/src/Appwrite/Services/Backups.php b/src/Appwrite/Services/Backups.php index 1d210817..02dcac7b 100644 --- a/src/Appwrite/Services/Backups.php +++ b/src/Appwrite/Services/Backups.php @@ -45,10 +45,11 @@ public function listArchives(?array $queries = null): \Appwrite\Models\BackupArc $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupArchiveList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupArchiveList::from($response); } @@ -82,10 +83,11 @@ public function createArchive(array $services, ?string $resourceId = null): \App $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupArchive::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupArchive::from($response); } @@ -116,10 +118,11 @@ public function getArchive(string $archiveId): \Appwrite\Models\BackupArchive $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupArchive::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupArchive::from($response); } @@ -185,10 +188,11 @@ public function listPolicies(?array $queries = null): \Appwrite\Models\BackupPol $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupPolicyList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupPolicyList::from($response); } @@ -238,10 +242,11 @@ public function createPolicy(string $policyId, array $services, int $retention, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupPolicy::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupPolicy::from($response); } @@ -272,10 +277,11 @@ public function getPolicy(string $policyId): \Appwrite\Models\BackupPolicy $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupPolicy::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupPolicy::from($response); } @@ -318,10 +324,11 @@ public function updatePolicy(string $policyId, ?string $name = null, ?int $reten $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupPolicy::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupPolicy::from($response); } @@ -397,10 +404,11 @@ public function createRestoration(string $archiveId, array $services, ?string $n $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupRestoration::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupRestoration::from($response); } @@ -434,10 +442,11 @@ public function listRestorations(?array $queries = null): \Appwrite\Models\Backu $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupRestorationList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupRestorationList::from($response); } @@ -468,10 +477,11 @@ public function getRestoration(string $restorationId): \Appwrite\Models\BackupRe $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BackupRestoration::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BackupRestoration::from($response); } } diff --git a/src/Appwrite/Services/Databases.php b/src/Appwrite/Services/Databases.php index ce718dca..6eb07890 100644 --- a/src/Appwrite/Services/Databases.php +++ b/src/Appwrite/Services/Databases.php @@ -62,10 +62,11 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\DatabaseList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\DatabaseList::from($response); } @@ -108,10 +109,11 @@ public function create(string $databaseId, string $name, ?bool $enabled = null): $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Database::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Database::from($response); } @@ -145,10 +147,11 @@ public function listTransactions(?array $queries = null): \Appwrite\Models\Trans $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\TransactionList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\TransactionList::from($response); } @@ -183,10 +186,11 @@ public function createTransaction(?int $ttl = null): \Appwrite\Models\Transactio $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Transaction::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Transaction::from($response); } @@ -217,10 +221,11 @@ public function getTransaction(string $transactionId): \Appwrite\Models\Transact $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Transaction::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Transaction::from($response); } @@ -262,10 +267,11 @@ public function updateTransaction(string $transactionId, ?bool $commit = null, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Transaction::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Transaction::from($response); } @@ -334,10 +340,11 @@ public function createOperations(string $transactionId, ?array $operations = nul $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Transaction::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Transaction::from($response); } @@ -372,10 +379,11 @@ public function get(string $databaseId): \Appwrite\Models\Database $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Database::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Database::from($response); } @@ -420,10 +428,11 @@ public function update(string $databaseId, ?string $name = null, ?bool $enabled $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Database::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Database::from($response); } @@ -509,10 +518,11 @@ public function listCollections(string $databaseId, ?array $queries = null, ?str $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\CollectionList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\CollectionList::from($response); } @@ -576,10 +586,11 @@ public function createCollection(string $databaseId, string $collectionId, strin $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Collection::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Collection::from($response); } @@ -616,10 +627,11 @@ public function getCollection(string $databaseId, string $collectionId): \Appwri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Collection::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Collection::from($response); } @@ -632,13 +644,14 @@ public function getCollection(string $databaseId, string $collectionId): \Appwri * @param ?array $permissions * @param ?bool $documentSecurity * @param ?bool $enabled + * @param ?bool $purge * @throws AppwriteException * @return \Appwrite\Models\Collection * * @deprecated This API has been deprecated since 1.8.0. Please use `updateTable` instead. * @see TablesDB::updateTable */ - public function updateCollection(string $databaseId, string $collectionId, ?string $name = null, ?array $permissions = null, ?bool $documentSecurity = null, ?bool $enabled = null): \Appwrite\Models\Collection + public function updateCollection(string $databaseId, string $collectionId, ?string $name = null, ?array $permissions = null, ?bool $documentSecurity = null, ?bool $enabled = null, ?bool $purge = null): \Appwrite\Models\Collection { $apiPath = str_replace( ['{databaseId}', '{collectionId}'], @@ -663,6 +676,10 @@ public function updateCollection(string $databaseId, string $collectionId, ?stri $apiParams['enabled'] = $enabled; } + if (!is_null($purge)) { + $apiParams['purge'] = $purge; + } + $apiHeaders = []; $apiHeaders['content-type'] = 'application/json'; @@ -673,10 +690,11 @@ public function updateCollection(string $databaseId, string $collectionId, ?stri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Collection::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Collection::from($response); } @@ -760,10 +778,11 @@ public function listAttributes(string $databaseId, string $collectionId, ?array $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeList::from($response); } @@ -812,10 +831,11 @@ public function createBooleanAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeBoolean::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeBoolean::from($response); } @@ -861,10 +881,11 @@ public function updateBooleanAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeBoolean::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeBoolean::from($response); } @@ -912,10 +933,11 @@ public function createDatetimeAttribute(string $databaseId, string $collectionId $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeDatetime::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeDatetime::from($response); } @@ -961,10 +983,11 @@ public function updateDatetimeAttribute(string $databaseId, string $collectionId $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeDatetime::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeDatetime::from($response); } @@ -1013,10 +1036,11 @@ public function createEmailAttribute(string $databaseId, string $collectionId, s $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeEmail::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeEmail::from($response); } @@ -1063,10 +1087,11 @@ public function updateEmailAttribute(string $databaseId, string $collectionId, s $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeEmail::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeEmail::from($response); } @@ -1118,10 +1143,11 @@ public function createEnumAttribute(string $databaseId, string $collectionId, st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeEnum::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeEnum::from($response); } @@ -1170,10 +1196,11 @@ public function updateEnumAttribute(string $databaseId, string $collectionId, st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeEnum::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeEnum::from($response); } @@ -1227,10 +1254,11 @@ public function createFloatAttribute(string $databaseId, string $collectionId, s $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeFloat::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeFloat::from($response); } @@ -1281,10 +1309,11 @@ public function updateFloatAttribute(string $databaseId, string $collectionId, s $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeFloat::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeFloat::from($response); } @@ -1338,10 +1367,11 @@ public function createIntegerAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeInteger::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeInteger::from($response); } @@ -1392,10 +1422,11 @@ public function updateIntegerAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeInteger::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeInteger::from($response); } @@ -1444,10 +1475,11 @@ public function createIpAttribute(string $databaseId, string $collectionId, stri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeIp::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeIp::from($response); } @@ -1494,10 +1526,11 @@ public function updateIpAttribute(string $databaseId, string $collectionId, stri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeIp::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeIp::from($response); } @@ -1540,10 +1573,11 @@ public function createLineAttribute(string $databaseId, string $collectionId, st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeLine::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeLine::from($response); } @@ -1589,10 +1623,11 @@ public function updateLineAttribute(string $databaseId, string $collectionId, st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeLine::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeLine::from($response); } @@ -1643,10 +1678,11 @@ public function createLongtextAttribute(string $databaseId, string $collectionId $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeLongtext::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeLongtext::from($response); } @@ -1690,10 +1726,11 @@ public function updateLongtextAttribute(string $databaseId, string $collectionId $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeLongtext::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeLongtext::from($response); } @@ -1744,10 +1781,11 @@ public function createMediumtextAttribute(string $databaseId, string $collection $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeMediumtext::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeMediumtext::from($response); } @@ -1791,10 +1829,11 @@ public function updateMediumtextAttribute(string $databaseId, string $collection $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeMediumtext::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeMediumtext::from($response); } @@ -1837,10 +1876,11 @@ public function createPointAttribute(string $databaseId, string $collectionId, s $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributePoint::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributePoint::from($response); } @@ -1886,10 +1926,11 @@ public function updatePointAttribute(string $databaseId, string $collectionId, s $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributePoint::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributePoint::from($response); } @@ -1932,10 +1973,11 @@ public function createPolygonAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributePolygon::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributePolygon::from($response); } @@ -1981,10 +2023,11 @@ public function updatePolygonAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributePolygon::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributePolygon::from($response); } @@ -2041,10 +2084,11 @@ public function createRelationshipAttribute(string $databaseId, string $collecti $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeRelationship::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeRelationship::from($response); } @@ -2092,10 +2136,11 @@ public function updateRelationshipAttribute(string $databaseId, string $collecti $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeRelationship::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeRelationship::from($response); } @@ -2151,10 +2196,11 @@ public function createStringAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeString::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeString::from($response); } @@ -2203,10 +2249,11 @@ public function updateStringAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeString::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeString::from($response); } @@ -2257,10 +2304,11 @@ public function createTextAttribute(string $databaseId, string $collectionId, st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeText::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeText::from($response); } @@ -2304,10 +2352,11 @@ public function updateTextAttribute(string $databaseId, string $collectionId, st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeText::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeText::from($response); } @@ -2356,10 +2405,11 @@ public function createUrlAttribute(string $databaseId, string $collectionId, str $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeUrl::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeUrl::from($response); } @@ -2406,10 +2456,11 @@ public function updateUrlAttribute(string $databaseId, string $collectionId, str $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeUrl::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeUrl::from($response); } @@ -2462,10 +2513,11 @@ public function createVarcharAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeVarchar::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeVarchar::from($response); } @@ -2511,10 +2563,11 @@ public function updateVarcharAttribute(string $databaseId, string $collectionId, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeVarchar::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\AttributeVarchar::from($response); } @@ -2552,53 +2605,51 @@ public function getAttribute(string $databaseId, string $collectionId, string $k $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\AttributeBoolean::class, \Appwrite\Models\AttributeInteger::class, \Appwrite\Models\AttributeFloat::class, \Appwrite\Models\AttributeEmail::class, \Appwrite\Models\AttributeEnum::class, \Appwrite\Models\AttributeUrl::class, \Appwrite\Models\AttributeIp::class, \Appwrite\Models\AttributeDatetime::class, \Appwrite\Models\AttributeRelationship::class, \Appwrite\Models\AttributeString::class] -, - [ - \Appwrite\Models\AttributeBoolean::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'default'], - ], - \Appwrite\Models\AttributeInteger::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'min', 'max', 'default'], - ], - \Appwrite\Models\AttributeFloat::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'min', 'max', 'default'], - ], - \Appwrite\Models\AttributeEmail::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'format', 'default'], - ], - \Appwrite\Models\AttributeEnum::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'elements', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'elements', 'format', 'default'], - ], - \Appwrite\Models\AttributeUrl::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'format', 'default'], - ], - \Appwrite\Models\AttributeIp::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'format', 'default'], - ], - \Appwrite\Models\AttributeDatetime::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'format', 'default'], - ], - \Appwrite\Models\AttributeRelationship::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'relatedCollection', 'relationType', 'twoWay', 'twoWayKey', 'onDelete', 'side'], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'relatedCollection', 'relationType', 'twoWay', 'twoWayKey', 'onDelete', 'side'], - ], - \Appwrite\Models\AttributeString::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'size', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'size', 'default', 'encrypt'], - ] - ] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + if (($response['type'] ?? null) === 'string' && ($response['format'] ?? null) === 'email') { + return \Appwrite\Models\AttributeEmail::from($response); + } + + if (($response['type'] ?? null) === 'string' && ($response['format'] ?? null) === 'enum') { + return \Appwrite\Models\AttributeEnum::from($response); + } + + if (($response['type'] ?? null) === 'string' && ($response['format'] ?? null) === 'url') { + return \Appwrite\Models\AttributeUrl::from($response); + } + + if (($response['type'] ?? null) === 'string' && ($response['format'] ?? null) === 'ip') { + return \Appwrite\Models\AttributeIp::from($response); + } + + if (($response['type'] ?? null) === 'boolean') { + return \Appwrite\Models\AttributeBoolean::from($response); + } + + if (($response['type'] ?? null) === 'integer') { + return \Appwrite\Models\AttributeInteger::from($response); + } + + if (($response['type'] ?? null) === 'double') { + return \Appwrite\Models\AttributeFloat::from($response); + } + + if (($response['type'] ?? null) === 'datetime') { + return \Appwrite\Models\AttributeDatetime::from($response); + } + + if (($response['type'] ?? null) === 'relationship') { + return \Appwrite\Models\AttributeRelationship::from($response); + } + + if (($response['type'] ?? null) === 'string') { + return \Appwrite\Models\AttributeString::from($response); + } + + throw new \UnexpectedValueException('Unable to match response to any expected response model.'); } @@ -2694,10 +2745,11 @@ public function listDocuments(string $databaseId, string $collectionId, ?array $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\DocumentList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\DocumentList::from($response); } @@ -2745,10 +2797,11 @@ public function createDocument(string $databaseId, string $collectionId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Document::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Document::from($response); } @@ -2792,10 +2845,11 @@ public function createDocuments(string $databaseId, string $collectionId, array $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\DocumentList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\DocumentList::from($response); } @@ -2840,10 +2894,11 @@ public function upsertDocuments(string $databaseId, string $collectionId, array $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\DocumentList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\DocumentList::from($response); } @@ -2894,10 +2949,11 @@ public function updateDocuments(string $databaseId, string $collectionId, ?array $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\DocumentList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\DocumentList::from($response); } @@ -2942,10 +2998,11 @@ public function deleteDocuments(string $databaseId, string $collectionId, ?array $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\DocumentList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\DocumentList::from($response); } @@ -2994,10 +3051,11 @@ public function getDocument(string $databaseId, string $collectionId, string $do $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Document::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Document::from($response); } @@ -3048,10 +3106,11 @@ public function upsertDocument(string $databaseId, string $collectionId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Document::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Document::from($response); } @@ -3100,10 +3159,11 @@ public function updateDocument(string $databaseId, string $collectionId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Document::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Document::from($response); } @@ -3194,10 +3254,11 @@ public function decrementDocumentAttribute(string $databaseId, string $collectio $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Document::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Document::from($response); } @@ -3247,10 +3308,11 @@ public function incrementDocumentAttribute(string $databaseId, string $collectio $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Document::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Document::from($response); } @@ -3296,10 +3358,11 @@ public function listIndexes(string $databaseId, string $collectionId, ?array $qu $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\IndexList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\IndexList::from($response); } @@ -3354,10 +3417,11 @@ public function createIndex(string $databaseId, string $collectionId, string $ke $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Index::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Index::from($response); } @@ -3395,10 +3459,11 @@ public function getIndex(string $databaseId, string $collectionId, string $key): $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Index::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Index::from($response); } diff --git a/src/Appwrite/Services/Functions.php b/src/Appwrite/Services/Functions.php index fcc035b9..c5c6e913 100644 --- a/src/Appwrite/Services/Functions.php +++ b/src/Appwrite/Services/Functions.php @@ -61,10 +61,11 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\FunctionList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\FunctionList::from($response); } @@ -188,10 +189,11 @@ public function create(string $functionId, string $name, Runtime $runtime, ?arra $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\FunctionModel::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\FunctionModel::from($response); } @@ -220,10 +222,11 @@ public function listRuntimes(): \Appwrite\Models\RuntimeList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\RuntimeList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\RuntimeList::from($response); } @@ -252,10 +255,11 @@ public function listSpecifications(): \Appwrite\Models\SpecificationList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\SpecificationList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\SpecificationList::from($response); } @@ -286,10 +290,11 @@ public function get(string $functionId): \Appwrite\Models\FunctionModel $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\FunctionModel::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\FunctionModel::from($response); } @@ -410,10 +415,11 @@ public function update(string $functionId, string $name, ?Runtime $runtime = nul $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\FunctionModel::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\FunctionModel::from($response); } @@ -480,10 +486,11 @@ public function updateFunctionDeployment(string $functionId, string $deploymentI $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\FunctionModel::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\FunctionModel::from($response); } @@ -530,10 +537,11 @@ public function listDeployments(string $functionId, ?array $queries = null, ?str $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\DeploymentList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\DeploymentList::from($response); } @@ -592,10 +600,11 @@ public function createDeployment(string $functionId, InputFile $code, bool $acti $response = $this->client->call(Client::METHOD_POST, $apiPath, [ 'content-type' => 'multipart/form-data', ], $apiParams); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } } else { $size = filesize($code->getPath()); @@ -607,10 +616,11 @@ public function createDeployment(string $functionId, InputFile $code, bool $acti $response = $this->client->call(Client::METHOD_POST, $apiPath, [ 'content-type' => 'multipart/form-data', ], $apiParams); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } } @@ -658,10 +668,11 @@ public function createDeployment(string $functionId, InputFile $code, bool $acti if(!empty($handle)) { @fclose($handle); } - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -704,10 +715,11 @@ public function createDuplicateDeployment(string $functionId, string $deployment $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -758,10 +770,11 @@ public function createTemplateDeployment(string $functionId, string $repository, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -804,10 +817,11 @@ public function createVcsDeployment(string $functionId, VCSReferenceType $type, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -840,10 +854,11 @@ public function getDeployment(string $functionId, string $deploymentId): \Appwri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -955,10 +970,11 @@ public function updateDeploymentStatus(string $functionId, string $deploymentId) $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -1000,10 +1016,11 @@ public function listExecutions(string $functionId, ?array $queries = null, ?bool $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ExecutionList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ExecutionList::from($response); } @@ -1065,10 +1082,11 @@ public function createExecution(string $functionId, ?string $body = null, ?bool $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Execution::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Execution::from($response); } @@ -1101,10 +1119,11 @@ public function getExecution(string $functionId, string $executionId): \Appwrite $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Execution::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Execution::from($response); } @@ -1169,10 +1188,11 @@ public function listVariables(string $functionId): \Appwrite\Models\VariableList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\VariableList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\VariableList::from($response); } @@ -1214,10 +1234,11 @@ public function createVariable(string $functionId, string $key, string $value, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Variable::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Variable::from($response); } @@ -1250,10 +1271,11 @@ public function getVariable(string $functionId, string $variableId): \Appwrite\M $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Variable::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Variable::from($response); } @@ -1293,10 +1315,11 @@ public function updateVariable(string $functionId, string $variableId, string $k $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Variable::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Variable::from($response); } diff --git a/src/Appwrite/Services/Health.php b/src/Appwrite/Services/Health.php index f37e0943..cb1b2fd9 100644 --- a/src/Appwrite/Services/Health.php +++ b/src/Appwrite/Services/Health.php @@ -40,10 +40,11 @@ public function get(): \Appwrite\Models\HealthStatus $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthStatus::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthStatus::from($response); } @@ -72,10 +73,11 @@ public function getAntivirus(): \Appwrite\Models\HealthAntivirus $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthAntivirus::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthAntivirus::from($response); } @@ -105,10 +107,11 @@ public function getCache(): \Appwrite\Models\HealthStatusList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthStatusList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthStatusList::from($response); } @@ -142,10 +145,11 @@ public function getCertificate(?string $domain = null): \Appwrite\Models\HealthC $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthCertificate::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthCertificate::from($response); } @@ -186,10 +190,11 @@ public function getConsolePausing(?int $threshold = null, ?int $inactivityDays = $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthStatus::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthStatus::from($response); } @@ -218,10 +223,11 @@ public function getDB(): \Appwrite\Models\HealthStatusList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthStatusList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthStatusList::from($response); } @@ -250,10 +256,11 @@ public function getPubSub(): \Appwrite\Models\HealthStatusList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthStatusList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthStatusList::from($response); } @@ -289,10 +296,11 @@ public function getQueueAudits(?int $threshold = null): \Appwrite\Models\HealthQ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -327,10 +335,11 @@ public function getQueueBuilds(?int $threshold = null): \Appwrite\Models\HealthQ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -366,10 +375,11 @@ public function getQueueCertificates(?int $threshold = null): \Appwrite\Models\H $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -409,10 +419,11 @@ public function getQueueDatabases(?string $name = null, ?int $threshold = null): $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -447,10 +458,11 @@ public function getQueueDeletes(?int $threshold = null): \Appwrite\Models\Health $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -487,10 +499,11 @@ public function getFailedJobs(Name $name, ?int $threshold = null): \Appwrite\Mod $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -525,10 +538,11 @@ public function getQueueFunctions(?int $threshold = null): \Appwrite\Models\Heal $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -563,10 +577,11 @@ public function getQueueLogs(?int $threshold = null): \Appwrite\Models\HealthQue $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -601,10 +616,11 @@ public function getQueueMails(?int $threshold = null): \Appwrite\Models\HealthQu $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -639,10 +655,11 @@ public function getQueueMessaging(?int $threshold = null): \Appwrite\Models\Heal $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -677,10 +694,11 @@ public function getQueueMigrations(?int $threshold = null): \Appwrite\Models\Hea $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -715,10 +733,11 @@ public function getQueueStatsResources(?int $threshold = null): \Appwrite\Models $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -753,10 +772,11 @@ public function getQueueUsage(?int $threshold = null): \Appwrite\Models\HealthQu $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -791,10 +811,11 @@ public function getQueueWebhooks(?int $threshold = null): \Appwrite\Models\Healt $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthQueue::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthQueue::from($response); } @@ -823,10 +844,11 @@ public function getStorage(): \Appwrite\Models\HealthStatus $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthStatus::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthStatus::from($response); } @@ -855,10 +877,11 @@ public function getStorageLocal(): \Appwrite\Models\HealthStatus $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthStatus::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthStatus::from($response); } @@ -893,10 +916,11 @@ public function getTime(): \Appwrite\Models\HealthTime $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\HealthTime::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\HealthTime::from($response); } } diff --git a/src/Appwrite/Services/Locale.php b/src/Appwrite/Services/Locale.php index ae2e44d7..87e0a3c8 100644 --- a/src/Appwrite/Services/Locale.php +++ b/src/Appwrite/Services/Locale.php @@ -44,10 +44,11 @@ public function get(): \Appwrite\Models\Locale $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Locale::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Locale::from($response); } @@ -77,10 +78,11 @@ public function listCodes(): \Appwrite\Models\LocaleCodeList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\LocaleCodeList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\LocaleCodeList::from($response); } @@ -110,10 +112,11 @@ public function listContinents(): \Appwrite\Models\ContinentList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ContinentList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ContinentList::from($response); } @@ -143,10 +146,11 @@ public function listCountries(): \Appwrite\Models\CountryList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\CountryList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\CountryList::from($response); } @@ -176,10 +180,11 @@ public function listCountriesEU(): \Appwrite\Models\CountryList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\CountryList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\CountryList::from($response); } @@ -209,10 +214,11 @@ public function listCountriesPhones(): \Appwrite\Models\PhoneList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\PhoneList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PhoneList::from($response); } @@ -243,10 +249,11 @@ public function listCurrencies(): \Appwrite\Models\CurrencyList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\CurrencyList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\CurrencyList::from($response); } @@ -276,10 +283,11 @@ public function listLanguages(): \Appwrite\Models\LanguageList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\LanguageList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\LanguageList::from($response); } } diff --git a/src/Appwrite/Services/Messaging.php b/src/Appwrite/Services/Messaging.php index 3b2fe2a8..769c9c4f 100644 --- a/src/Appwrite/Services/Messaging.php +++ b/src/Appwrite/Services/Messaging.php @@ -56,10 +56,11 @@ public function listMessages(?array $queries = null, ?string $search = null, ?bo $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MessageList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MessageList::from($response); } @@ -137,10 +138,11 @@ public function createEmail(string $messageId, string $subject, string $content, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Message::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Message::from($response); } @@ -197,10 +199,11 @@ public function updateEmail(string $messageId, ?array $topics = null, ?array $us $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Message::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Message::from($response); } @@ -316,10 +319,11 @@ public function createPush(string $messageId, ?string $title = null, ?string $bo $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Message::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Message::from($response); } @@ -390,10 +394,11 @@ public function updatePush(string $messageId, ?array $topics = null, ?array $use $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Message::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Message::from($response); } @@ -449,10 +454,11 @@ public function createSMS(string $messageId, string $content, ?array $topics = n $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Message::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Message::from($response); } @@ -499,10 +505,11 @@ public function updateSMS(string $messageId, ?array $topics = null, ?array $user $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Message::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Message::from($response); } @@ -534,10 +541,11 @@ public function getMessage(string $messageId): \Appwrite\Models\Message $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Message::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Message::from($response); } @@ -611,10 +619,11 @@ public function listMessageLogs(string $messageId, ?array $queries = null, ?bool $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\LogList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\LogList::from($response); } @@ -655,10 +664,11 @@ public function listTargets(string $messageId, ?array $queries = null, ?bool $to $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\TargetList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\TargetList::from($response); } @@ -702,10 +712,11 @@ public function listProviders(?array $queries = null, ?string $search = null, ?b $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ProviderList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ProviderList::from($response); } @@ -766,10 +777,11 @@ public function createAPNSProvider(string $providerId, string $name, ?string $au $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -830,10 +842,11 @@ public function updateAPNSProvider(string $providerId, ?string $name = null, ?bo $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -871,10 +884,11 @@ public function createFCMProvider(string $providerId, string $name, ?array $serv $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -915,10 +929,11 @@ public function updateFCMProvider(string $providerId, ?string $name = null, ?boo $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -986,10 +1001,11 @@ public function createMailgunProvider(string $providerId, string $name, ?string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1060,10 +1076,11 @@ public function updateMailgunProvider(string $providerId, ?string $name = null, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1114,10 +1131,11 @@ public function createMsg91Provider(string $providerId, string $name, ?string $t $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1171,10 +1189,11 @@ public function updateMsg91Provider(string $providerId, ?string $name = null, ?b $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1235,10 +1254,11 @@ public function createResendProvider(string $providerId, string $name, ?string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1302,10 +1322,11 @@ public function updateResendProvider(string $providerId, ?string $name = null, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1366,10 +1387,11 @@ public function createSendgridProvider(string $providerId, string $name, ?string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1433,10 +1455,11 @@ public function updateSendgridProvider(string $providerId, ?string $name = null, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1524,10 +1547,11 @@ public function createSMTPProvider(string $providerId, string $name, string $hos $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1615,10 +1639,11 @@ public function updateSMTPProvider(string $providerId, ?string $name = null, ?st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1669,10 +1694,11 @@ public function createTelesignProvider(string $providerId, string $name, ?string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1726,10 +1752,11 @@ public function updateTelesignProvider(string $providerId, ?string $name = null, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1780,10 +1807,11 @@ public function createTextmagicProvider(string $providerId, string $name, ?strin $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1837,10 +1865,11 @@ public function updateTextmagicProvider(string $providerId, ?string $name = null $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1891,10 +1920,11 @@ public function createTwilioProvider(string $providerId, string $name, ?string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -1948,10 +1978,11 @@ public function updateTwilioProvider(string $providerId, ?string $name = null, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -2002,10 +2033,11 @@ public function createVonageProvider(string $providerId, string $name, ?string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -2059,10 +2091,11 @@ public function updateVonageProvider(string $providerId, ?string $name = null, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -2094,10 +2127,11 @@ public function getProvider(string $providerId): \Appwrite\Models\Provider $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Provider::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Provider::from($response); } @@ -2170,10 +2204,11 @@ public function listProviderLogs(string $providerId, ?array $queries = null, ?bo $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\LogList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\LogList::from($response); } @@ -2214,10 +2249,11 @@ public function listSubscriberLogs(string $subscriberId, ?array $queries = null, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\LogList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\LogList::from($response); } @@ -2261,10 +2297,11 @@ public function listTopics(?array $queries = null, ?string $search = null, ?bool $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\TopicList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\TopicList::from($response); } @@ -2303,10 +2340,11 @@ public function createTopic(string $topicId, string $name, ?array $subscribe = n $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Topic::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Topic::from($response); } @@ -2338,10 +2376,11 @@ public function getTopic(string $topicId): \Appwrite\Models\Topic $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Topic::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Topic::from($response); } @@ -2378,10 +2417,11 @@ public function updateTopic(string $topicId, ?string $name = null, ?array $subsc $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Topic::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Topic::from($response); } @@ -2454,10 +2494,11 @@ public function listTopicLogs(string $topicId, ?array $queries = null, ?bool $to $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\LogList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\LogList::from($response); } @@ -2503,10 +2544,11 @@ public function listSubscribers(string $topicId, ?array $queries = null, ?string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\SubscriberList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\SubscriberList::from($response); } @@ -2542,10 +2584,11 @@ public function createSubscriber(string $topicId, string $subscriberId, string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Subscriber::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Subscriber::from($response); } @@ -2579,10 +2622,11 @@ public function getSubscriber(string $topicId, string $subscriberId): \Appwrite\ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Subscriber::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Subscriber::from($response); } diff --git a/src/Appwrite/Services/Project.php b/src/Appwrite/Services/Project.php index e82fbb62..07796816 100644 --- a/src/Appwrite/Services/Project.php +++ b/src/Appwrite/Services/Project.php @@ -6,6 +6,9 @@ use Appwrite\Client; use Appwrite\Service; use Appwrite\InputFile; +use Appwrite\Enums\Scopes; +use Appwrite\Enums\ProtocolId; +use Appwrite\Enums\ServiceId; class Project extends Service { @@ -14,6 +17,866 @@ public function __construct(Client $client) parent::__construct($client); } + /** + * Get a list of all API keys from the current project. + * + * @param ?array $queries + * @param ?bool $total + * @throws AppwriteException + * @return \Appwrite\Models\KeyList + */ + public function listKeys(?array $queries = null, ?bool $total = null): \Appwrite\Models\KeyList + { + $apiPath = str_replace( + [], + [], + '/project/keys' + ); + + $apiParams = []; + + if (!is_null($queries)) { + $apiParams['queries'] = $queries; + } + + if (!is_null($total)) { + $apiParams['total'] = $total; + } + + $apiHeaders = []; + + $response = $this->client->call( + Client::METHOD_GET, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\KeyList::from($response); + + } + + /** + * Create a new API key. It's recommended to have multiple API keys with + * strict scopes for separate functions within your project. + * + * @param string $keyId + * @param string $name + * @param array $scopes + * @param ?string $expire + * @throws AppwriteException + * @return \Appwrite\Models\Key + */ + public function createKey(string $keyId, string $name, array $scopes, ?string $expire = null): \Appwrite\Models\Key + { + $apiPath = str_replace( + [], + [], + '/project/keys' + ); + + $apiParams = []; + $apiParams['keyId'] = $keyId; + $apiParams['name'] = $name; + $apiParams['scopes'] = $scopes; + $apiParams['expire'] = $expire; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_POST, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Key::from($response); + + } + + /** + * Get a key by its unique ID. + * + * @param string $keyId + * @throws AppwriteException + * @return \Appwrite\Models\Key + */ + public function getKey(string $keyId): \Appwrite\Models\Key + { + $apiPath = str_replace( + ['{keyId}'], + [$keyId], + '/project/keys/{keyId}' + ); + + $apiParams = []; + $apiParams['keyId'] = $keyId; + + $apiHeaders = []; + + $response = $this->client->call( + Client::METHOD_GET, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Key::from($response); + + } + + /** + * Update a key by its unique ID. Use this endpoint to update the name, + * scopes, or expiration time of an API key. + * + * @param string $keyId + * @param string $name + * @param array $scopes + * @param ?string $expire + * @throws AppwriteException + * @return \Appwrite\Models\Key + */ + public function updateKey(string $keyId, string $name, array $scopes, ?string $expire = null): \Appwrite\Models\Key + { + $apiPath = str_replace( + ['{keyId}'], + [$keyId], + '/project/keys/{keyId}' + ); + + $apiParams = []; + $apiParams['keyId'] = $keyId; + $apiParams['name'] = $name; + $apiParams['scopes'] = $scopes; + $apiParams['expire'] = $expire; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_PUT, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Key::from($response); + + } + + /** + * Delete a key by its unique ID. Once deleted, the key can no longer be used + * to authenticate API calls. + * + * @param string $keyId + * @throws AppwriteException + * @return string + */ + public function deleteKey(string $keyId): string + { + $apiPath = str_replace( + ['{keyId}'], + [$keyId], + '/project/keys/{keyId}' + ); + + $apiParams = []; + $apiParams['keyId'] = $keyId; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_DELETE, + $apiPath, + $apiHeaders, + $apiParams + ); + + return $response; + + } + + /** + * Update the project labels. Labels can be used to easily filter projects in + * an organization. + * + * @param array $labels + * @throws AppwriteException + * @return \Appwrite\Models\Project + */ + public function updateLabels(array $labels): \Appwrite\Models\Project + { + $apiPath = str_replace( + [], + [], + '/project/labels' + ); + + $apiParams = []; + $apiParams['labels'] = $labels; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_PUT, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Project::from($response); + + } + + /** + * Get a list of all platforms in the project. This endpoint returns an array + * of all platforms and their configurations. + * + * @param ?array $queries + * @param ?bool $total + * @throws AppwriteException + * @return \Appwrite\Models\PlatformList + */ + public function listPlatforms(?array $queries = null, ?bool $total = null): \Appwrite\Models\PlatformList + { + $apiPath = str_replace( + [], + [], + '/project/platforms' + ); + + $apiParams = []; + + if (!is_null($queries)) { + $apiParams['queries'] = $queries; + } + + if (!is_null($total)) { + $apiParams['total'] = $total; + } + + $apiHeaders = []; + + $response = $this->client->call( + Client::METHOD_GET, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformList::from($response); + + } + + /** + * Create a new Android platform for your project. Use this endpoint to + * register a new Android platform where your users will run your application + * which will interact with the Appwrite API. + * + * @param string $platformId + * @param string $name + * @param string $applicationId + * @throws AppwriteException + * @return \Appwrite\Models\PlatformAndroid + */ + public function createAndroidPlatform(string $platformId, string $name, string $applicationId): \Appwrite\Models\PlatformAndroid + { + $apiPath = str_replace( + [], + [], + '/project/platforms/android' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['applicationId'] = $applicationId; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_POST, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformAndroid::from($response); + + } + + /** + * Update an Android platform by its unique ID. Use this endpoint to update + * the platform's name or application ID. + * + * @param string $platformId + * @param string $name + * @param string $applicationId + * @throws AppwriteException + * @return \Appwrite\Models\PlatformAndroid + */ + public function updateAndroidPlatform(string $platformId, string $name, string $applicationId): \Appwrite\Models\PlatformAndroid + { + $apiPath = str_replace( + ['{platformId}'], + [$platformId], + '/project/platforms/android/{platformId}' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['applicationId'] = $applicationId; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_PUT, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformAndroid::from($response); + + } + + /** + * Create a new Apple platform for your project. Use this endpoint to register + * a new Apple platform where your users will run your application which will + * interact with the Appwrite API. + * + * @param string $platformId + * @param string $name + * @param string $bundleIdentifier + * @throws AppwriteException + * @return \Appwrite\Models\PlatformApple + */ + public function createApplePlatform(string $platformId, string $name, string $bundleIdentifier): \Appwrite\Models\PlatformApple + { + $apiPath = str_replace( + [], + [], + '/project/platforms/apple' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['bundleIdentifier'] = $bundleIdentifier; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_POST, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformApple::from($response); + + } + + /** + * Update an Apple platform by its unique ID. Use this endpoint to update the + * platform's name or bundle identifier. + * + * @param string $platformId + * @param string $name + * @param string $bundleIdentifier + * @throws AppwriteException + * @return \Appwrite\Models\PlatformApple + */ + public function updateApplePlatform(string $platformId, string $name, string $bundleIdentifier): \Appwrite\Models\PlatformApple + { + $apiPath = str_replace( + ['{platformId}'], + [$platformId], + '/project/platforms/apple/{platformId}' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['bundleIdentifier'] = $bundleIdentifier; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_PUT, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformApple::from($response); + + } + + /** + * Create a new Linux platform for your project. Use this endpoint to register + * a new Linux platform where your users will run your application which will + * interact with the Appwrite API. + * + * @param string $platformId + * @param string $name + * @param string $packageName + * @throws AppwriteException + * @return \Appwrite\Models\PlatformLinux + */ + public function createLinuxPlatform(string $platformId, string $name, string $packageName): \Appwrite\Models\PlatformLinux + { + $apiPath = str_replace( + [], + [], + '/project/platforms/linux' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['packageName'] = $packageName; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_POST, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformLinux::from($response); + + } + + /** + * Update a Linux platform by its unique ID. Use this endpoint to update the + * platform's name or package name. + * + * @param string $platformId + * @param string $name + * @param string $packageName + * @throws AppwriteException + * @return \Appwrite\Models\PlatformLinux + */ + public function updateLinuxPlatform(string $platformId, string $name, string $packageName): \Appwrite\Models\PlatformLinux + { + $apiPath = str_replace( + ['{platformId}'], + [$platformId], + '/project/platforms/linux/{platformId}' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['packageName'] = $packageName; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_PUT, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformLinux::from($response); + + } + + /** + * Create a new web platform for your project. Use this endpoint to register a + * new platform where your users will run your application which will interact + * with the Appwrite API. + * + * @param string $platformId + * @param string $name + * @param string $hostname + * @throws AppwriteException + * @return \Appwrite\Models\PlatformWeb + */ + public function createWebPlatform(string $platformId, string $name, string $hostname): \Appwrite\Models\PlatformWeb + { + $apiPath = str_replace( + [], + [], + '/project/platforms/web' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['hostname'] = $hostname; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_POST, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformWeb::from($response); + + } + + /** + * Update a web platform by its unique ID. Use this endpoint to update the + * platform's name or hostname. + * + * @param string $platformId + * @param string $name + * @param string $hostname + * @throws AppwriteException + * @return \Appwrite\Models\PlatformWeb + */ + public function updateWebPlatform(string $platformId, string $name, string $hostname): \Appwrite\Models\PlatformWeb + { + $apiPath = str_replace( + ['{platformId}'], + [$platformId], + '/project/platforms/web/{platformId}' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['hostname'] = $hostname; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_PUT, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformWeb::from($response); + + } + + /** + * Create a new Windows platform for your project. Use this endpoint to + * register a new Windows platform where your users will run your application + * which will interact with the Appwrite API. + * + * @param string $platformId + * @param string $name + * @param string $packageIdentifierName + * @throws AppwriteException + * @return \Appwrite\Models\PlatformWindows + */ + public function createWindowsPlatform(string $platformId, string $name, string $packageIdentifierName): \Appwrite\Models\PlatformWindows + { + $apiPath = str_replace( + [], + [], + '/project/platforms/windows' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['packageIdentifierName'] = $packageIdentifierName; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_POST, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformWindows::from($response); + + } + + /** + * Update a Windows platform by its unique ID. Use this endpoint to update the + * platform's name or package identifier name. + * + * @param string $platformId + * @param string $name + * @param string $packageIdentifierName + * @throws AppwriteException + * @return \Appwrite\Models\PlatformWindows + */ + public function updateWindowsPlatform(string $platformId, string $name, string $packageIdentifierName): \Appwrite\Models\PlatformWindows + { + $apiPath = str_replace( + ['{platformId}'], + [$platformId], + '/project/platforms/windows/{platformId}' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + $apiParams['name'] = $name; + $apiParams['packageIdentifierName'] = $packageIdentifierName; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_PUT, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\PlatformWindows::from($response); + + } + + /** + * Get a platform by its unique ID. This endpoint returns the platform's + * details, including its name, type, and key configurations. + * + * @param string $platformId + * @throws AppwriteException + * @return \Appwrite\Models\PlatformWeb|\Appwrite\Models\PlatformApple|\Appwrite\Models\PlatformAndroid|\Appwrite\Models\PlatformWindows|\Appwrite\Models\PlatformLinux + */ + public function getPlatform(string $platformId): \Appwrite\Models\PlatformWeb|\Appwrite\Models\PlatformApple|\Appwrite\Models\PlatformAndroid|\Appwrite\Models\PlatformWindows|\Appwrite\Models\PlatformLinux + { + $apiPath = str_replace( + ['{platformId}'], + [$platformId], + '/project/platforms/{platformId}' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + + $apiHeaders = []; + + $response = $this->client->call( + Client::METHOD_GET, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + if (($response['type'] ?? null) === 'web') { + return \Appwrite\Models\PlatformWeb::from($response); + } + + if (($response['type'] ?? null) === 'apple') { + return \Appwrite\Models\PlatformApple::from($response); + } + + if (($response['type'] ?? null) === 'android') { + return \Appwrite\Models\PlatformAndroid::from($response); + } + + if (($response['type'] ?? null) === 'windows') { + return \Appwrite\Models\PlatformWindows::from($response); + } + + if (($response['type'] ?? null) === 'linux') { + return \Appwrite\Models\PlatformLinux::from($response); + } + + throw new \UnexpectedValueException('Unable to match response to any expected response model.'); + + } + + /** + * Delete a platform by its unique ID. This endpoint removes the platform and + * all its configurations from the project. + * + * @param string $platformId + * @throws AppwriteException + * @return string + */ + public function deletePlatform(string $platformId): string + { + $apiPath = str_replace( + ['{platformId}'], + [$platformId], + '/project/platforms/{platformId}' + ); + + $apiParams = []; + $apiParams['platformId'] = $platformId; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_DELETE, + $apiPath, + $apiHeaders, + $apiParams + ); + + return $response; + + } + + /** + * Update the status of a specific protocol. Use this endpoint to enable or + * disable a protocol in your project. + * + * @param ProtocolId $protocolId + * @param bool $enabled + * @throws AppwriteException + * @return \Appwrite\Models\Project + */ + public function updateProtocolStatus(ProtocolId $protocolId, bool $enabled): \Appwrite\Models\Project + { + $apiPath = str_replace( + ['{protocolId}'], + [$protocolId], + '/project/protocols/{protocolId}/status' + ); + + $apiParams = []; + $apiParams['protocolId'] = $protocolId; + $apiParams['enabled'] = $enabled; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_PATCH, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Project::from($response); + + } + + /** + * Update the status of a specific service. Use this endpoint to enable or + * disable a service in your project. + * + * @param ServiceId $serviceId + * @param bool $enabled + * @throws AppwriteException + * @return \Appwrite\Models\Project + */ + public function updateServiceStatus(ServiceId $serviceId, bool $enabled): \Appwrite\Models\Project + { + $apiPath = str_replace( + ['{serviceId}'], + [$serviceId], + '/project/services/{serviceId}/status' + ); + + $apiParams = []; + $apiParams['serviceId'] = $serviceId; + $apiParams['enabled'] = $enabled; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + $response = $this->client->call( + Client::METHOD_PATCH, + $apiPath, + $apiHeaders, + $apiParams + ); + + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Project::from($response); + + } + /** * Get a list of all project environment variables. * @@ -49,10 +912,11 @@ public function listVariables(?array $queries = null, ?bool $total = null): \App $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\VariableList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\VariableList::from($response); } @@ -94,10 +958,11 @@ public function createVariable(string $variableId, string $key, string $value, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Variable::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Variable::from($response); } @@ -128,10 +993,11 @@ public function getVariable(string $variableId): \Appwrite\Models\Variable $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Variable::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Variable::from($response); } @@ -169,10 +1035,11 @@ public function updateVariable(string $variableId, ?string $key = null, ?string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Variable::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Variable::from($response); } diff --git a/src/Appwrite/Services/Sites.php b/src/Appwrite/Services/Sites.php index b656a521..6d784d16 100644 --- a/src/Appwrite/Services/Sites.php +++ b/src/Appwrite/Services/Sites.php @@ -61,10 +61,11 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\SiteList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\SiteList::from($response); } @@ -187,10 +188,11 @@ public function create(string $siteId, string $name, Framework $framework, Build $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Site::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Site::from($response); } @@ -220,10 +222,11 @@ public function listFrameworks(): \Appwrite\Models\FrameworkList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\FrameworkList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\FrameworkList::from($response); } @@ -252,10 +255,11 @@ public function listSpecifications(): \Appwrite\Models\SpecificationList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\SpecificationList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\SpecificationList::from($response); } @@ -286,10 +290,11 @@ public function get(string $siteId): \Appwrite\Models\Site $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Site::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Site::from($response); } @@ -415,10 +420,11 @@ public function update(string $siteId, string $name, Framework $framework, ?bool $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Site::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Site::from($response); } @@ -485,10 +491,11 @@ public function updateSiteDeployment(string $siteId, string $deploymentId): \App $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Site::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Site::from($response); } @@ -535,10 +542,11 @@ public function listDeployments(string $siteId, ?array $queries = null, ?string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\DeploymentList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\DeploymentList::from($response); } @@ -598,10 +606,11 @@ public function createDeployment(string $siteId, InputFile $code, ?string $insta $response = $this->client->call(Client::METHOD_POST, $apiPath, [ 'content-type' => 'multipart/form-data', ], $apiParams); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } } else { $size = filesize($code->getPath()); @@ -613,10 +622,11 @@ public function createDeployment(string $siteId, InputFile $code, ?string $insta $response = $this->client->call(Client::METHOD_POST, $apiPath, [ 'content-type' => 'multipart/form-data', ], $apiParams); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } } @@ -664,10 +674,11 @@ public function createDeployment(string $siteId, InputFile $code, ?string $insta if(!empty($handle)) { @fclose($handle); } - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -705,10 +716,11 @@ public function createDuplicateDeployment(string $siteId, string $deploymentId): $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -759,10 +771,11 @@ public function createTemplateDeployment(string $siteId, string $repository, str $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -805,10 +818,11 @@ public function createVcsDeployment(string $siteId, VCSReferenceType $type, stri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -841,10 +855,11 @@ public function getDeployment(string $siteId, string $deploymentId): \Appwrite\M $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -956,10 +971,11 @@ public function updateDeploymentStatus(string $siteId, string $deploymentId): \A $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Deployment::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Deployment::from($response); } @@ -1001,10 +1017,11 @@ public function listLogs(string $siteId, ?array $queries = null, ?bool $total = $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ExecutionList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ExecutionList::from($response); } @@ -1037,10 +1054,11 @@ public function getLog(string $siteId, string $logId): \Appwrite\Models\Executio $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Execution::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Execution::from($response); } @@ -1105,10 +1123,11 @@ public function listVariables(string $siteId): \Appwrite\Models\VariableList $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\VariableList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\VariableList::from($response); } @@ -1150,10 +1169,11 @@ public function createVariable(string $siteId, string $key, string $value, ?bool $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Variable::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Variable::from($response); } @@ -1186,10 +1206,11 @@ public function getVariable(string $siteId, string $variableId): \Appwrite\Model $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Variable::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Variable::from($response); } @@ -1229,10 +1250,11 @@ public function updateVariable(string $siteId, string $variableId, string $key, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Variable::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Variable::from($response); } diff --git a/src/Appwrite/Services/Storage.php b/src/Appwrite/Services/Storage.php index bcc245bb..a8661140 100644 --- a/src/Appwrite/Services/Storage.php +++ b/src/Appwrite/Services/Storage.php @@ -58,10 +58,11 @@ public function listBuckets(?array $queries = null, ?string $search = null, ?boo $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\BucketList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\BucketList::from($response); } @@ -137,10 +138,11 @@ public function createBucket(string $bucketId, string $name, ?array $permissions $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Bucket::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Bucket::from($response); } @@ -172,10 +174,11 @@ public function getBucket(string $bucketId): \Appwrite\Models\Bucket $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Bucket::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Bucket::from($response); } @@ -251,10 +254,11 @@ public function updateBucket(string $bucketId, string $name, ?array $permissions $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Bucket::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Bucket::from($response); } @@ -333,10 +337,11 @@ public function listFiles(string $bucketId, ?array $queries = null, ?string $sea $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\FileList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\FileList::from($response); } @@ -398,10 +403,11 @@ public function createFile(string $bucketId, string $fileId, InputFile $file, ?a $response = $this->client->call(Client::METHOD_POST, $apiPath, [ 'content-type' => 'multipart/form-data', ], $apiParams); - return $this->parseResponse( - $response, - [\Appwrite\Models\File::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\File::from($response); } } else { $size = filesize($file->getPath()); @@ -413,10 +419,11 @@ public function createFile(string $bucketId, string $fileId, InputFile $file, ?a $response = $this->client->call(Client::METHOD_POST, $apiPath, [ 'content-type' => 'multipart/form-data', ], $apiParams); - return $this->parseResponse( - $response, - [\Appwrite\Models\File::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\File::from($response); } } @@ -469,10 +476,11 @@ public function createFile(string $bucketId, string $fileId, InputFile $file, ?a if(!empty($handle)) { @fclose($handle); } - return $this->parseResponse( - $response, - [\Appwrite\Models\File::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\File::from($response); } @@ -506,10 +514,11 @@ public function getFile(string $bucketId, string $fileId): \Appwrite\Models\File $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\File::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\File::from($response); } @@ -551,10 +560,11 @@ public function updateFile(string $bucketId, string $fileId, ?string $name = nul $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\File::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\File::from($response); } diff --git a/src/Appwrite/Services/TablesDB.php b/src/Appwrite/Services/TablesDB.php index 391a8bac..55f7f679 100644 --- a/src/Appwrite/Services/TablesDB.php +++ b/src/Appwrite/Services/TablesDB.php @@ -59,10 +59,11 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\DatabaseList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\DatabaseList::from($response); } @@ -102,10 +103,11 @@ public function create(string $databaseId, string $name, ?bool $enabled = null): $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Database::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Database::from($response); } @@ -139,10 +141,11 @@ public function listTransactions(?array $queries = null): \Appwrite\Models\Trans $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\TransactionList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\TransactionList::from($response); } @@ -177,10 +180,11 @@ public function createTransaction(?int $ttl = null): \Appwrite\Models\Transactio $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Transaction::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Transaction::from($response); } @@ -211,10 +215,11 @@ public function getTransaction(string $transactionId): \Appwrite\Models\Transact $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Transaction::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Transaction::from($response); } @@ -256,10 +261,11 @@ public function updateTransaction(string $transactionId, ?bool $commit = null, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Transaction::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Transaction::from($response); } @@ -328,10 +334,11 @@ public function createOperations(string $transactionId, ?array $operations = nul $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Transaction::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Transaction::from($response); } @@ -363,10 +370,11 @@ public function get(string $databaseId): \Appwrite\Models\Database $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Database::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Database::from($response); } @@ -408,10 +416,11 @@ public function update(string $databaseId, ?string $name = null, ?bool $enabled $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Database::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Database::from($response); } @@ -491,10 +500,11 @@ public function listTables(string $databaseId, ?array $queries = null, ?string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\TableList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\TableList::from($response); } @@ -555,10 +565,11 @@ public function createTable(string $databaseId, string $tableId, string $name, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Table::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Table::from($response); } @@ -592,10 +603,11 @@ public function getTable(string $databaseId, string $tableId): \Appwrite\Models\ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Table::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Table::from($response); } @@ -608,10 +620,11 @@ public function getTable(string $databaseId, string $tableId): \Appwrite\Models\ * @param ?array $permissions * @param ?bool $rowSecurity * @param ?bool $enabled + * @param ?bool $purge * @throws AppwriteException * @return \Appwrite\Models\Table */ - public function updateTable(string $databaseId, string $tableId, ?string $name = null, ?array $permissions = null, ?bool $rowSecurity = null, ?bool $enabled = null): \Appwrite\Models\Table + public function updateTable(string $databaseId, string $tableId, ?string $name = null, ?array $permissions = null, ?bool $rowSecurity = null, ?bool $enabled = null, ?bool $purge = null): \Appwrite\Models\Table { $apiPath = str_replace( ['{databaseId}', '{tableId}'], @@ -636,6 +649,10 @@ public function updateTable(string $databaseId, string $tableId, ?string $name = $apiParams['enabled'] = $enabled; } + if (!is_null($purge)) { + $apiParams['purge'] = $purge; + } + $apiHeaders = []; $apiHeaders['content-type'] = 'application/json'; @@ -646,10 +663,11 @@ public function updateTable(string $databaseId, string $tableId, ?string $name = $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Table::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Table::from($response); } @@ -727,10 +745,11 @@ public function listColumns(string $databaseId, string $tableId, ?array $queries $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnList::from($response); } @@ -776,10 +795,11 @@ public function createBooleanColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnBoolean::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnBoolean::from($response); } @@ -822,10 +842,11 @@ public function updateBooleanColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnBoolean::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnBoolean::from($response); } @@ -870,10 +891,11 @@ public function createDatetimeColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnDatetime::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnDatetime::from($response); } @@ -916,10 +938,11 @@ public function updateDatetimeColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnDatetime::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnDatetime::from($response); } @@ -965,10 +988,11 @@ public function createEmailColumn(string $databaseId, string $tableId, string $k $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnEmail::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnEmail::from($response); } @@ -1012,10 +1036,11 @@ public function updateEmailColumn(string $databaseId, string $tableId, string $k $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnEmail::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnEmail::from($response); } @@ -1063,10 +1088,11 @@ public function createEnumColumn(string $databaseId, string $tableId, string $ke $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnEnum::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnEnum::from($response); } @@ -1112,10 +1138,11 @@ public function updateEnumColumn(string $databaseId, string $tableId, string $ke $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnEnum::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnEnum::from($response); } @@ -1166,10 +1193,11 @@ public function createFloatColumn(string $databaseId, string $tableId, string $k $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnFloat::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnFloat::from($response); } @@ -1217,10 +1245,11 @@ public function updateFloatColumn(string $databaseId, string $tableId, string $k $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnFloat::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnFloat::from($response); } @@ -1271,10 +1300,11 @@ public function createIntegerColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnInteger::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnInteger::from($response); } @@ -1322,10 +1352,11 @@ public function updateIntegerColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnInteger::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnInteger::from($response); } @@ -1371,10 +1402,11 @@ public function createIpColumn(string $databaseId, string $tableId, string $key, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnIp::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnIp::from($response); } @@ -1418,10 +1450,11 @@ public function updateIpColumn(string $databaseId, string $tableId, string $key, $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnIp::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnIp::from($response); } @@ -1461,10 +1494,11 @@ public function createLineColumn(string $databaseId, string $tableId, string $ke $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnLine::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnLine::from($response); } @@ -1507,10 +1541,11 @@ public function updateLineColumn(string $databaseId, string $tableId, string $ke $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnLine::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnLine::from($response); } @@ -1561,10 +1596,11 @@ public function createLongtextColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnLongtext::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnLongtext::from($response); } @@ -1608,10 +1644,11 @@ public function updateLongtextColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnLongtext::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnLongtext::from($response); } @@ -1662,10 +1699,11 @@ public function createMediumtextColumn(string $databaseId, string $tableId, stri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnMediumtext::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnMediumtext::from($response); } @@ -1709,10 +1747,11 @@ public function updateMediumtextColumn(string $databaseId, string $tableId, stri $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnMediumtext::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnMediumtext::from($response); } @@ -1752,10 +1791,11 @@ public function createPointColumn(string $databaseId, string $tableId, string $k $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnPoint::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnPoint::from($response); } @@ -1798,10 +1838,11 @@ public function updatePointColumn(string $databaseId, string $tableId, string $k $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnPoint::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnPoint::from($response); } @@ -1841,10 +1882,11 @@ public function createPolygonColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnPolygon::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnPolygon::from($response); } @@ -1887,10 +1929,11 @@ public function updatePolygonColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnPolygon::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnPolygon::from($response); } @@ -1944,10 +1987,11 @@ public function createRelationshipColumn(string $databaseId, string $tableId, st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnRelationship::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnRelationship::from($response); } @@ -2003,10 +2047,11 @@ public function createStringColumn(string $databaseId, string $tableId, string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnString::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnString::from($response); } @@ -2055,10 +2100,11 @@ public function updateStringColumn(string $databaseId, string $tableId, string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnString::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnString::from($response); } @@ -2109,10 +2155,11 @@ public function createTextColumn(string $databaseId, string $tableId, string $ke $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnText::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnText::from($response); } @@ -2156,10 +2203,11 @@ public function updateTextColumn(string $databaseId, string $tableId, string $ke $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnText::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnText::from($response); } @@ -2205,10 +2253,11 @@ public function createUrlColumn(string $databaseId, string $tableId, string $key $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnUrl::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnUrl::from($response); } @@ -2252,10 +2301,11 @@ public function updateUrlColumn(string $databaseId, string $tableId, string $key $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnUrl::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnUrl::from($response); } @@ -2308,10 +2358,11 @@ public function createVarcharColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnVarchar::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnVarchar::from($response); } @@ -2357,10 +2408,11 @@ public function updateVarcharColumn(string $databaseId, string $tableId, string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnVarchar::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnVarchar::from($response); } @@ -2395,53 +2447,51 @@ public function getColumn(string $databaseId, string $tableId, string $key): \Ap $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnBoolean::class, \Appwrite\Models\ColumnInteger::class, \Appwrite\Models\ColumnFloat::class, \Appwrite\Models\ColumnEmail::class, \Appwrite\Models\ColumnEnum::class, \Appwrite\Models\ColumnUrl::class, \Appwrite\Models\ColumnIp::class, \Appwrite\Models\ColumnDatetime::class, \Appwrite\Models\ColumnRelationship::class, \Appwrite\Models\ColumnString::class] -, - [ - \Appwrite\Models\ColumnBoolean::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'default'], - ], - \Appwrite\Models\ColumnInteger::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'min', 'max', 'default'], - ], - \Appwrite\Models\ColumnFloat::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'min', 'max', 'default'], - ], - \Appwrite\Models\ColumnEmail::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'format', 'default'], - ], - \Appwrite\Models\ColumnEnum::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'elements', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'elements', 'format', 'default'], - ], - \Appwrite\Models\ColumnUrl::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'format', 'default'], - ], - \Appwrite\Models\ColumnIp::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'format', 'default'], - ], - \Appwrite\Models\ColumnDatetime::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'format', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'format', 'default'], - ], - \Appwrite\Models\ColumnRelationship::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'relatedTable', 'relationType', 'twoWay', 'twoWayKey', 'onDelete', 'side'], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'relatedTable', 'relationType', 'twoWay', 'twoWayKey', 'onDelete', 'side'], - ], - \Appwrite\Models\ColumnString::class => [ - 'required' => ['key', 'type', 'status', 'error', 'required', '$createdAt', '$updatedAt', 'size', ], - 'all' => ['key', 'type', 'status', 'error', 'required', 'array', '$createdAt', '$updatedAt', 'size', 'default', 'encrypt'], - ] - ] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + if (($response['type'] ?? null) === 'string' && ($response['format'] ?? null) === 'email') { + return \Appwrite\Models\ColumnEmail::from($response); + } + + if (($response['type'] ?? null) === 'string' && ($response['format'] ?? null) === 'enum') { + return \Appwrite\Models\ColumnEnum::from($response); + } + + if (($response['type'] ?? null) === 'string' && ($response['format'] ?? null) === 'url') { + return \Appwrite\Models\ColumnUrl::from($response); + } + + if (($response['type'] ?? null) === 'string' && ($response['format'] ?? null) === 'ip') { + return \Appwrite\Models\ColumnIp::from($response); + } + + if (($response['type'] ?? null) === 'boolean') { + return \Appwrite\Models\ColumnBoolean::from($response); + } + + if (($response['type'] ?? null) === 'integer') { + return \Appwrite\Models\ColumnInteger::from($response); + } + + if (($response['type'] ?? null) === 'double') { + return \Appwrite\Models\ColumnFloat::from($response); + } + + if (($response['type'] ?? null) === 'datetime') { + return \Appwrite\Models\ColumnDatetime::from($response); + } + + if (($response['type'] ?? null) === 'relationship') { + return \Appwrite\Models\ColumnRelationship::from($response); + } + + if (($response['type'] ?? null) === 'string') { + return \Appwrite\Models\ColumnString::from($response); + } + + throw new \UnexpectedValueException('Unable to match response to any expected response model.'); } @@ -2519,10 +2569,11 @@ public function updateRelationshipColumn(string $databaseId, string $tableId, st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnRelationship::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnRelationship::from($response); } @@ -2565,10 +2616,11 @@ public function listIndexes(string $databaseId, string $tableId, ?array $queries $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnIndexList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnIndexList::from($response); } @@ -2620,10 +2672,11 @@ public function createIndex(string $databaseId, string $tableId, string $key, Ta $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnIndex::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnIndex::from($response); } @@ -2658,10 +2711,11 @@ public function getIndex(string $databaseId, string $tableId, string $key): \App $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ColumnIndex::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ColumnIndex::from($response); } @@ -2751,10 +2805,11 @@ public function listRows(string $databaseId, string $tableId, ?array $queries = $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\RowList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\RowList::from($response); } @@ -2799,10 +2854,11 @@ public function createRow(string $databaseId, string $tableId, string $rowId, ar $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Row::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Row::from($response); } @@ -2843,10 +2899,11 @@ public function createRows(string $databaseId, string $tableId, array $rows, ?st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\RowList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\RowList::from($response); } @@ -2888,10 +2945,11 @@ public function upsertRows(string $databaseId, string $tableId, array $rows, ?st $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\RowList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\RowList::from($response); } @@ -2938,10 +2996,11 @@ public function updateRows(string $databaseId, string $tableId, ?array $data = n $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\RowList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\RowList::from($response); } @@ -2983,10 +3042,11 @@ public function deleteRows(string $databaseId, string $tableId, ?array $queries $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\RowList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\RowList::from($response); } @@ -3032,10 +3092,11 @@ public function getRow(string $databaseId, string $tableId, string $rowId, ?arra $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Row::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Row::from($response); } @@ -3083,10 +3144,11 @@ public function upsertRow(string $databaseId, string $tableId, string $rowId, ?a $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Row::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Row::from($response); } @@ -3132,10 +3194,11 @@ public function updateRow(string $databaseId, string $tableId, string $rowId, ?a $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Row::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Row::from($response); } @@ -3220,10 +3283,11 @@ public function decrementRowColumn(string $databaseId, string $tableId, string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Row::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Row::from($response); } @@ -3270,10 +3334,11 @@ public function incrementRowColumn(string $databaseId, string $tableId, string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Row::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Row::from($response); } } diff --git a/src/Appwrite/Services/Teams.php b/src/Appwrite/Services/Teams.php index 9060489e..fea80312 100644 --- a/src/Appwrite/Services/Teams.php +++ b/src/Appwrite/Services/Teams.php @@ -55,10 +55,11 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\TeamList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\TeamList::from($response); } @@ -99,10 +100,11 @@ public function create(string $teamId, string $name, ?array $roles = null): \App $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Team::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Team::from($response); } @@ -133,10 +135,11 @@ public function get(string $teamId): \Appwrite\Models\Team $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Team::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Team::from($response); } @@ -170,10 +173,11 @@ public function updateName(string $teamId, string $name): \Appwrite\Models\Team $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Team::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Team::from($response); } @@ -254,10 +258,11 @@ public function listMemberships(string $teamId, ?array $queries = null, ?string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MembershipList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MembershipList::from($response); } @@ -336,10 +341,11 @@ public function createMembership(string $teamId, array $roles, ?string $email = $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Membership::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Membership::from($response); } @@ -374,10 +380,11 @@ public function getMembership(string $teamId, string $membershipId): \Appwrite\M $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Membership::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Membership::from($response); } @@ -416,10 +423,11 @@ public function updateMembership(string $teamId, string $membershipId, array $ro $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Membership::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Membership::from($response); } @@ -499,10 +507,11 @@ public function updateMembershipStatus(string $teamId, string $membershipId, str $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Membership::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Membership::from($response); } @@ -535,10 +544,11 @@ public function getPrefs(string $teamId): \Appwrite\Models\Preferences $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Preferences::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Preferences::from($response); } @@ -574,10 +584,11 @@ public function updatePrefs(string $teamId, array $prefs): \Appwrite\Models\Pref $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Preferences::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Preferences::from($response); } } diff --git a/src/Appwrite/Services/Tokens.php b/src/Appwrite/Services/Tokens.php index 684d6504..6b8ea8ad 100644 --- a/src/Appwrite/Services/Tokens.php +++ b/src/Appwrite/Services/Tokens.php @@ -54,10 +54,11 @@ public function list(string $bucketId, string $fileId, ?array $queries = null, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ResourceTokenList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ResourceTokenList::from($response); } @@ -94,10 +95,11 @@ public function createFileToken(string $bucketId, string $fileId, ?string $expir $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ResourceToken::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ResourceToken::from($response); } @@ -128,10 +130,11 @@ public function get(string $tokenId): \Appwrite\Models\ResourceToken $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ResourceToken::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ResourceToken::from($response); } @@ -166,10 +169,11 @@ public function update(string $tokenId, ?string $expire = null): \Appwrite\Model $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\ResourceToken::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\ResourceToken::from($response); } diff --git a/src/Appwrite/Services/Users.php b/src/Appwrite/Services/Users.php index 97792524..d1bb06a0 100644 --- a/src/Appwrite/Services/Users.php +++ b/src/Appwrite/Services/Users.php @@ -58,10 +58,11 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\UserList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\UserList::from($response); } @@ -107,10 +108,11 @@ public function create(string $userId, ?string $email = null, ?string $phone = n $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -154,10 +156,11 @@ public function createArgon2User(string $userId, string $email, string $password $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -201,10 +204,11 @@ public function createBcryptUser(string $userId, string $email, string $password $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -248,10 +252,11 @@ public function listIdentities(?array $queries = null, ?string $search = null, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\IdentityList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\IdentityList::from($response); } @@ -327,10 +332,11 @@ public function createMD5User(string $userId, string $email, string $password, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -374,10 +380,11 @@ public function createPHPassUser(string $userId, string $email, string $password $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -431,10 +438,11 @@ public function createScryptUser(string $userId, string $email, string $password $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -485,10 +493,11 @@ public function createScryptModifiedUser(string $userId, string $email, string $ $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -537,10 +546,11 @@ public function createSHAUser(string $userId, string $email, string $password, ? $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -571,10 +581,11 @@ public function get(string $userId): \Appwrite\Models\User $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -645,10 +656,11 @@ public function updateEmail(string $userId, string $email): \Appwrite\Models\Use $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -687,10 +699,11 @@ public function updateImpersonator(string $userId, bool $impersonator): \Appwrit $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -734,10 +747,11 @@ public function createJWT(string $userId, ?string $sessionId = null, ?int $durat $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Jwt::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Jwt::from($response); } @@ -776,10 +790,11 @@ public function updateLabels(string $userId, array $labels): \Appwrite\Models\Us $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -820,10 +835,11 @@ public function listLogs(string $userId, ?array $queries = null, ?bool $total = $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\LogList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\LogList::from($response); } @@ -869,10 +885,11 @@ public function listMemberships(string $userId, ?array $queries = null, ?string $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MembershipList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MembershipList::from($response); } @@ -906,10 +923,11 @@ public function updateMFA(string $userId, bool $mfa): \Appwrite\Models\User $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -974,10 +992,11 @@ public function listMFAFactors(string $userId): \Appwrite\Models\MfaFactors $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaFactors::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaFactors::from($response); } @@ -1011,10 +1030,11 @@ public function getMFARecoveryCodes(string $userId): \Appwrite\Models\MfaRecover $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaRecoveryCodes::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaRecoveryCodes::from($response); } @@ -1049,10 +1069,11 @@ public function updateMFARecoveryCodes(string $userId): \Appwrite\Models\MfaReco $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaRecoveryCodes::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaRecoveryCodes::from($response); } @@ -1087,10 +1108,11 @@ public function createMFARecoveryCodes(string $userId): \Appwrite\Models\MfaReco $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\MfaRecoveryCodes::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\MfaRecoveryCodes::from($response); } @@ -1124,10 +1146,11 @@ public function updateName(string $userId, string $name): \Appwrite\Models\User $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -1161,10 +1184,11 @@ public function updatePassword(string $userId, string $password): \Appwrite\Mode $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -1198,10 +1222,11 @@ public function updatePhone(string $userId, string $number): \Appwrite\Models\Us $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -1232,10 +1257,11 @@ public function getPrefs(string $userId): \Appwrite\Models\Preferences $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Preferences::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Preferences::from($response); } @@ -1271,10 +1297,11 @@ public function updatePrefs(string $userId, array $prefs): \Appwrite\Models\Pref $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Preferences::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Preferences::from($response); } @@ -1310,10 +1337,11 @@ public function listSessions(string $userId, ?bool $total = null): \Appwrite\Mod $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\SessionList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\SessionList::from($response); } @@ -1350,10 +1378,11 @@ public function createSession(string $userId): \Appwrite\Models\Session $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Session::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Session::from($response); } @@ -1454,10 +1483,11 @@ public function updateStatus(string $userId, bool $status): \Appwrite\Models\Use $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -1498,10 +1528,11 @@ public function listTargets(string $userId, ?array $queries = null, ?bool $total $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\TargetList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\TargetList::from($response); } @@ -1549,10 +1580,11 @@ public function createTarget(string $userId, string $targetId, MessagingProvider $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Target::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Target::from($response); } @@ -1585,10 +1617,11 @@ public function getTarget(string $userId, string $targetId): \Appwrite\Models\Ta $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Target::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Target::from($response); } @@ -1637,10 +1670,11 @@ public function updateTarget(string $userId, string $targetId, ?string $identifi $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Target::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Target::from($response); } @@ -1720,10 +1754,11 @@ public function createToken(string $userId, ?int $length = null, ?int $expire = $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Token::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Token::from($response); } @@ -1757,10 +1792,11 @@ public function updateEmailVerification(string $userId, bool $emailVerification) $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } @@ -1794,10 +1830,11 @@ public function updatePhoneVerification(string $userId, bool $phoneVerification) $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\User::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\User::from($response); } } diff --git a/src/Appwrite/Services/Webhooks.php b/src/Appwrite/Services/Webhooks.php index 4ad755d9..f530b824 100644 --- a/src/Appwrite/Services/Webhooks.php +++ b/src/Appwrite/Services/Webhooks.php @@ -50,10 +50,11 @@ public function list(?array $queries = null, ?bool $total = null): \Appwrite\Mod $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\WebhookList::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\WebhookList::from($response); } @@ -66,13 +67,14 @@ public function list(?array $queries = null, ?bool $total = null): \Appwrite\Mod * @param string $name * @param array $events * @param ?bool $enabled - * @param ?bool $security - * @param ?string $httpUser - * @param ?string $httpPass + * @param ?bool $tls + * @param ?string $authUsername + * @param ?string $authPassword + * @param ?string $secret * @throws AppwriteException * @return \Appwrite\Models\Webhook */ - public function create(string $webhookId, string $url, string $name, array $events, ?bool $enabled = null, ?bool $security = null, ?string $httpUser = null, ?string $httpPass = null): \Appwrite\Models\Webhook + public function create(string $webhookId, string $url, string $name, array $events, ?bool $enabled = null, ?bool $tls = null, ?string $authUsername = null, ?string $authPassword = null, ?string $secret = null): \Appwrite\Models\Webhook { $apiPath = str_replace( [], @@ -90,17 +92,18 @@ public function create(string $webhookId, string $url, string $name, array $even $apiParams['enabled'] = $enabled; } - if (!is_null($security)) { - $apiParams['security'] = $security; + if (!is_null($tls)) { + $apiParams['tls'] = $tls; } - if (!is_null($httpUser)) { - $apiParams['httpUser'] = $httpUser; + if (!is_null($authUsername)) { + $apiParams['authUsername'] = $authUsername; } - if (!is_null($httpPass)) { - $apiParams['httpPass'] = $httpPass; + if (!is_null($authPassword)) { + $apiParams['authPassword'] = $authPassword; } + $apiParams['secret'] = $secret; $apiHeaders = []; $apiHeaders['content-type'] = 'application/json'; @@ -112,10 +115,11 @@ public function create(string $webhookId, string $url, string $name, array $even $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Webhook::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Webhook::from($response); } @@ -147,10 +151,11 @@ public function get(string $webhookId): \Appwrite\Models\Webhook $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Webhook::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Webhook::from($response); } @@ -163,13 +168,13 @@ public function get(string $webhookId): \Appwrite\Models\Webhook * @param string $url * @param array $events * @param ?bool $enabled - * @param ?bool $security - * @param ?string $httpUser - * @param ?string $httpPass + * @param ?bool $tls + * @param ?string $authUsername + * @param ?string $authPassword * @throws AppwriteException * @return \Appwrite\Models\Webhook */ - public function update(string $webhookId, string $name, string $url, array $events, ?bool $enabled = null, ?bool $security = null, ?string $httpUser = null, ?string $httpPass = null): \Appwrite\Models\Webhook + public function update(string $webhookId, string $name, string $url, array $events, ?bool $enabled = null, ?bool $tls = null, ?string $authUsername = null, ?string $authPassword = null): \Appwrite\Models\Webhook { $apiPath = str_replace( ['{webhookId}'], @@ -187,16 +192,16 @@ public function update(string $webhookId, string $name, string $url, array $even $apiParams['enabled'] = $enabled; } - if (!is_null($security)) { - $apiParams['security'] = $security; + if (!is_null($tls)) { + $apiParams['tls'] = $tls; } - if (!is_null($httpUser)) { - $apiParams['httpUser'] = $httpUser; + if (!is_null($authUsername)) { + $apiParams['authUsername'] = $authUsername; } - if (!is_null($httpPass)) { - $apiParams['httpPass'] = $httpPass; + if (!is_null($authPassword)) { + $apiParams['authPassword'] = $authPassword; } $apiHeaders = []; @@ -209,10 +214,11 @@ public function update(string $webhookId, string $name, string $url, array $even $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Webhook::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Webhook::from($response); } @@ -250,24 +256,26 @@ public function delete(string $webhookId): string } /** - * Update the webhook signature key. This endpoint can be used to regenerate - * the signature key used to sign and validate payload deliveries for a - * specific webhook. + * Update the webhook signing key. This endpoint can be used to regenerate the + * signing key used to sign and validate payload deliveries for a specific + * webhook. * * @param string $webhookId + * @param ?string $secret * @throws AppwriteException * @return \Appwrite\Models\Webhook */ - public function updateSignature(string $webhookId): \Appwrite\Models\Webhook + public function updateSecret(string $webhookId, ?string $secret = null): \Appwrite\Models\Webhook { $apiPath = str_replace( ['{webhookId}'], [$webhookId], - '/webhooks/{webhookId}/signature' + '/webhooks/{webhookId}/secret' ); $apiParams = []; $apiParams['webhookId'] = $webhookId; + $apiParams['secret'] = $secret; $apiHeaders = []; $apiHeaders['content-type'] = 'application/json'; @@ -279,10 +287,11 @@ public function updateSignature(string $webhookId): \Appwrite\Models\Webhook $apiParams ); - return $this->parseResponse( - $response, - [\Appwrite\Models\Webhook::class] - ); + if (!is_array($response)) { + throw new \UnexpectedValueException('Expected array response when hydrating a response model.'); + } + + return \Appwrite\Models\Webhook::from($response); } } diff --git a/tests/Appwrite/Services/AccountTest.php b/tests/Appwrite/Services/AccountTest.php index 65a2fc47..da86553d 100644 --- a/tests/Appwrite/Services/AccountTest.php +++ b/tests/Appwrite/Services/AccountTest.php @@ -221,6 +221,7 @@ public function testMethodListLogs(): void "userEmail" => "john@appwrite.io", "userName" => "John Doe", "mode" => "admin", + "userType" => "user", "ip" => "127.0.0.1", "time" => "2020-10-15T06:38:00.000+00:00", "osCode" => "Mac", diff --git a/tests/Appwrite/Services/DatabasesTest.php b/tests/Appwrite/Services/DatabasesTest.php index 54326046..c3c281c4 100644 --- a/tests/Appwrite/Services/DatabasesTest.php +++ b/tests/Appwrite/Services/DatabasesTest.php @@ -1553,14 +1553,20 @@ public function testMethodUpdateVarcharAttribute(): void public function testMethodGetAttribute(): void { - $data = array( - "key" => "isEnabled", - "type" => "boolean", - "status" => "available", - "error" => "string", - "required" => true, - "\$createdAt" => "2020-10-15T06:38:00.000+00:00", - "\$updatedAt" => "2020-10-15T06:38:00.000+00:00" + $data = array_replace( + array( + "key" => "fullName", + "type" => "string", + "status" => "available", + "error" => "string", + "required" => true, + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "size" => 128 + ), + array( + "type" => "string" + ) ); $this->client @@ -1573,7 +1579,7 @@ public function testMethodGetAttribute(): void "" ); - $this->assertInstanceOf(\Appwrite\Models\AttributeBoolean::class, $response); + $this->assertInstanceOf(\Appwrite\Models\AttributeString::class, $response); } public function testMethodDeleteAttribute(): void diff --git a/tests/Appwrite/Services/MessagingTest.php b/tests/Appwrite/Services/MessagingTest.php index f1bcb19e..c967bebe 100644 --- a/tests/Appwrite/Services/MessagingTest.php +++ b/tests/Appwrite/Services/MessagingTest.php @@ -260,6 +260,7 @@ public function testMethodListMessageLogs(): void "userEmail" => "john@appwrite.io", "userName" => "John Doe", "mode" => "admin", + "userType" => "user", "ip" => "127.0.0.1", "time" => "2020-10-15T06:38:00.000+00:00", "osCode" => "Mac", @@ -937,6 +938,7 @@ public function testMethodListProviderLogs(): void "userEmail" => "john@appwrite.io", "userName" => "John Doe", "mode" => "admin", + "userType" => "user", "ip" => "127.0.0.1", "time" => "2020-10-15T06:38:00.000+00:00", "osCode" => "Mac", @@ -979,6 +981,7 @@ public function testMethodListSubscriberLogs(): void "userEmail" => "john@appwrite.io", "userName" => "John Doe", "mode" => "admin", + "userType" => "user", "ip" => "127.0.0.1", "time" => "2020-10-15T06:38:00.000+00:00", "osCode" => "Mac", @@ -1136,6 +1139,7 @@ public function testMethodListTopicLogs(): void "userEmail" => "john@appwrite.io", "userName" => "John Doe", "mode" => "admin", + "userType" => "user", "ip" => "127.0.0.1", "time" => "2020-10-15T06:38:00.000+00:00", "osCode" => "Mac", diff --git a/tests/Appwrite/Services/ProjectTest.php b/tests/Appwrite/Services/ProjectTest.php index c6b648c4..a14223be 100644 --- a/tests/Appwrite/Services/ProjectTest.php +++ b/tests/Appwrite/Services/ProjectTest.php @@ -6,6 +6,9 @@ use Appwrite\InputFile; use Mockery; use PHPUnit\Framework\TestCase; +use Appwrite\Enums\Scopes; +use Appwrite\Enums\ProtocolId; +use Appwrite\Enums\ServiceId; final class ProjectTest extends TestCase { @@ -18,6 +21,911 @@ protected function setUp(): void $this->project = new Project($this->client); } + public function testMethodListKeys(): void + { + $data = array( + "total" => 5, + "keys" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "scopes" => array(), + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ) + ) + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->listKeys(); + + $this->assertInstanceOf(\Appwrite\Models\KeyList::class, $response); + } + + public function testMethodCreateKey(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "scopes" => array(), + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->createKey( + "", + "", + array(Scopes::SESSIONSWRITE()) + ); + + $this->assertInstanceOf(\Appwrite\Models\Key::class, $response); + } + + public function testMethodGetKey(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "scopes" => array(), + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->getKey( + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\Key::class, $response); + } + + public function testMethodUpdateKey(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "scopes" => array(), + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateKey( + "", + "", + array(Scopes::SESSIONSWRITE()) + ); + + $this->assertInstanceOf(\Appwrite\Models\Key::class, $response); + } + + public function testMethodDeleteKey(): void + { + $data = ''; + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->deleteKey( + "" + ); + + $this->assertSame($data, $response); + } + + public function testMethodUpdateLabels(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "New Project", + "description" => "This is a new project.", + "teamId" => "1592981250", + "logo" => "5f5c451b403cb", + "url" => "5f5c451b403cb", + "legalName" => "Company LTD.", + "legalCountry" => "US", + "legalState" => "New York", + "legalCity" => "New York City.", + "legalAddress" => "620 Eighth Avenue, New York, NY 10018", + "legalTaxId" => "131102020", + "authDuration" => 60, + "authLimit" => 100, + "authSessionsLimit" => 10, + "authPasswordHistory" => 5, + "authPasswordDictionary" => true, + "authPersonalDataCheck" => true, + "authDisposableEmails" => true, + "authCanonicalEmails" => true, + "authFreeEmails" => true, + "authMockNumbers" => array( + array( + "phone" => "+1612842323", + "otp" => "123456" + ) + ), + "authSessionAlerts" => true, + "authMembershipsUserName" => true, + "authMembershipsUserEmail" => true, + "authMembershipsMfa" => true, + "authInvalidateSessions" => true, + "oAuthProviders" => array( + array( + "key" => "github", + "name" => "GitHub", + "appId" => "259125845563242502", + "secret" => "Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ", + "enabled" => true + ) + ), + "platforms" => array(), + "webhooks" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Webhook", + "url" => "https://example.com/webhook", + "events" => array(), + "tls" => true, + "authUsername" => "username", + "authPassword" => "password", + "secret" => "ad3d581ca230e2b7059c545e5a", + "enabled" => true, + "logs" => "Failed to connect to remote server.", + "attempts" => 10 + ) + ), + "keys" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "scopes" => array(), + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ) + ), + "devKeys" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "Dev API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ) + ), + "smtpEnabled" => true, + "smtpSenderName" => "John Appwrite", + "smtpSenderEmail" => "john@appwrite.io", + "smtpReplyTo" => "support@appwrite.io", + "smtpHost" => "mail.appwrite.io", + "smtpPort" => 25, + "smtpUsername" => "emailuser", + "smtpPassword" => "securepassword", + "smtpSecure" => "tls", + "pingCount" => 1, + "pingedAt" => "2020-10-15T06:38:00.000+00:00", + "labels" => array(), + "status" => "active", + "authEmailPassword" => true, + "authUsersAuthMagicURL" => true, + "authEmailOtp" => true, + "authAnonymous" => true, + "authInvites" => true, + "authJWT" => true, + "authPhone" => true, + "serviceStatusForAccount" => true, + "serviceStatusForAvatars" => true, + "serviceStatusForDatabases" => true, + "serviceStatusForTablesdb" => true, + "serviceStatusForLocale" => true, + "serviceStatusForHealth" => true, + "serviceStatusForProject" => true, + "serviceStatusForStorage" => true, + "serviceStatusForTeams" => true, + "serviceStatusForUsers" => true, + "serviceStatusForVcs" => true, + "serviceStatusForSites" => true, + "serviceStatusForFunctions" => true, + "serviceStatusForProxy" => true, + "serviceStatusForGraphql" => true, + "serviceStatusForMigrations" => true, + "serviceStatusForMessaging" => true, + "protocolStatusForRest" => true, + "protocolStatusForGraphql" => true, + "protocolStatusForWebsocket" => true, + "region" => "fra", + "billingLimits" => array( + "bandwidth" => 5, + "storage" => 150, + "users" => 200000, + "executions" => 750000, + "GBHours" => 100, + "imageTransformations" => 100, + "authPhone" => 10, + "budgetLimit" => 100 + ), + "blocks" => array( + array( + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "resourceType" => "project", + "resourceId" => "5e5ea5c16897e" + ) + ), + "consoleAccessedAt" => "2020-10-15T06:38:00.000+00:00" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateLabels( + array() + ); + + $this->assertInstanceOf(\Appwrite\Models\Project::class, $response); + } + + public function testMethodListPlatforms(): void + { + $data = array( + "total" => 5, + "platforms" => array() + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->listPlatforms(); + + $this->assertInstanceOf(\Appwrite\Models\PlatformList::class, $response); + } + + public function testMethodCreateAndroidPlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "applicationId" => "com.company.appname" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->createAndroidPlatform( + "", + "", + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformAndroid::class, $response); + } + + public function testMethodUpdateAndroidPlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "applicationId" => "com.company.appname" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateAndroidPlatform( + "", + "", + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformAndroid::class, $response); + } + + public function testMethodCreateApplePlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "bundleIdentifier" => "com.company.appname" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->createApplePlatform( + "", + "", + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformApple::class, $response); + } + + public function testMethodUpdateApplePlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "bundleIdentifier" => "com.company.appname" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateApplePlatform( + "", + "", + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformApple::class, $response); + } + + public function testMethodCreateLinuxPlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "packageName" => "com.company.appname" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->createLinuxPlatform( + "", + "", + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformLinux::class, $response); + } + + public function testMethodUpdateLinuxPlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "packageName" => "com.company.appname" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateLinuxPlatform( + "", + "", + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformLinux::class, $response); + } + + public function testMethodCreateWebPlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "hostname" => "app.example.com" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->createWebPlatform( + "", + "", + "app.example.com" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformWeb::class, $response); + } + + public function testMethodUpdateWebPlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "hostname" => "app.example.com" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateWebPlatform( + "", + "", + "app.example.com" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformWeb::class, $response); + } + + public function testMethodCreateWindowsPlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "packageIdentifierName" => "com.company.appname" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->createWindowsPlatform( + "", + "", + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformWindows::class, $response); + } + + public function testMethodUpdateWindowsPlatform(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "packageIdentifierName" => "com.company.appname" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateWindowsPlatform( + "", + "", + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformWindows::class, $response); + } + + public function testMethodGetPlatform(): void + { + $data = array_replace( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Web App", + "type" => "windows", + "packageName" => "com.company.appname" + ), + array( + "type" => "linux" + ) + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->getPlatform( + "" + ); + + $this->assertInstanceOf(\Appwrite\Models\PlatformLinux::class, $response); + } + + public function testMethodDeletePlatform(): void + { + $data = ''; + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->deletePlatform( + "" + ); + + $this->assertSame($data, $response); + } + + public function testMethodUpdateProtocolStatus(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "New Project", + "description" => "This is a new project.", + "teamId" => "1592981250", + "logo" => "5f5c451b403cb", + "url" => "5f5c451b403cb", + "legalName" => "Company LTD.", + "legalCountry" => "US", + "legalState" => "New York", + "legalCity" => "New York City.", + "legalAddress" => "620 Eighth Avenue, New York, NY 10018", + "legalTaxId" => "131102020", + "authDuration" => 60, + "authLimit" => 100, + "authSessionsLimit" => 10, + "authPasswordHistory" => 5, + "authPasswordDictionary" => true, + "authPersonalDataCheck" => true, + "authDisposableEmails" => true, + "authCanonicalEmails" => true, + "authFreeEmails" => true, + "authMockNumbers" => array( + array( + "phone" => "+1612842323", + "otp" => "123456" + ) + ), + "authSessionAlerts" => true, + "authMembershipsUserName" => true, + "authMembershipsUserEmail" => true, + "authMembershipsMfa" => true, + "authInvalidateSessions" => true, + "oAuthProviders" => array( + array( + "key" => "github", + "name" => "GitHub", + "appId" => "259125845563242502", + "secret" => "Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ", + "enabled" => true + ) + ), + "platforms" => array(), + "webhooks" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Webhook", + "url" => "https://example.com/webhook", + "events" => array(), + "tls" => true, + "authUsername" => "username", + "authPassword" => "password", + "secret" => "ad3d581ca230e2b7059c545e5a", + "enabled" => true, + "logs" => "Failed to connect to remote server.", + "attempts" => 10 + ) + ), + "keys" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "scopes" => array(), + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ) + ), + "devKeys" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "Dev API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ) + ), + "smtpEnabled" => true, + "smtpSenderName" => "John Appwrite", + "smtpSenderEmail" => "john@appwrite.io", + "smtpReplyTo" => "support@appwrite.io", + "smtpHost" => "mail.appwrite.io", + "smtpPort" => 25, + "smtpUsername" => "emailuser", + "smtpPassword" => "securepassword", + "smtpSecure" => "tls", + "pingCount" => 1, + "pingedAt" => "2020-10-15T06:38:00.000+00:00", + "labels" => array(), + "status" => "active", + "authEmailPassword" => true, + "authUsersAuthMagicURL" => true, + "authEmailOtp" => true, + "authAnonymous" => true, + "authInvites" => true, + "authJWT" => true, + "authPhone" => true, + "serviceStatusForAccount" => true, + "serviceStatusForAvatars" => true, + "serviceStatusForDatabases" => true, + "serviceStatusForTablesdb" => true, + "serviceStatusForLocale" => true, + "serviceStatusForHealth" => true, + "serviceStatusForProject" => true, + "serviceStatusForStorage" => true, + "serviceStatusForTeams" => true, + "serviceStatusForUsers" => true, + "serviceStatusForVcs" => true, + "serviceStatusForSites" => true, + "serviceStatusForFunctions" => true, + "serviceStatusForProxy" => true, + "serviceStatusForGraphql" => true, + "serviceStatusForMigrations" => true, + "serviceStatusForMessaging" => true, + "protocolStatusForRest" => true, + "protocolStatusForGraphql" => true, + "protocolStatusForWebsocket" => true, + "region" => "fra", + "billingLimits" => array( + "bandwidth" => 5, + "storage" => 150, + "users" => 200000, + "executions" => 750000, + "GBHours" => 100, + "imageTransformations" => 100, + "authPhone" => 10, + "budgetLimit" => 100 + ), + "blocks" => array( + array( + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "resourceType" => "project", + "resourceId" => "5e5ea5c16897e" + ) + ), + "consoleAccessedAt" => "2020-10-15T06:38:00.000+00:00" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateProtocolStatus( + ProtocolId::REST(), + true + ); + + $this->assertInstanceOf(\Appwrite\Models\Project::class, $response); + } + + public function testMethodUpdateServiceStatus(): void + { + $data = array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "New Project", + "description" => "This is a new project.", + "teamId" => "1592981250", + "logo" => "5f5c451b403cb", + "url" => "5f5c451b403cb", + "legalName" => "Company LTD.", + "legalCountry" => "US", + "legalState" => "New York", + "legalCity" => "New York City.", + "legalAddress" => "620 Eighth Avenue, New York, NY 10018", + "legalTaxId" => "131102020", + "authDuration" => 60, + "authLimit" => 100, + "authSessionsLimit" => 10, + "authPasswordHistory" => 5, + "authPasswordDictionary" => true, + "authPersonalDataCheck" => true, + "authDisposableEmails" => true, + "authCanonicalEmails" => true, + "authFreeEmails" => true, + "authMockNumbers" => array( + array( + "phone" => "+1612842323", + "otp" => "123456" + ) + ), + "authSessionAlerts" => true, + "authMembershipsUserName" => true, + "authMembershipsUserEmail" => true, + "authMembershipsMfa" => true, + "authInvalidateSessions" => true, + "oAuthProviders" => array( + array( + "key" => "github", + "name" => "GitHub", + "appId" => "259125845563242502", + "secret" => "Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ", + "enabled" => true + ) + ), + "platforms" => array(), + "webhooks" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My Webhook", + "url" => "https://example.com/webhook", + "events" => array(), + "tls" => true, + "authUsername" => "username", + "authPassword" => "password", + "secret" => "ad3d581ca230e2b7059c545e5a", + "enabled" => true, + "logs" => "Failed to connect to remote server.", + "attempts" => 10 + ) + ), + "keys" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "My API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "scopes" => array(), + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ) + ), + "devKeys" => array( + array( + "\$id" => "5e5ea5c16897e", + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "name" => "Dev API Key", + "expire" => "2020-10-15T06:38:00.000+00:00", + "secret" => "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt" => "2020-10-15T06:38:00.000+00:00", + "sdks" => array() + ) + ), + "smtpEnabled" => true, + "smtpSenderName" => "John Appwrite", + "smtpSenderEmail" => "john@appwrite.io", + "smtpReplyTo" => "support@appwrite.io", + "smtpHost" => "mail.appwrite.io", + "smtpPort" => 25, + "smtpUsername" => "emailuser", + "smtpPassword" => "securepassword", + "smtpSecure" => "tls", + "pingCount" => 1, + "pingedAt" => "2020-10-15T06:38:00.000+00:00", + "labels" => array(), + "status" => "active", + "authEmailPassword" => true, + "authUsersAuthMagicURL" => true, + "authEmailOtp" => true, + "authAnonymous" => true, + "authInvites" => true, + "authJWT" => true, + "authPhone" => true, + "serviceStatusForAccount" => true, + "serviceStatusForAvatars" => true, + "serviceStatusForDatabases" => true, + "serviceStatusForTablesdb" => true, + "serviceStatusForLocale" => true, + "serviceStatusForHealth" => true, + "serviceStatusForProject" => true, + "serviceStatusForStorage" => true, + "serviceStatusForTeams" => true, + "serviceStatusForUsers" => true, + "serviceStatusForVcs" => true, + "serviceStatusForSites" => true, + "serviceStatusForFunctions" => true, + "serviceStatusForProxy" => true, + "serviceStatusForGraphql" => true, + "serviceStatusForMigrations" => true, + "serviceStatusForMessaging" => true, + "protocolStatusForRest" => true, + "protocolStatusForGraphql" => true, + "protocolStatusForWebsocket" => true, + "region" => "fra", + "billingLimits" => array( + "bandwidth" => 5, + "storage" => 150, + "users" => 200000, + "executions" => 750000, + "GBHours" => 100, + "imageTransformations" => 100, + "authPhone" => 10, + "budgetLimit" => 100 + ), + "blocks" => array( + array( + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "resourceType" => "project", + "resourceId" => "5e5ea5c16897e" + ) + ), + "consoleAccessedAt" => "2020-10-15T06:38:00.000+00:00" + ); + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->project->updateServiceStatus( + ServiceId::ACCOUNT(), + true + ); + + $this->assertInstanceOf(\Appwrite\Models\Project::class, $response); + } + public function testMethodListVariables(): void { $data = array( diff --git a/tests/Appwrite/Services/TablesDBTest.php b/tests/Appwrite/Services/TablesDBTest.php index ce78470f..979085de 100644 --- a/tests/Appwrite/Services/TablesDBTest.php +++ b/tests/Appwrite/Services/TablesDBTest.php @@ -1522,14 +1522,20 @@ public function testMethodUpdateVarcharColumn(): void public function testMethodGetColumn(): void { - $data = array( - "key" => "isEnabled", - "type" => "boolean", - "status" => "available", - "error" => "string", - "required" => true, - "\$createdAt" => "2020-10-15T06:38:00.000+00:00", - "\$updatedAt" => "2020-10-15T06:38:00.000+00:00" + $data = array_replace( + array( + "key" => "fullName", + "type" => "string", + "status" => "available", + "error" => "string", + "required" => true, + "\$createdAt" => "2020-10-15T06:38:00.000+00:00", + "\$updatedAt" => "2020-10-15T06:38:00.000+00:00", + "size" => 128 + ), + array( + "type" => "string" + ) ); $this->client @@ -1542,7 +1548,7 @@ public function testMethodGetColumn(): void "" ); - $this->assertInstanceOf(\Appwrite\Models\ColumnBoolean::class, $response); + $this->assertInstanceOf(\Appwrite\Models\ColumnString::class, $response); } public function testMethodDeleteColumn(): void diff --git a/tests/Appwrite/Services/UsersTest.php b/tests/Appwrite/Services/UsersTest.php index 3b62c0eb..3af694d1 100644 --- a/tests/Appwrite/Services/UsersTest.php +++ b/tests/Appwrite/Services/UsersTest.php @@ -695,6 +695,7 @@ public function testMethodListLogs(): void "userEmail" => "john@appwrite.io", "userName" => "John Doe", "mode" => "admin", + "userType" => "user", "ip" => "127.0.0.1", "time" => "2020-10-15T06:38:00.000+00:00", "osCode" => "Mac", diff --git a/tests/Appwrite/Services/WebhooksTest.php b/tests/Appwrite/Services/WebhooksTest.php index fc8a7ce4..8e57b6e2 100644 --- a/tests/Appwrite/Services/WebhooksTest.php +++ b/tests/Appwrite/Services/WebhooksTest.php @@ -30,10 +30,10 @@ public function testMethodList(): void "name" => "My Webhook", "url" => "https://example.com/webhook", "events" => array(), - "security" => true, - "httpUser" => "username", - "httpPass" => "password", - "signatureKey" => "ad3d581ca230e2b7059c545e5a", + "tls" => true, + "authUsername" => "username", + "authPassword" => "password", + "secret" => "ad3d581ca230e2b7059c545e5a", "enabled" => true, "logs" => "Failed to connect to remote server.", "attempts" => 10 @@ -59,10 +59,10 @@ public function testMethodCreate(): void "name" => "My Webhook", "url" => "https://example.com/webhook", "events" => array(), - "security" => true, - "httpUser" => "username", - "httpPass" => "password", - "signatureKey" => "ad3d581ca230e2b7059c545e5a", + "tls" => true, + "authUsername" => "username", + "authPassword" => "password", + "secret" => "ad3d581ca230e2b7059c545e5a", "enabled" => true, "logs" => "Failed to connect to remote server.", "attempts" => 10 @@ -91,10 +91,10 @@ public function testMethodGet(): void "name" => "My Webhook", "url" => "https://example.com/webhook", "events" => array(), - "security" => true, - "httpUser" => "username", - "httpPass" => "password", - "signatureKey" => "ad3d581ca230e2b7059c545e5a", + "tls" => true, + "authUsername" => "username", + "authPassword" => "password", + "secret" => "ad3d581ca230e2b7059c545e5a", "enabled" => true, "logs" => "Failed to connect to remote server.", "attempts" => 10 @@ -120,10 +120,10 @@ public function testMethodUpdate(): void "name" => "My Webhook", "url" => "https://example.com/webhook", "events" => array(), - "security" => true, - "httpUser" => "username", - "httpPass" => "password", - "signatureKey" => "ad3d581ca230e2b7059c545e5a", + "tls" => true, + "authUsername" => "username", + "authPassword" => "password", + "secret" => "ad3d581ca230e2b7059c545e5a", "enabled" => true, "logs" => "Failed to connect to remote server.", "attempts" => 10 @@ -158,7 +158,7 @@ public function testMethodDelete(): void $this->assertSame($data, $response); } - public function testMethodUpdateSignature(): void + public function testMethodUpdateSecret(): void { $data = array( "\$id" => "5e5ea5c16897e", @@ -167,10 +167,10 @@ public function testMethodUpdateSignature(): void "name" => "My Webhook", "url" => "https://example.com/webhook", "events" => array(), - "security" => true, - "httpUser" => "username", - "httpPass" => "password", - "signatureKey" => "ad3d581ca230e2b7059c545e5a", + "tls" => true, + "authUsername" => "username", + "authPassword" => "password", + "secret" => "ad3d581ca230e2b7059c545e5a", "enabled" => true, "logs" => "Failed to connect to remote server.", "attempts" => 10 @@ -180,7 +180,7 @@ public function testMethodUpdateSignature(): void ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) ->andReturn($data); - $response = $this->webhooks->updateSignature( + $response = $this->webhooks->updateSecret( "" );