diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 9d6785309a..658b200ec6 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -55,7 +55,7 @@ App::post('/v1/account') ->param('password', '', new Password(), 'User password. Must be between 6 to 32 chars.') ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->action(function ($email, $password, $name, $request, $response, $project, $projectDB, $webhooks, $audits) use ($oauth2Keys) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $projectDB */ @@ -160,7 +160,7 @@ App::post('/v1/account/sessions') ->param('email', '', new Email(), 'User email.') ->param('password', '', new Password(), 'User password. Must be between 6 to 32 chars.') ->action(function ($email, $password, $request, $response, $projectDB, $webhooks, $audits) { - /** @var Appwrite\Swoole\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ @@ -261,7 +261,7 @@ App::get('/v1/account/sessions/oauth2/:provider') ->param('failure', $oauthDefaultFailure, function ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project 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.', true, ['clients']) ->param('scopes', [], new ArrayList(new Text(128)), 'A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes.', true) ->action(function ($provider, $success, $failure, $scopes, $request, $response, $project) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ @@ -306,7 +306,7 @@ App::get('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->param('code', '', new Text(1024), 'OAuth2 code.') ->param('state', '', new Text(2048), 'Login state params.', true) ->action(function ($projectId, $provider, $code, $state, $request, $response) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ $domain = $request->getHostname(); @@ -331,7 +331,7 @@ App::post('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->param('code', '', new Text(1024), 'OAuth2 code.') ->param('state', '', new Text(2048), 'Login state params.', true) ->action(function ($projectId, $provider, $code, $state, $request, $response) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ $domain = $request->getHostname(); @@ -357,7 +357,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') ->param('code', '', new Text(1024), 'OAuth2 code.') ->param('state', '', new Text(2048), 'OAuth2 state params.', true) ->action(function ($provider, $code, $state, $request, $response, $project, $user, $projectDB, $audits) use ($oauthDefaultSuccess) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ @@ -944,7 +944,7 @@ App::delete('/v1/account') ->label('sdk.method', 'delete') ->label('sdk.description', '/docs/references/account/delete.md') ->action(function ($request, $response, $user, $projectDB, $audits, $webhooks) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -1007,7 +1007,7 @@ App::delete('/v1/account/sessions/:sessionId') ->label('abuse-limit', 100) ->param('sessionId', null, new UID(), 'Session unique ID. Use the string \'current\' to delete the current device session.') ->action(function ($sessionId, $request, $response, $user, $projectDB, $audits, $webhooks) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -1071,7 +1071,7 @@ App::delete('/v1/account/sessions') ->label('sdk.description', '/docs/references/account/delete-sessions.md') ->label('abuse-limit', 100) ->action(function ($request, $response, $user, $projectDB, $audits, $webhooks) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -1129,7 +1129,7 @@ App::post('/v1/account/recovery') ->param('email', '', new Email(), 'User email.') ->param('url', '', function ($clients) { return new Host($clients); }, 'URL to redirect the user back to your app from the recovery email. Only URLs from hostnames in your project 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.', false, ['clients']) ->action(function ($email, $url, $request, $response, $projectDB, $project, $locale, $mails, $audits) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Database\Document $project */ @@ -1306,7 +1306,7 @@ App::post('/v1/account/verification') ->label('abuse-key', 'url:{url},email:{param-email}') ->param('url', '', function ($clients) { return new Host($clients); }, 'URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project 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.', false, ['clients']) // TODO add built-in confirm page ->action(function ($url, $request, $response, $project, $user, $projectDB, $locale, $audits, $mails) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index bd19935754..a24de80887 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -529,7 +529,7 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId') ->param('collectionId', null, new UID(), 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).') ->param('documentId', null, new UID(), 'Document unique ID.') ->action(function ($collectionId, $documentId, $request, $response, $projectDB) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index aa6fa92780..26b90cfea2 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -12,7 +12,7 @@ App::get('/v1/locale') ->label('sdk.method', 'get') ->label('sdk.description', '/docs/references/locale/get-locale.md') ->action(function ($request, $response, $locale, $geodb) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Utopia\Locale\Locale $locale */ /** @var MaxMind\Db\Reader $geodb */ diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 18cfb58f46..55ae740373 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -37,7 +37,7 @@ App::post('/v1/storage/files') ->param('read', [], new ArrayList(new Text(64)), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('write', [], new ArrayList(new Text(64)), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->action(function ($file, $read, $write, $request, $response, $user, $projectDB, $webhooks, $audits, $usage) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -233,7 +233,7 @@ App::get('/v1/storage/files/:fileId/preview') ->param('background', '', new HexColor(), 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true) ->param('output', '', new WhiteList(\array_keys(Config::getParam('storage-outputs')), true), 'Output format type (jpeg, jpg, png, gif and webp).', true) ->action(function ($fileId, $width, $height, $quality, $background, $output, $request, $response, $project, $projectDB) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $projectDB */ diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index ae9e44015f..ab0db7a259 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -480,7 +480,7 @@ App::patch('/v1/teams/:teamId/memberships/:inviteId/status') ->param('userId', '', new UID(), 'User unique ID.') ->param('secret', '', new Text(256), 'Secret key.') ->action(function ($teamId, $inviteId, $userId, $secret, $request, $response, $user, $projectDB, $audits) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ diff --git a/app/controllers/general.php b/app/controllers/general.php index 5aae62ac3c..b83630a23d 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -3,7 +3,7 @@ require_once __DIR__.'/../init.php'; use Utopia\App; -use Appwrite\Swoole\Request; +use Utopia\Swoole\Request; use Appwrite\Utopia\Response; use Utopia\View; use Utopia\Exception; @@ -22,7 +22,7 @@ Config::setParam('cookieDomain', 'localhost'); Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE); App::init(function ($utopia, $request, $response, $console, $project, $user, $locale, $webhooks, $audits, $usage, $clients) { - /** @var Appwrite\Swoole\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $console */ /** @var Appwrite\Database\Document $project */ @@ -246,7 +246,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo App::shutdown(function ($utopia, $request, $response, $project, $webhooks, $audits, $usage, $deletes, $mode) { /** @var Utopia\App $utopia */ - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Event\Event $webhooks */ @@ -282,7 +282,7 @@ App::shutdown(function ($utopia, $request, $response, $project, $webhooks, $audi }, ['utopia', 'request', 'response', 'project', 'webhooks', 'audits', 'usage', 'deletes', 'mode']); App::options(function ($request, $response) { - /** @var Appwrite\Swoole\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ $origin = $request->getOrigin(); @@ -300,7 +300,7 @@ App::options(function ($request, $response) { App::error(function ($error, $utopia, $request, $response, $layout, $project) { /** @var Exception $error */ /** @var Utopia\App $utopia */ - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\View $layout */ /** @var Appwrite\Database\Document $project */ diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 3fdca7cf17..a1a4d6cf65 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -7,7 +7,7 @@ use Utopia\Abuse\Adapters\TimeLimit; App::init(function ($utopia, $request, $response, $project, $user, $register) { /** @var Utopia\App $utopia */ - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index 3452cd3535..383685e0d0 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -5,7 +5,7 @@ use Utopia\Config\Config; App::init(function ($utopia, $request, $response, $layout) { /** @var Utopia\App $utopia */ - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Utopia\View $layout */ diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index a6c2491c0f..f2cf21ffd5 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -189,7 +189,7 @@ App::get('/open-api-2.json') ->param('tests', 0, new Range(0, 1), 'Include only test services.', true) ->action(function ($platform, $extensions, $tests, $utopia, $request, $response) { /** @var Utopia\App $utopia */ - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ $security = [ diff --git a/app/http.php b/app/http.php index 89b3d1f9e8..07e0fff45e 100644 --- a/app/http.php +++ b/app/http.php @@ -2,9 +2,9 @@ require_once __DIR__.'/../vendor/autoload.php'; -use Appwrite\Swoole\Files; -use Appwrite\Swoole\Request; -use Appwrite\Swoole\Response; +use Utopia\Swoole\Files; +use Utopia\Swoole\Request; +use Appwrite\Utopia\Response; use Swoole\Process; use Swoole\Http\Server; use Swoole\Http\Request as SwooleRequest; diff --git a/app/init.php b/app/init.php index d24ca9d281..8c3457dd3a 100644 --- a/app/init.php +++ b/app/init.php @@ -361,7 +361,7 @@ App::setResource('clients', function($console, $project) { }, ['console', 'project']); App::setResource('user', function($mode, $project, $console, $request, $response, $projectDB, $consoleDB) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $consoleDB */ @@ -423,7 +423,7 @@ App::setResource('user', function($mode, $project, $console, $request, $response }, ['mode', 'project', 'console', 'request', 'response', 'projectDB', 'consoleDB']); App::setResource('project', function($consoleDB, $request) { - /** @var Appwrite\Swoole\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Database\Database $consoleDB */ Authorization::disable(); @@ -460,11 +460,11 @@ App::setResource('projectDB', function($register, $project) { }, ['register', 'project']); App::setResource('mode', function($request) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ return $request->getParam('mode', $request->getHeader('x-appwrite-mode', 'default')); }, ['request']); App::setResource('geodb', function($request) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ return new Reader(__DIR__.'/db/DBIP/dbip-country-lite-2020-01.mmdb'); }, ['request']); diff --git a/composer.json b/composer.json index bf121686a8..1a60237d43 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "utopia-php/registry": "0.2.*", "utopia-php/preloader": "0.2.*", "utopia-php/domains": "0.2.*", + "utopia-php/swoole": "0.2.*", "resque/php-resque": "1.3.6", "piwik/device-detector": "3.13.0", diff --git a/src/Appwrite/Swoole/Files.php b/src/Appwrite/Swoole/Files.php deleted file mode 100644 index 7971beba2b..0000000000 --- a/src/Appwrite/Swoole/Files.php +++ /dev/null @@ -1,176 +0,0 @@ - 'text/css', - 'js' => 'text/javascript', - 'svg' => 'image/svg+xml', - ]; - - /** - * Add MimeType - * - * @var string $mimeType - * - * @return void - */ - public static function addMimeType(string $mimeType): void - { - self::$mimeTypes[$mimeType] = true; - } - - /** - * Remove MimeType - * - * @var string $mimeType - * - * @return void - */ - public static function removeMimeType(string $mimeType): void - { - if(isset(self::$mimeTypes[$mimeType])) { - unset(self::$mimeTypes[$mimeType]); - } - } - - /** - * Get MimeType List - * - * @return array - */ - public static function getMimeTypes(): array - { - return self::$mimeTypes; - } - - /** - * Get Files Loaded Count - * - * @return int - */ - public static function getCount(): int - { - return self::$count; - } - - /** - * Load - * - * @var string $path - * - * @return void - */ - public static function load(string $directory, string $root = null): void - { - if(!is_readable($directory)) { - throw new Exception('Failed to load directory: '.$directory); - } - - $directory = realpath($directory); - - $root = ($root) ? $root : $directory; - - $handle = opendir($directory); - - while ($path = readdir($handle)) { - $extension = pathinfo($path, PATHINFO_EXTENSION); - - if (in_array($path, ['.', '..'])) { - continue; - } - - if (in_array($extension, ['php', 'phtml'])) { - continue; - } - - if(substr($path, 0, 1) === '.') { - continue; - } - - if (is_dir($directory.'/'.$path)) { - self::load($directory.'/'.$path, $root); - continue; - } - - self::$count++; - - self::$loaded[substr($directory.'/'.$path , strlen($root))] = [ - 'contents' => file_get_contents($directory.'/'.$path), - 'mimeType' => (array_key_exists($extension, self::$extensions)) - ? self::$extensions[$extension] - : mime_content_type($directory.'/'.$path) - ]; - } - - closedir($handle); - - if($directory === $root) { - echo '[Static Files] Loadded '.self::$count.' files'.PHP_EOL; - } - } - - /** - * Is File Loaded - * - * @var string $uri - */ - public static function isFileLoaded(string $uri): bool - { - if(!array_key_exists($uri, self::$loaded)) { - return false; - } - - return true; - } - - /** - * Get File Contants - * - * @var string $uri - */ - public static function getFileContents(string $uri): string - { - if(!array_key_exists($uri, self::$loaded)) { - throw new Exception('File not found or not loaded: '.$uri); - } - - return self::$loaded[$uri]['contents']; - } - - /** - * Get File MimeType - * - * @var string $uri - */ - public static function getFileMimeType(string $uri): string - { - if(!array_key_exists($uri, self::$loaded)) { - throw new Exception('File not found or not loaded: '.$uri); - } - - return self::$loaded[$uri]['mimeType']; - } -} diff --git a/src/Appwrite/Swoole/Request.php b/src/Appwrite/Swoole/Request.php deleted file mode 100644 index 4535924686..0000000000 --- a/src/Appwrite/Swoole/Request.php +++ /dev/null @@ -1,339 +0,0 @@ -swoole = $request; - } - - /** - * Get Param - * - * Get param by current method name - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function getParam(string $key, $default = null) - { - switch($this->getMethod()) { - case self::METHOD_GET: - return $this->getQuery($key, $default); - break; - case self::METHOD_POST: - case self::METHOD_PUT: - case self::METHOD_PATCH: - case self::METHOD_DELETE: - return $this->getPayload($key, $default); - break; - default: - return $this->getQuery($key, $default); - } - } - - /** - * Get Params - * - * Get all params of current method - * - * @return array - */ - public function getParams(): array - { - switch($this->getMethod()) { - case self::METHOD_GET: - return (!empty($this->swoole->get)) ? $this->swoole->get : []; - break; - case self::METHOD_POST: - case self::METHOD_PUT: - case self::METHOD_PATCH: - case self::METHOD_DELETE: - return $this->generateInput(); - break; - default: - return (!empty($this->swoole->get)) ? $this->swoole->get : []; - } - - return []; - } - - /** - * Get Query - * - * Method for querying HTTP GET request parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function getQuery(string $key, $default = null) - { - return (isset($this->swoole->get[$key])) ? $this->swoole->get[$key] : $default; - } - - /** - * Get payload - * - * Method for querying HTTP request payload parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function getPayload(string $key, $default = null) - { - $payload = $this->generateInput(); - - return (isset($payload[$key])) ? $payload[$key] : $default; - } - - /** - * Get server - * - * Method for querying server parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function getServer(string $key, $default = null) - { - return (isset($this->swoole->server) && isset($this->swoole->server[$key])) ? $this->swoole->server[$key] : $default; - } - - /** - * Get IP - * - * Returns users IP address. - * Support HTTP_X_FORWARDED_FOR header usually return - * from different proxy servers or PHP default REMOTE_ADDR - */ - public function getIP(): string - { - return $this->getHeader('x-forwarded-for', $this->getServer('remote_addr', '0.0.0.0')); - } - - /** - * Get Protocol - * - * Returns request protocol. - * Support HTTP_X_FORWARDED_PROTO header usually return - * from different proxy servers or PHP default REQUEST_SCHEME - * - * @return string - */ - public function getProtocol(): string - { - $protocol = $this->getHeader('x-forwarded-proto', $this->getServer('server_protocol', 'https')); - - if($protocol === 'HTTP/1.1') { - return 'http'; - } - - return $protocol; - } - - /** - * Get Port - * - * Returns request port. - * - * @return string - */ - public function getPort(): string - { - return $this->getHeader('x-forwarded-port', (string)\parse_url($this->getProtocol().'://'.$this->getHeader('x-forwarded-host', $this->getHeader('host')), PHP_URL_PORT)); - } - - /** - * Get Hostname - * - * Returns request hostname. - * - * @return string - */ - public function getHostname(): string - { - return \parse_url($this->getProtocol().'://'.$this->getHeader('x-forwarded-host', $this->getHeader('host')), PHP_URL_HOST); - } - - /** - * Get Method - * - * Return HTTP request method - * - * @return string - */ - public function getMethod(): string - { - return $this->getServer('request_method', 'UNKNOWN'); - } - - /** - * Get URI - * - * Return HTTP request URI - * - * @return string - */ - public function getURI(): string - { - return $this->getServer('request_uri', ''); - } - - /** - * Get Referer - * - * Return HTTP referer header - * - * @return string - */ - public function getReferer(string $default = ''): string - { - return $this->getHeader('referer', ''); - } - - /** - * Get Origin - * - * Return HTTP origin header - * - * @return string - */ - public function getOrigin(string $default = ''): string - { - return $this->getHeader('origin', $default); - } - - /** - * Get User Agent - * - * Return HTTP user agent header - * - * @return string - */ - public function getUserAgent(string $default = ''): string - { - return $this->getHeader('user-agent', $default); - } - - /** - * Get Accept - * - * Return HTTP accept header - * - * @return string - */ - public function getAccept(string $default = ''): string - { - return $this->getHeader('accept', $default); - } - - /** - * Get files - * - * Method for querying upload files data. If $key is not found empty array will be returned. - * - * @param string $key - * @return array - */ - public function getFiles($key): array - { - $key = strtolower($key); - return (isset($this->swoole->files[$key])) ? $this->swoole->files[$key] : []; - } - - /** - * Get cookie - * - * Method for querying HTTP cookie parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param string $default - * - * @return string - */ - public function getCookie(string $key, string $default = ''): string - { - $key = strtolower($key); - return (isset($this->swoole->cookie[$key])) ? $this->swoole->cookie[$key] : $default; - } - - /** - * Get header - * - * Method for querying HTTP header parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param string $default - * @return string - */ - public function getHeader(string $key, string $default = ''): string - { - return (isset($this->swoole->header[$key])) ? $this->swoole->header[$key] : $default; - } - - /** - * Generate input - * - * Generate PHP input stream and parse it as an array in order to handle different content type of requests - * - * @return array - */ - protected function generateInput(): array - { - if (null === $this->payload) { - $contentType = $this->getHeader('content-type'); - - // Get content-type without the charset - $length = strpos($contentType, ';'); - $length = (empty($length)) ? strlen($contentType) : $length; - $contentType = substr($contentType, 0, $length); - - switch ($contentType) { - case 'application/json': - $this->payload = json_decode($this->swoole->rawContent(), true); - break; - - default: - $this->payload = $this->swoole->post; - break; - } - - if(empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed - $this->payload = []; - } - } - - return $this->payload; - } - - /** - * Generate headers - * - * Parse request headers as an array for easy querying using the getHeader method - * - * @return array - */ - protected function generateHeaders(): array - { - return $this->swoole->header; - } -} \ No newline at end of file diff --git a/src/Appwrite/Swoole/Response.php b/src/Appwrite/Swoole/Response.php deleted file mode 100644 index 7661011460..0000000000 --- a/src/Appwrite/Swoole/Response.php +++ /dev/null @@ -1,138 +0,0 @@ - true, - 'text/css' => true, - 'text/javascript' => true, - 'application/javascript' => true, - 'text/html' => true, - 'text/html; charset=UTF-8' => true, - 'application/json' => true, - 'application/json; charset=UTF-8' => true, - 'image/svg+xml' => true, - 'application/xml+rss' => true, - ]; - - /** - * Response constructor. - */ - public function __construct(SwooleResponse $response) - { - $this->swoole = $response; - parent::__construct(\microtime(true)); - } - - /** - * Output response - * - * Generate HTTP response output including the response header (+cookies) and body and prints them. - * - * @param string $body - * @param int $exit exit code or don't exit if code is null - * - * @return void - */ - public function send(string $body = '', int $exit = null): void - { - if(!$this->disablePayload) { - $this->addHeader('X-Debug-Speed', (string)(microtime(true) - $this->startTime)); - - $this - ->appendCookies() - ->appendHeaders() - ; - - $chunk = 2000000; // Max chunk of 2 mb - $length = strlen($body); - - $this->size = $this->size + strlen(implode("\n", $this->headers)) + $length; - - if(array_key_exists( - $this->contentType, - $this->compressed - ) && ($length <= $chunk)) { // Dont compress with GZIP / Brotli if header is not listed and size is bigger than 2mb - $this->swoole->end($body); - } - else { - for ($i=0; $i < ceil($length / $chunk); $i++) { - $this->swoole->write(substr($body, ($i * $chunk), min((($i * $chunk) + $chunk), $length))); - } - - $this->swoole->end(); - } - - $this->disablePayload(); - } - } - - /** - * Append headers - * - * Iterating over response headers to generate them using native PHP header function. - * This method is also responsible for generating the response and content type headers. - * - * @return self - */ - protected function appendHeaders(): self - { - // Send status code header - $this->swoole->status((string)$this->statusCode); - - // Send content type header - $this - ->addHeader('Content-Type', $this->contentType) - ; - - // Set application headers - foreach ($this->headers as $key => $value) { - $this->swoole->header($key, $value); - } - - return $this; - } - - /** - * Append cookies - * - * Iterating over response cookies to generate them using native PHP cookie function. - * - * @return self - */ - protected function appendCookies(): self - { - foreach ($this->cookies as $cookie) { - $this->swoole->cookie( - $cookie['name'], - $cookie['value'], - $cookie['expire'], - $cookie['path'], - $cookie['domain'], - $cookie['secure'], - $cookie['httponly'], - $cookie['samesite'], - ); - } - - return $this; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index b2a9f5b5dd..66d1eaf18a 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -3,46 +3,79 @@ namespace Appwrite\Utopia; use Exception; +use Utopia\Swoole\Response as SwooleResponse; +use Swoole\Http\Response as SwooleHTTPResponse; use Appwrite\Database\Document; use Appwrite\Utopia\Response\Model; +use Appwrite\Utopia\Response\Model\Any; +use Appwrite\Utopia\Response\Model\BaseList; +use Appwrite\Utopia\Response\Model\Collection; +use Appwrite\Utopia\Response\Model\Continent; +use Appwrite\Utopia\Response\Model\Country; +use Appwrite\Utopia\Response\Model\Currency; +use Appwrite\Utopia\Response\Model\Domain; use Appwrite\Utopia\Response\Model\Error; use Appwrite\Utopia\Response\Model\ErrorDev; +use Appwrite\Utopia\Response\Model\Execution; +use Appwrite\Utopia\Response\Model\File; +use Appwrite\Utopia\Response\Model\Func; +use Appwrite\Utopia\Response\Model\Key; +use Appwrite\Utopia\Response\Model\Language; use Appwrite\Utopia\Response\Model\User; use Appwrite\Utopia\Response\Model\Session; use Appwrite\Utopia\Response\Model\Team; -use Appwrite\Utopia\Response\Model\TeamList; use Appwrite\Utopia\Response\Model\Locale; +use Appwrite\Utopia\Response\Model\Log; use Appwrite\Utopia\Response\Model\Membership; -use Appwrite\Utopia\Response\Model\MembershipList; -use Utopia\Response as UtopiaResponse; +use Appwrite\Utopia\Response\Model\Phone; +use Appwrite\Utopia\Response\Model\Platform; +use Appwrite\Utopia\Response\Model\Project; +use Appwrite\Utopia\Response\Model\Rule; +use Appwrite\Utopia\Response\Model\Tag; +use Appwrite\Utopia\Response\Model\Task; +use Appwrite\Utopia\Response\Model\Webhook; -class Response extends UtopiaResponse +class Response extends SwooleResponse { // General - const MODEL_LOG = 'log'; // - Missing + const MODEL_ANY = 'any'; + const MODEL_LOG = 'log'; + const MODEL_LOG_LIST = 'logList'; const MODEL_ERROR = 'error'; const MODEL_ERROR_DEV = 'errorDev'; const MODEL_BASE_LIST = 'baseList'; + const MODEL_PERMISSIONS = 'permissions'; + // Database + const MODEL_COLLECTION = 'collection'; + const MODEL_COLLECTION_LIST = 'collectionList'; + const MODEL_RULE = 'rule'; + const MODEL_DOCUMENT_LIST = 'documentList'; + // Users const MODEL_USER = 'user'; + const MODEL_USER_LIST = 'userList'; const MODEL_SESSION = 'session'; + const MODEL_SESSION_LIST = 'sessionList'; const MODEL_TOKEN = 'token'; // - Missing - - // Database - const MODEL_COLLECTION = 'collection'; // - Missing + // Storage + const MODEL_FILE = 'file'; + const MODEL_FILE_LIST = 'fileList'; + const MODEL_BUCKET = 'bucket'; // - Missing + // Locale const MODEL_LOCALE = 'locale'; - const MODEL_COUNTRY = 'country'; // - Missing - const MODEL_CONTINENT = 'continent'; // - Missing - const MODEL_CURRENCY = 'currency'; // - Missing - const MODEL_LANGUAGE = 'langauge'; // - Missing - const MODEL_PHONE = 'phone'; // - Missing - - // Storage - const MODEL_FILE = 'file'; // - Missing - const MODEL_BUCKET = 'bucket'; // - Missing + const MODEL_COUNTRY = 'country'; + const MODEL_COUNTRY_LIST = 'countryList'; + const MODEL_CONTINENT = 'continent'; + const MODEL_CONTINENT_LIST = 'continentList'; + const MODEL_CURRENCY = 'currency'; + const MODEL_CURRENCY_LIST = 'currencyList'; + const MODEL_LANGUAGE = 'langauge'; + const MODEL_LANGUAGE_LIST = 'langaugeList'; + const MODEL_PHONE = 'phone'; + const MODEL_PHONE_LIST = 'phoneList'; // Teams const MODEL_TEAM = 'team'; @@ -50,26 +83,97 @@ class Response extends UtopiaResponse const MODEL_MEMBERSHIP = 'membership'; const MODEL_MEMBERSHIP_LIST = 'membershipList'; + // Functions + const MODEL_FUNCTION = 'function'; + const MODEL_FUNCTION_LIST = 'functionList'; + const MODEL_TAG = 'tag'; + const MODEL_TAG_LIST = 'tagList'; + const MODEL_EXECUTION = 'execution'; + const MODEL_EXECUTION_LIST = 'executionList'; + + // Project + const MODEL_PROJECT = 'project'; + const MODEL_PROJECT_LIST = 'projectsList'; + const MODEL_WEBHOOK = 'webhook'; + const MODEL_WEBHOOK_LIST = 'webhookList'; + const MODEL_KEY = 'key'; + const MODEL_KEY_LIST = 'keyList'; + const MODEL_TASK = 'task'; + const MODEL_TASK_LIST = 'taskList'; + const MODEL_PLATFORM = 'platform'; + const MODEL_PLATFORM_LIST = 'platformList'; + const MODEL_DOMAIN = 'domain'; + const MODEL_DOMAIN_LIST = 'domainList'; + + /** + * @var array + */ + protected $payload = []; + /** * Response constructor. * * @param float $time */ - public function __construct(float $time = 0) + public function __construct(SwooleHTTPResponse $response) { $this + // General ->setModel(new Error()) ->setModel(new ErrorDev()) + // Lists + ->setModel(new BaseList('Collections List', self::MODEL_COLLECTION_LIST, 'collections', self::MODEL_COLLECTION)) + ->setModel(new BaseList('Documents List', self::MODEL_DOCUMENT_LIST, 'documents', self::MODEL_ANY)) + ->setModel(new BaseList('Users List', self::MODEL_USER_LIST, 'users', self::MODEL_USER)) + ->setModel(new BaseList('Sessions List', self::MODEL_SESSION_LIST, 'sessions', self::MODEL_SESSION)) + ->setModel(new BaseList('Logs List', self::MODEL_LOG_LIST, 'logs', self::MODEL_LOG, false)) + ->setModel(new BaseList('Files List', self::MODEL_FILE_LIST, 'files', self::MODEL_FILE)) + ->setModel(new BaseList('Teams List', self::MODEL_TEAM_LIST, 'teams', self::MODEL_TEAM)) + ->setModel(new BaseList('Memberships List', self::MODEL_MEMBERSHIP_LIST, 'memberships', self::MODEL_MEMBERSHIP)) + ->setModel(new BaseList('Functions List', self::MODEL_FUNCTION_LIST, 'functions', self::MODEL_FUNCTION)) + ->setModel(new BaseList('Tags List', self::MODEL_TAG_LIST, 'tags', self::MODEL_TAG)) + ->setModel(new BaseList('Executions List', self::MODEL_EXECUTION_LIST, 'executions', self::MODEL_EXECUTION)) + ->setModel(new BaseList('Projects List', self::MODEL_PROJECT_LIST, 'projects', self::MODEL_PROJECT)) + ->setModel(new BaseList('Webhooks List', self::MODEL_WEBHOOK_LIST, 'webhooks', self::MODEL_WEBHOOK)) + ->setModel(new BaseList('API Keys List', self::MODEL_KEY_LIST, 'keys', self::MODEL_KEY)) + ->setModel(new BaseList('Tasks List', self::MODEL_TASK_LIST, 'tasks', self::MODEL_TASK)) + ->setModel(new BaseList('Platforms List', self::MODEL_PLATFORM_LIST, 'platforms', self::MODEL_PLATFORM)) + ->setModel(new BaseList('Domains List', self::MODEL_DOMAIN_LIST, 'domains', self::MODEL_DOMAIN)) + ->setModel(new BaseList('Countries List', self::MODEL_COUNTRY_LIST, 'countries', self::MODEL_COUNTRY)) + ->setModel(new BaseList('Continents List', self::MODEL_CONTINENT_LIST, 'continents', self::MODEL_CONTINENT)) + ->setModel(new BaseList('Languages List', self::MODEL_LANGUAGE_LIST, 'languages', self::MODEL_LANGUAGE)) + ->setModel(new BaseList('Currencies List', self::MODEL_CURRENCY_LIST, 'currencies', self::MODEL_CURRENCY)) + ->setModel(new BaseList('Phones List', self::MODEL_PHONE_LIST, 'phones', self::MODEL_PHONE)) + // Entities + ->setModel(new Any()) + ->setModel(new Collection()) + ->setModel(new Rule()) + ->setModel(new Log()) ->setModel(new User()) ->setModel(new Session()) ->setModel(new Locale()) + ->setModel(new File()) ->setModel(new Team()) - ->setModel(new TeamList()) ->setModel(new Membership()) - ->setModel(new MembershipList()) + ->setModel(new Func()) + ->setModel(new Tag()) + ->setModel(new Execution()) + ->setModel(new Project()) + ->setModel(new Webhook()) + ->setModel(new Key()) + ->setModel(new Task()) + ->setModel(new Domain()) + ->setModel(new Platform()) + ->setModel(new Country()) + ->setModel(new Continent()) + ->setModel(new Language()) + ->setModel(new Currency()) + ->setModel(new Phone()) + // Verification + // Recovery ; - parent::__construct($time); + parent::__construct($response); } /** @@ -120,29 +224,37 @@ class Response extends UtopiaResponse /** * Generate valid response object from document data */ - protected function output(Document $document, string $model): array + public function output(Document $document, string $model): array { $data = $document; $model = $this->getModel($model); $output = []; + if($model->isAny()) { + return $document->getArrayCopy(); + } + foreach($model->getRules() as $key => $rule) { if(!$document->isSet($key)) { if(!is_null($rule['default'])) { $document->setAttribute($key, $rule['default']); } else { - throw new Exception('Missing response key: '.$key); + throw new Exception('Model '.$model->getName().' is missing response key: '.$key); } } if($rule['array']) { if(!is_array($data[$key])) { - throw new Exception($key.' must be an array of '.$rule['type'].' types'); + throw new Exception($key.' must be an array of type '.$rule['type']); } foreach ($data[$key] as &$item) { - if(array_key_exists($rule['type'], $this->models) && $item instanceof Document) { + if($item instanceof Document) { + if(!array_key_exists($rule['type'], $this->models)) { + throw new Exception('Missing model for rule: '. $rule['type']); + } + $item = $this->output($item, $rule['type']); } } @@ -151,6 +263,8 @@ class Response extends UtopiaResponse $output[$key] = $data[$key]; } + $this->payload = $output; + return $output; } @@ -177,4 +291,12 @@ class Response extends UtopiaResponse ->send(yaml_emit($data, YAML_UTF8_ENCODING)) ; } + + /** + * @return array + */ + public function getPayload():array + { + return $this->payload; + } } diff --git a/src/Appwrite/Utopia/Response/Model.php b/src/Appwrite/Utopia/Response/Model.php index 36a2745e0e..225aa685b1 100644 --- a/src/Appwrite/Utopia/Response/Model.php +++ b/src/Appwrite/Utopia/Response/Model.php @@ -5,7 +5,12 @@ namespace Appwrite\Utopia\Response; abstract class Model { /** - * @return array + * @var bool + */ + protected $any = false; + + /** + * @var array */ protected $rules = []; @@ -48,4 +53,9 @@ abstract class Model return $this; } + + public function isAny(): bool + { + return $this->any; + } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Any.php b/src/Appwrite/Utopia/Response/Model/Any.php new file mode 100644 index 0000000000..1a5defec66 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Any.php @@ -0,0 +1,34 @@ +addRule('sum', [ + $this->name = $name; + $this->type = $type; + + if($paging) { + $this->addRule('sum', [ 'type' => 'integer', 'description' => 'Total sum of items in the list.', 'example' => '5', - ]) - ; + ]); + } + $this->addRule($key, [ + 'type' => $model, + 'description' => 'List of '.$key.'.', + 'example' => [], + 'array' => true, + ]); } /** @@ -25,7 +44,7 @@ abstract class BaseList extends Model */ public function getName():string { - return 'Base List'; + return $this->name; } /** @@ -35,6 +54,6 @@ abstract class BaseList extends Model */ public function getType():string { - return Response::MODEL_BASE_LIST; + return $this->type; } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Collection.php b/src/Appwrite/Utopia/Response/Model/Collection.php new file mode 100644 index 0000000000..9c6dd15d69 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Collection.php @@ -0,0 +1,68 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Collection ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('$permissions', [ + 'type' => Response::MODEL_PERMISSIONS, + 'description' => 'Collection permissions.', + 'example' => new \stdClass, + 'array' => false, + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Collection name.', + 'example' => 'Movies', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'Collection creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('dateUpdated', [ + 'type' => 'integer', + 'description' => 'Collection creation date in Unix timestamp.', + 'example' => 1592981550, + ]) + ->addRule('rules', [ + 'type' => Response::MODEL_RULE, + 'description' => 'Collection rules.', + 'example' => [], + 'default' => [], + 'array' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Collection'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_COLLECTION; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Continent.php b/src/Appwrite/Utopia/Response/Model/Continent.php new file mode 100644 index 0000000000..a42b39e9e9 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Continent.php @@ -0,0 +1,45 @@ +addRule('name', [ + 'type' => 'string', + 'description' => 'Continent name.', + 'example' => 'Europe', + ]) + ->addRule('code', [ + 'type' => 'string', + 'description' => 'Continent two letter code.', + 'example' => 'EU', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Continent'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_CONTINENT; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Country.php b/src/Appwrite/Utopia/Response/Model/Country.php new file mode 100644 index 0000000000..b5ba0f74f5 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Country.php @@ -0,0 +1,45 @@ +addRule('name', [ + 'type' => 'string', + 'description' => 'Country name.', + 'example' => 'United States', + ]) + ->addRule('code', [ + 'type' => 'string', + 'description' => 'Country two-character ISO 3166-1 alpha code.', + 'example' => 'US', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Country'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_COUNTRY; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Currency.php b/src/Appwrite/Utopia/Response/Model/Currency.php new file mode 100644 index 0000000000..29b3d78f98 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Currency.php @@ -0,0 +1,76 @@ +addRule('symbol', [ + 'type' => 'string', + 'description' => 'Currency symbol.', + 'example' => '$', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Currency name.', + 'example' => 'US dollar', + ]) + ->addRule('symbolNative', [ + 'type' => 'string', + 'description' => 'Currency native symbol.', + 'example' => '$', + ]) + ->addRule('decimalDigits', [ + 'type' => 'integer', + 'description' => 'Number of decimal digits.', + 'example' => 2, + ]) + ->addRule('rounding', [ + 'type' => 'float', + 'description' => 'Currency digit rounding.', + 'example' => 0, + ]) + ->addRule('code', [ + 'type' => 'string', + 'description' => 'Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format.', + 'example' => 'USD', + ]) + ->addRule('namePlural', [ + 'type' => 'string', + 'description' => 'Currency plural name', + 'example' => 'US dollars', + ]) + // ->addRule('locations', [ + // 'type' => 'string', + // 'description' => 'Currency locations list. List of location in two-character ISO 3166-1 alpha code.', + // 'example' => ['US'], + // 'array' => true, + // ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Currency'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_CURRENCY; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Domain.php b/src/Appwrite/Utopia/Response/Model/Domain.php new file mode 100644 index 0000000000..f8273ff876 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Domain.php @@ -0,0 +1,60 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Domain ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('domain', [ + 'type' => 'string', + 'description' => 'Domain name.', + 'example' => 'appwrite.company.com', + ]) + ->addRule('registerable', [ + 'type' => 'string', + 'description' => 'Registerable domain name.', + 'example' => 'company.com', + ]) + ->addRule('tld', [ + 'type' => 'string', + 'description' => 'TLD name.', + 'example' => 'com', + ]) + ->addRule('verification', [ + 'type' => 'boolean', + 'description' => 'Verification process status.', + 'example' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Domain'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_DOMAIN; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Execution.php b/src/Appwrite/Utopia/Response/Model/Execution.php new file mode 100644 index 0000000000..92a00208dd --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Execution.php @@ -0,0 +1,80 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Execution ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('functionId', [ + 'type' => 'string', + 'description' => 'Function ID.', + 'example' => '5e5ea6g16897e', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'The execution creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('trigger', [ + 'type' => 'string', + 'description' => 'The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`.', + 'example' => 'http', + ]) + ->addRule('status', [ + 'type' => 'string', + 'description' => 'The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`.', + 'example' => 'processing', + ]) + ->addRule('exitCode', [ + 'type' => 'integer', + 'description' => 'The script exit code.', + 'example' => 0, + ]) + ->addRule('stdout', [ + 'type' => 'string', + 'description' => 'The script stdout output string.', + 'example' => '', + ]) + ->addRule('stderr', [ + 'type' => 'string', + 'description' => 'The script stderr output string.', + 'example' => '', + ]) + ->addRule('time', [ + 'type' => 'float', + 'description' => 'The script execution time in seconds.', + 'example' => 0.400, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Execution'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_EXECUTION; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/File.php b/src/Appwrite/Utopia/Response/Model/File.php index 875c6f4bd7..416a02ac53 100644 --- a/src/Appwrite/Utopia/Response/Model/File.php +++ b/src/Appwrite/Utopia/Response/Model/File.php @@ -9,7 +9,44 @@ class File extends Model { public function __construct() { - + $this + ->addRule('$id', [ + 'type' => 'string', + 'description' => 'File ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('$permissions', [ + 'type' => Response::MODEL_PERMISSIONS, + 'description' => 'File permissions.', + 'example' => new \stdClass, + 'array' => false, + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'File name.', + 'example' => 'Pink.png', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'File creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('signature', [ + 'type' => 'string', + 'description' => 'File MD5 signature.', + 'example' => '5d529fd02b544198ae075bd57c1762bb', + ]) + ->addRule('mimeType', [ + 'type' => 'string', + 'description' => 'File mime type.', + 'example' => 'image/png', + ]) + ->addRule('sizeOriginal', [ + 'type' => 'integer', + 'description' => 'File original size in bytes.', + 'example' => 17890, + ]) + ; } /** @@ -29,6 +66,6 @@ class File extends Model */ public function getType():string { - return Response::MODEL_LOCALE; + return Response::MODEL_FILE; } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php new file mode 100644 index 0000000000..e0d3595355 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -0,0 +1,108 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Function ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Function name.', + 'example' => 'My Function', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'Function creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('dateUpdated', [ + 'type' => 'integer', + 'description' => 'Function update date in Unix timestamp.', + 'example' => 1592981257, + ]) + ->addRule('status', [ + 'type' => 'string', + 'description' => 'Function status. Possible values: disabled, enabled', + 'example' => 'enabled', + ]) + ->addRule('env', [ + 'type' => 'string', + 'description' => 'Function execution environment.', + 'example' => 'python-3.8', + ]) + ->addRule('tag', [ + 'type' => 'string', + 'description' => 'Function active tag ID.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('vars', [ + 'type' => 'json', + 'description' => 'Function environment variables.', + 'default' => new \stdClass, + 'example' => ['key' => 'value'], + ]) + ->addRule('events', [ + 'type' => 'string', + 'description' => 'Function trigger events.', + 'default' => [], + 'example' => ['account.create'], + 'array' => true, + ]) + ->addRule('schedule', [ + 'type' => 'string', + 'description' => 'Function execution schedult in CRON format.', + 'default' => '', + 'example' => '5 4 * * *', + ]) + ->addRule('scheduleNext', [ + 'type' => 'integer', + 'description' => 'Function next scheduled execution date in Unix timestamp.', + 'example' => 1592981292, + 'default' => 0, + ]) + ->addRule('schedulePrevious', [ + 'type' => 'integer', + 'description' => 'Function next scheduled execution date in Unix timestamp.', + 'example' => 1592981237, + 'default' => 0, + ]) + ->addRule('timeout', [ + 'type' => 'integer', + 'description' => 'Function execution timeout in seconds.', + 'default' => 15, + 'example' => 1592981237, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Function'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_FUNCTION; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Key.php b/src/Appwrite/Utopia/Response/Model/Key.php new file mode 100644 index 0000000000..99abb38d5d --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Key.php @@ -0,0 +1,57 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Key ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Key name.', + 'example' => 'My API Key', + ]) + ->addRule('scopes', [ + 'type' => 'string', + 'description' => 'Allowed permission scopes.', + 'default' => [], + 'example' => ['users.read', 'documents.write'], + 'array' => true, + ]) + ->addRule('secret', [ + 'type' => 'string', + 'description' => 'Secret key.', + 'example' => '919c2d18fb5d4...a2ae413da83346ad2', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Key'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_KEY; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Language.php b/src/Appwrite/Utopia/Response/Model/Language.php new file mode 100644 index 0000000000..966efa7e72 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Language.php @@ -0,0 +1,50 @@ +addRule('name', [ + 'type' => 'string', + 'description' => 'Language name.', + 'example' => 'Italian', + ]) + ->addRule('code', [ + 'type' => 'string', + 'description' => 'Language two-character ISO 639-1 codes.', + 'example' => 'it', + ]) + ->addRule('nativeName', [ + 'type' => 'string', + 'description' => 'Language native name.', + 'example' => 'Italiano', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Language'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_LANGUAGE; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Log.php b/src/Appwrite/Utopia/Response/Model/Log.php index 93e7e88efd..35040d018e 100644 --- a/src/Appwrite/Utopia/Response/Model/Log.php +++ b/src/Appwrite/Utopia/Response/Model/Log.php @@ -9,6 +9,107 @@ class Log extends Model { public function __construct() { + $this + ->addRule('event', [ + 'type' => 'string', + 'description' => 'Event name.', + 'example' => 'account.sessions.create', + ]) + ->addRule('ip', [ + 'type' => 'string', + 'description' => 'IP session in use when the session was created.', + 'example' => '127.0.0.1', + ]) + ->addRule('time', [ + 'type' => 'integer', + 'description' => 'Log creation time in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('osCode', [ + 'type' => 'string', + 'description' => 'Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json).', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('osName', [ + 'type' => 'string', + 'description' => 'Operating system name.', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('osVersion', [ + 'type' => 'string', + 'description' => 'Operating system version.', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('clientType', [ + 'type' => 'string', + 'description' => 'Client type.', + 'default' => '', + 'example' => 'browser', + ]) + ->addRule('clientCode', [ + 'type' => 'string', + 'description' => 'Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json).', + 'default' => '', + 'example' => 'CM', + ]) + ->addRule('clientName', [ + 'type' => 'string', + 'description' => 'Client name.', + 'default' => '', + 'example' => 'Chrome Mobile iOS', + ]) + ->addRule('clientVersion', [ + 'type' => 'string', + 'description' => 'Client version.', + 'default' => '', + 'example' => '84.0', + ]) + ->addRule('clientEngine', [ + 'type' => 'string', + 'description' => 'Client engine name.', + 'default' => '', + 'example' => 'WebKit', + ]) + ->addRule('clientEngineVersion', [ + 'type' => 'string', + 'description' => 'Client engine name.', + 'default' => '', + 'example' => '605.1.15', + ]) + ->addRule('deviceName', [ + 'type' => 'string', + 'description' => 'Device name.', + 'default' => '', + 'example' => 'smartphone', + ]) + ->addRule('deviceBrand', [ + 'type' => 'string', + 'description' => 'Device brand name.', + 'default' => '', + 'example' => 'Google', + ]) + ->addRule('deviceModel', [ + 'type' => 'string', + 'description' => 'Device model name.', + 'default' => '', + 'example' => 'Nexus 5', + ]) + ->addRule('countryCode', [ + 'type' => 'string', + 'description' => 'Country two-character ISO 3166-1 alpha code.', + 'default' => '', + 'example' => 'US', + ]) + ->addRule('countryName', [ + 'type' => 'string', + 'description' => 'Country name.', + 'default' => '', + 'example' => 'United States', + ]) + ; } /** @@ -18,7 +119,7 @@ class Log extends Model */ public function getName():string { - return 'Session'; + return 'Log'; } /** @@ -28,6 +129,6 @@ class Log extends Model */ public function getType():string { - return Response::MODEL_LOCALE; + return Response::MODEL_LOG; } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/MembershipList.php b/src/Appwrite/Utopia/Response/Model/MembershipList.php deleted file mode 100644 index 56937c8d33..0000000000 --- a/src/Appwrite/Utopia/Response/Model/MembershipList.php +++ /dev/null @@ -1,41 +0,0 @@ -addRule('memberships', [ - 'type' => Response::MODEL_MEMBERSHIP, - 'description' => 'List of memberships.', - 'example' => [], - 'array' => true, - ]) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'Membership List'; - } - - /** - * Get Collection - * - * @return string - */ - public function getType():string - { - return Response::MODEL_MEMBERSHIP_LIST; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Permissions.php b/src/Appwrite/Utopia/Response/Model/Permissions.php new file mode 100644 index 0000000000..8f14ccb86a --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Permissions.php @@ -0,0 +1,47 @@ +addRule('read', [ + 'type' => 'string', + 'description' => 'Read permissions.', + 'example' => ['*', 'user:5e5ea5c16897e'], + 'array' => true, + ]) + ->addRule('write', [ + 'type' => 'string', + 'description' => 'Write permissions.', + 'example' => ['*', 'user:5e5ea5c16897e'], + 'array' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Permissions'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_PERMISSIONS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Phone.php b/src/Appwrite/Utopia/Response/Model/Phone.php new file mode 100644 index 0000000000..e0242981e9 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Phone.php @@ -0,0 +1,50 @@ +addRule('code', [ + 'type' => 'string', + 'description' => 'Phone code.', + 'example' => '+1', + ]) + ->addRule('countryCode', [ + 'type' => 'string', + 'description' => 'Country two-character ISO 3166-1 alpha code.', + 'example' => 'US', + ]) + ->addRule('countryName', [ + 'type' => 'string', + 'description' => 'Country name.', + 'example' => 'United States', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Phone'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_PHONE; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Platform.php b/src/Appwrite/Utopia/Response/Model/Platform.php new file mode 100644 index 0000000000..861300f887 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Platform.php @@ -0,0 +1,77 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Platform ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Platform name.', + 'example' => 'My Web App', + ]) + ->addRule('type', [ + 'type' => 'string', + 'description' => 'Platform type. Possible values are: web, flutter-ios, flutter-android, ios, android, and unity.', + 'example' => 'My Web App', + ]) + ->addRule('key', [ + 'type' => 'string', + 'description' => 'Platform Key. iOS bundle ID or Android package name. Empty string for other platforms.', + 'example' => 'com.company.appname', + ]) + // ->addRule('store', [ + // 'type' => 'string', + // 'description' => 'Link to platform store.', + // 'example' => '', + // ]) + ->addRule('hostname', [ + 'type' => 'string', + 'description' => 'Web app hostname. Empty string for other platforms.', + 'example' => true, + ]) + ->addRule('httpUser', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication username.', + 'default' => '', + 'example' => 'username', + ]) + ->addRule('httpPass', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication password.', + 'default' => '', + 'example' => 'password', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Platform'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_PLATFORM; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php new file mode 100644 index 0000000000..af5cad3ebe --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -0,0 +1,166 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Project ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Project name.', + 'default' => '', + 'example' => 'New Project', + ]) + ->addRule('description', [ + 'type' => 'string', + 'description' => 'Project description.', + 'default' => '', + 'example' => 'This is a new project.', + ]) + ->addRule('teamId', [ + 'type' => 'string', + 'description' => 'Project team ID.', + 'example' => '1592981250', + ]) + ->addRule('logo', [ + 'type' => 'string', + 'description' => 'Project logo file ID.', + 'default' => '', + 'example' => '5f5c451b403cb', + ]) + ->addRule('url', [ + 'type' => 'string', + 'description' => 'Project website URL.', + 'default' => '', + 'example' => '5f5c451b403cb', + ]) + ->addRule('legalName', [ + 'type' => 'string', + 'description' => 'Company legal name.', + 'default' => '', + 'example' => 'Company LTD.', + ]) + ->addRule('legalCountry', [ + 'type' => 'string', + 'description' => 'Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format.', + 'default' => '', + 'example' => 'US', + ]) + ->addRule('legalState', [ + 'type' => 'string', + 'description' => 'State name.', + 'default' => '', + 'example' => 'New York', + ]) + ->addRule('legalCity', [ + 'type' => 'string', + 'description' => 'City name.', + 'default' => '', + 'example' => 'New York City.', + ]) + ->addRule('legalAddress', [ + 'type' => 'string', + 'description' => 'Company Address.', + 'default' => '', + 'example' => '620 Eighth Avenue, New York, NY 10018', + ]) + ->addRule('legalTaxId', [ + 'type' => 'string', + 'description' => 'Company Tax ID.', + 'default' => '', + 'example' => '131102020', + ]) + ->addRule('platforms', [ + 'type' => Response::MODEL_PLATFORM, + 'description' => 'List of Platforms.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('webhooks', [ + 'type' => Response::MODEL_WEBHOOK, + 'description' => 'List of Webhooks.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('keys', [ + 'type' => Response::MODEL_KEY, + 'description' => 'List of API Keys.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('domains', [ + 'type' => Response::MODEL_DOMAIN, + 'description' => 'List of Domains.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('tasks', [ + 'type' => Response::MODEL_TASK, + 'description' => 'List of Tasks.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ; + + $providers = Config::getParam('providers', []); + + foreach ($providers as $index => $provider) { + if (!$provider['enabled']) { + continue; + } + + $name = (isset($provider['name'])) ? $provider['name'] : 'Unknown'; + + $this + ->addRule('usersOauth2'.\ucfirst($index).'Appid', [ + 'type' => 'string', + 'description' => $name.' OAuth app ID.', + 'example' => '123247283472834787438', + 'default' => '', + ]) + ->addRule('usersOauth2'.\ucfirst($index).'Secret', [ + 'type' => 'string', + 'description' => $name.' OAuth secret ID.', + 'example' => 'djsgudsdsewe43434343dd34...', + 'default' => '', + ]) + ; + } + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Project'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_PROJECT; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Rule.php b/src/Appwrite/Utopia/Response/Model/Rule.php new file mode 100644 index 0000000000..234377c432 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Rule.php @@ -0,0 +1,83 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Rule ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('$collection', [ // TODO remove this from public response + 'type' => 'string', + 'description' => 'Rule Collection.', + 'example' => '5e5e66c16897e', + ]) + ->addRule('type', [ + 'type' => 'string', + 'description' => 'Rule type. Possible values: ', + 'example' => 'title', + ]) + ->addRule('key', [ + 'type' => 'string', + 'description' => 'Rule key.', + 'example' => 'title', + ]) + ->addRule('label', [ + 'type' => 'string', + 'description' => 'Rule label.', + 'example' => 'Title', + ]) + ->addRule('default', [ // TODO should be of mixed types + 'type' => 'string', + 'description' => 'Rule default value.', + 'example' => 'Movie Name', + 'default' => '', + ]) + ->addRule('array', [ + 'type' => 'boolean', + 'description' => 'Is array?', + 'example' => false, + ]) + ->addRule('required', [ + 'type' => 'boolean', + 'description' => 'Is required?', + 'example' => true, + ]) + ->addRule('list', [ + 'type' => 'string', + 'description' => 'List of allowed values', + 'array' => true, + 'default' => [], + 'example' => ['5e5ea5c168099'], + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Rule'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_RULE; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Session.php b/src/Appwrite/Utopia/Response/Model/Session.php index 6146feb31d..2e22513fdf 100644 --- a/src/Appwrite/Utopia/Response/Model/Session.php +++ b/src/Appwrite/Utopia/Response/Model/Session.php @@ -16,15 +16,107 @@ class Session extends Model 'example' => '5e5ea5c16897e', ]) ->addRule('expire', [ - 'type' => 'string', + 'type' => 'integer', 'description' => 'Session expiration date in Unix timestamp.', + 'default' => 0, 'example' => 1592981250, ]) ->addRule('ip', [ 'type' => 'string', - 'description' => 'IP session in use when the session was created.', + 'description' => 'IP in use when the session was created.', + 'default' => '', 'example' => '127.0.0.1', ]) + ->addRule('osCode', [ + 'type' => 'string', + 'description' => 'Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json).', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('osName', [ + 'type' => 'string', + 'description' => 'Operating system name.', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('osVersion', [ + 'type' => 'string', + 'description' => 'Operating system version.', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('clientType', [ + 'type' => 'string', + 'description' => 'Client type.', + 'default' => '', + 'example' => 'browser', + ]) + ->addRule('clientCode', [ + 'type' => 'string', + 'description' => 'Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json).', + 'default' => '', + 'example' => 'CM', + ]) + ->addRule('clientName', [ + 'type' => 'string', + 'description' => 'Client name.', + 'default' => '', + 'example' => 'Chrome Mobile iOS', + ]) + ->addRule('clientVersion', [ + 'type' => 'string', + 'description' => 'Client version.', + 'default' => '', + 'example' => '84.0', + ]) + ->addRule('clientEngine', [ + 'type' => 'string', + 'description' => 'Client engine name.', + 'default' => '', + 'example' => 'WebKit', + ]) + ->addRule('clientEngineVersion', [ + 'type' => 'string', + 'description' => 'Client engine name.', + 'default' => '', + 'example' => '605.1.15', + ]) + ->addRule('deviceName', [ + 'type' => 'string', + 'description' => 'Device name.', + 'default' => '', + 'example' => 'smartphone', + ]) + ->addRule('deviceBrand', [ + 'type' => 'string', + 'description' => 'Device brand name.', + 'default' => '', + 'example' => 'Google', + ]) + ->addRule('deviceModel', [ + 'type' => 'string', + 'description' => 'Device model name.', + 'default' => '', + 'example' => 'Nexus 5', + ]) + ->addRule('countryCode', [ + 'type' => 'string', + 'description' => 'Country two-character ISO 3166-1 alpha code.', + 'default' => '', + 'example' => 'US', + ]) + ->addRule('countryName', [ + 'type' => 'string', + 'description' => 'Country name.', + 'default' => '', + 'example' => 'United States', + ]) + ->addRule('current', [ + 'type' => 'boolean', + 'description' => 'Returns true if this the current user session.', + 'default' => '', + 'example' => true, + ]) ; } diff --git a/src/Appwrite/Utopia/Response/Model/Tag.php b/src/Appwrite/Utopia/Response/Model/Tag.php new file mode 100644 index 0000000000..4b6facab82 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Tag.php @@ -0,0 +1,60 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Tag ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('functionId', [ + 'type' => 'string', + 'description' => 'Function ID.', + 'example' => '5e5ea6g16897e', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'The tag creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('command', [ + 'type' => 'string', + 'description' => 'The entrypoint command in use to execute the tag code.', + 'example' => 'enabled', + ]) + ->addRule('size', [ + 'type' => 'string', + 'description' => 'The code size in bytes.', + 'example' => 'python-3.8', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Tag'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_TAG; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Task.php b/src/Appwrite/Utopia/Response/Model/Task.php new file mode 100644 index 0000000000..e2ab652fe7 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Task.php @@ -0,0 +1,125 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Task ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Task name.', + 'example' => 'My Task', + ]) + ->addRule('security', [ + 'type' => 'boolean', + 'description' => 'Indicated if SSL / TLS Certificate verification is enabled.', + 'example' => true, + ]) + ->addRule('httpMethod', [ + 'type' => 'string', + 'description' => 'Task HTTP Method.', + 'example' => 'POST', + ]) + ->addRule('httpUrl', [ + 'type' => 'string', + 'description' => 'Task HTTP URL.', + 'example' => 'https://example.com/task', + ]) + ->addRule('httpHeaders', [ + 'type' => 'string', + 'description' => 'Task HTTP headers.', + 'default' => [], + 'example' => ['key:value'], + 'array' => true, + ]) + ->addRule('httpUser', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication username.', + 'default' => '', + 'example' => 'username', + ]) + ->addRule('httpPass', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication password.', + 'default' => '', + 'example' => 'password', + ]) + ->addRule('duration', [ + 'type' => 'float', + 'description' => 'Task duration in seconds.', + 'default' => 0, + 'example' => 1.2, + ]) + ->addRule('delay', [ + 'type' => 'float', + 'description' => 'Task delay time in seconds.', + 'default' => 0, + 'example' => 1.2, + ]) + ->addRule('failures', [ + 'type' => 'integer', + 'description' => 'Number of recurring task failures.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('schedule', [ + 'type' => 'string', + 'description' => 'Task schedule in CRON syntax.', + 'example' => '* * * * *', + ]) + ->addRule('status', [ + 'type' => 'string', + 'description' => 'Task status. Possible values: play, pause', // TODO - change to enabled disabled + 'example' => 'enabled', + ]) + ->addRule('updated', [ + 'type' => 'integer', + 'description' => 'Task last updated time in Unix timestamp.', + 'default' => 0, + 'example' => 1592981250, + ]) + ->addRule('previous', [ + 'type' => 'integer', + 'description' => 'Task previous run time in Unix timestamp.', + 'default' => 0, + 'example' => 1592981250, + ]) + ->addRule('next', [ + 'type' => 'integer', + 'description' => 'Task next run time in Unix timestamp.', + 'default' => 0, + 'example' => 1592981650, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Task'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_TASK; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/TeamList.php b/src/Appwrite/Utopia/Response/Model/TeamList.php deleted file mode 100644 index c96e4cd0d4..0000000000 --- a/src/Appwrite/Utopia/Response/Model/TeamList.php +++ /dev/null @@ -1,41 +0,0 @@ -addRule('teams', [ - 'type' => Response::MODEL_TEAM, - 'description' => 'List of teams.', - 'example' => [], - 'array' => true, - ]) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'Team List'; - } - - /** - * Get Collection - * - * @return string - */ - public function getType():string - { - return Response::MODEL_TEAM_LIST; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index 56af2156cf..25b50cfa20 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -18,7 +18,6 @@ class User extends Model ->addRule('name', [ 'type' => 'string', 'description' => 'User name.', - 'default' => '', 'example' => 'John Doe', ]) ->addRule('registration', [ @@ -29,13 +28,11 @@ class User extends Model ->addRule('status', [ 'type' => 'integer', 'description' => 'User status. 0 for Unavtivated, 1 for active and 2 is blocked.', - 'default' => false, - 'example' => true, + 'example' => 0, ]) ->addRule('email', [ 'type' => 'string', 'description' => 'User email address.', - 'default' => '', 'example' => 'john@appwrite.io', ]) ->addRule('emailVerification', [ @@ -48,7 +45,7 @@ class User extends Model 'type' => 'json', 'description' => 'User preferences as a key-value object', 'default' => new \stdClass, - 'example' => ['theme' => 'dark', 'timezone' => 'UTC'], + 'example' => ['theme' => 'pink', 'timezone' => 'UTC'], ]) ->addRule('roles', [ 'type' => 'string', diff --git a/src/Appwrite/Utopia/Response/Model/Webhook.php b/src/Appwrite/Utopia/Response/Model/Webhook.php new file mode 100644 index 0000000000..e3fe565afb --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Webhook.php @@ -0,0 +1,74 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Webhook ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Webhook name.', + 'example' => 'My Webhook', + ]) + ->addRule('url', [ + 'type' => 'string', + 'description' => 'Webhook URL endpoint.', + 'example' => 'https://example.com/webhook', + ]) + ->addRule('events', [ + 'type' => 'string', + 'description' => 'Webhook trigger events.', + 'default' => [], + 'example' => ['database.collections.update', 'database.collections.delete'], + 'array' => true, + ]) + ->addRule('security', [ + 'type' => 'boolean', + 'description' => 'Indicated if SSL / TLS Certificate verification is enabled.', + 'example' => true, + ]) + ->addRule('httpUser', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication username.', + 'default' => '', + 'example' => 'username', + ]) + ->addRule('httpPass', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication password.', + 'default' => '', + 'example' => 'password', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Webhook'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_WEBHOOK; + } +} \ No newline at end of file diff --git a/tests/unit/Swoole/FilesTest.php b/tests/unit/Swoole/FilesTest.php deleted file mode 100644 index adcf4b4fc0..0000000000 --- a/tests/unit/Swoole/FilesTest.php +++ /dev/null @@ -1,48 +0,0 @@ -assertGreaterThan(100, Files::getCount()); - $this->assertLessThan(250, Files::getCount()); - - $this->assertEquals(false, Files::isFileLoaded('/index.php')); - $this->assertEquals(false, Files::isFileLoaded('/unknown.jpg')); - $this->assertEquals(true, Files::isFileLoaded('/scripts/app.js')); - $this->assertEquals(true, Files::isFileLoaded('/styles/default.less')); - $this->assertEquals(true, Files::isFileLoaded('/dist/scripts/app.js')); - $this->assertEquals(true, Files::isFileLoaded('/dist/styles/default-ltr.css')); - $this->assertEquals(true, Files::isFileLoaded('/dist/styles/default-rtl.css')); - - $this->assertEquals('application/vnd.ms-fontobject', Files::getFileMimeType('/fonts/poppins-v9-latin-100.eot')); - $this->assertEquals('image/svg+xml', Files::getFileMimeType('/fonts/poppins-v9-latin-100.svg')); - $this->assertEquals('font/sfnt', Files::getFileMimeType('/fonts/poppins-v9-latin-100.ttf')); - $this->assertEquals('application/octet-stream', Files::getFileMimeType('/fonts/poppins-v9-latin-100.woff')); - $this->assertEquals('application/octet-stream', Files::getFileMimeType('/fonts/poppins-v9-latin-100.woff2')); - $this->assertEquals('image/png', Files::getFileMimeType('/images/apple.png')); - $this->assertEquals('text/javascript', Files::getFileMimeType('/dist/scripts/app.js')); - $this->assertEquals('text/javascript', Files::getFileMimeType('/dist/scripts/app.js')); - $this->assertEquals('text/css', Files::getFileMimeType('/dist/styles/default-ltr.css')); - $this->assertEquals('text/css', Files::getFileMimeType('/dist/styles/default-rtl.css')); - - $this->assertNotEmpty(Files::getFileContents('/fonts/poppins-v9-latin-100.eot')); - $this->assertNotEmpty(Files::getFileContents('/fonts/poppins-v9-latin-100.svg')); - $this->assertNotEmpty(Files::getFileContents('/fonts/poppins-v9-latin-100.ttf')); - $this->assertNotEmpty(Files::getFileContents('/fonts/poppins-v9-latin-100.woff')); - $this->assertNotEmpty(Files::getFileMimeType('/fonts/poppins-v9-latin-100.woff2')); - $this->assertNotEmpty(Files::getFileContents('/images/apple.png')); - $this->assertNotEmpty(Files::getFileContents('/dist/scripts/app.js')); - $this->assertNotEmpty(Files::getFileContents('/dist/scripts/app.js')); - $this->assertNotEmpty(Files::getFileContents('/dist/styles/default-ltr.css')); - $this->assertNotEmpty(Files::getFileContents('/dist/styles/default-rtl.css')); - - } -} \ No newline at end of file