Added external swoole lib and extended response class
This commit is contained in:
parent
a56ca3535a
commit
0450604d27
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
require_once __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
use Appwrite\Swoole\Files;
|
||||
use Appwrite\Swoole\Request;
|
||||
use Appwrite\Swoole\Response;
|
||||
use Utopia\Swoole\Request;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Swoole\Process;
|
||||
use Swoole\Http\Server;
|
||||
use Swoole\Http\Request as SwooleRequest;
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -1,176 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Swoole;
|
||||
|
||||
use Exception;
|
||||
|
||||
class Files
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
static protected $loaded = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
static protected $count = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
static protected $mimeTypes = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
static protected $extensions = [
|
||||
'css' => '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'];
|
||||
}
|
||||
}
|
|
@ -1,339 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Swoole;
|
||||
|
||||
use Utopia\Request as UtopiaRequest;
|
||||
use Swoole\Http\Request as SwooleRequest;
|
||||
|
||||
class Request extends UtopiaRequest
|
||||
{
|
||||
/**
|
||||
* Swoole Request Object
|
||||
*
|
||||
* @var SwooleRequest
|
||||
*/
|
||||
protected $swoole;
|
||||
|
||||
/**
|
||||
* Request constructor.
|
||||
*/
|
||||
public function __construct(SwooleRequest $request)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Swoole;
|
||||
|
||||
use Appwrite\Utopia\Response as UtopiaResponse;
|
||||
use Swoole\Http\Response as SwooleResponse;
|
||||
|
||||
class Response extends UtopiaResponse
|
||||
{
|
||||
/**
|
||||
* Swoole Response Object
|
||||
*
|
||||
* @var SwooleResponse
|
||||
*/
|
||||
protected $swoole;
|
||||
|
||||
/**
|
||||
* Mime Types
|
||||
* with compression support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $compressed = [
|
||||
'text/plain' => 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
34
src/Appwrite/Utopia/Response/Model/Any.php
Normal file
34
src/Appwrite/Utopia/Response/Model/Any.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Any extends Model
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $any = true;
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Any';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_ANY;
|
||||
}
|
||||
}
|
|
@ -5,17 +5,36 @@ namespace Appwrite\Utopia\Response\Model;
|
|||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
abstract class BaseList extends Model
|
||||
class BaseList extends Model
|
||||
{
|
||||
public function __construct()
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type = '';
|
||||
|
||||
public function __construct(string $name, string $type, string $key, string $model, bool $paging = true)
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
68
src/Appwrite/Utopia/Response/Model/Collection.php
Normal file
68
src/Appwrite/Utopia/Response/Model/Collection.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Collection extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
45
src/Appwrite/Utopia/Response/Model/Continent.php
Normal file
45
src/Appwrite/Utopia/Response/Model/Continent.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Continent extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
45
src/Appwrite/Utopia/Response/Model/Country.php
Normal file
45
src/Appwrite/Utopia/Response/Model/Country.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Country extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
76
src/Appwrite/Utopia/Response/Model/Currency.php
Normal file
76
src/Appwrite/Utopia/Response/Model/Currency.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Currency extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
60
src/Appwrite/Utopia/Response/Model/Domain.php
Normal file
60
src/Appwrite/Utopia/Response/Model/Domain.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Domain extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
80
src/Appwrite/Utopia/Response/Model/Execution.php
Normal file
80
src/Appwrite/Utopia/Response/Model/Execution.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Execution extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
108
src/Appwrite/Utopia/Response/Model/Func.php
Normal file
108
src/Appwrite/Utopia/Response/Model/Func.php
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Func extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
57
src/Appwrite/Utopia/Response/Model/Key.php
Normal file
57
src/Appwrite/Utopia/Response/Model/Key.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Key extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
50
src/Appwrite/Utopia/Response/Model/Language.php
Normal file
50
src/Appwrite/Utopia/Response/Model/Language.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Language extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class MembershipList extends BaseList
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
47
src/Appwrite/Utopia/Response/Model/Permissions.php
Normal file
47
src/Appwrite/Utopia/Response/Model/Permissions.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Permissions extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
50
src/Appwrite/Utopia/Response/Model/Phone.php
Normal file
50
src/Appwrite/Utopia/Response/Model/Phone.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Phone extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
77
src/Appwrite/Utopia/Response/Model/Platform.php
Normal file
77
src/Appwrite/Utopia/Response/Model/Platform.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Platform extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
166
src/Appwrite/Utopia/Response/Model/Project.php
Normal file
166
src/Appwrite/Utopia/Response/Model/Project.php
Normal file
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
use Utopia\Config\Config;
|
||||
|
||||
class Project extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
83
src/Appwrite/Utopia/Response/Model/Rule.php
Normal file
83
src/Appwrite/Utopia/Response/Model/Rule.php
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Rule extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
|
60
src/Appwrite/Utopia/Response/Model/Tag.php
Normal file
60
src/Appwrite/Utopia/Response/Model/Tag.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
125
src/Appwrite/Utopia/Response/Model/Task.php
Normal file
125
src/Appwrite/Utopia/Response/Model/Task.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Task extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class TeamList extends BaseList
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
|
@ -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',
|
||||
|
|
74
src/Appwrite/Utopia/Response/Model/Webhook.php
Normal file
74
src/Appwrite/Utopia/Response/Model/Webhook.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Webhook extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use Appwrite\Swoole\Files;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FilesTest extends TestCase
|
||||
{
|
||||
public function testParse()
|
||||
{
|
||||
Files::load(__DIR__.'/../../../public');
|
||||
|
||||
$this->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'));
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue