mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Draft commit with POC
This commit is contained in:
parent
b05680cf7d
commit
9b749db89b
5 changed files with 95 additions and 25 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
require_once __DIR__.'/../init.php';
|
require_once __DIR__.'/../init.php';
|
||||||
|
|
||||||
|
use Appwrite\Utopia\Request\Filters\V11;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\Swoole\Request;
|
use Utopia\Swoole\Request;
|
||||||
use Appwrite\Utopia\Response;
|
use Appwrite\Utopia\Response;
|
||||||
|
|
@ -23,7 +24,7 @@ Config::setParam('domainVerification', false);
|
||||||
Config::setParam('cookieDomain', 'localhost');
|
Config::setParam('cookieDomain', 'localhost');
|
||||||
Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE);
|
Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE);
|
||||||
|
|
||||||
App::init(function ($utopia, $request, $response, $console, $project, $dbForConsole, $user, $locale, $clients) {
|
App::init(function ($args, $utopia, $request, $response, $console, $project, $dbForConsole, $user, $locale, $clients) {
|
||||||
/** @var Utopia\App $utopia */
|
/** @var Utopia\App $utopia */
|
||||||
/** @var Utopia\Swoole\Request $request */
|
/** @var Utopia\Swoole\Request $request */
|
||||||
/** @var Appwrite\Utopia\Response $response */
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
|
@ -79,13 +80,30 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons
|
||||||
Config::setParam('domains', $domains);
|
Config::setParam('domains', $domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
$localeParam = (string) $request->getParam('locale', $request->getHeader('x-appwrite-locale', ''));
|
$route = $utopia->match($request);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Request format
|
||||||
|
*/
|
||||||
|
$requestFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', ''));
|
||||||
|
if ($requestFormat) {
|
||||||
|
switch($requestFormat) {
|
||||||
|
// TODO: For some reason console is still on 0.12. We dont want this filter logic in console, console uses 0.12 SDK
|
||||||
|
case version_compare ($requestFormat , '0.11.0', '<=') :
|
||||||
|
$requestFilter = new V11();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(isset($requestFilter)) {
|
||||||
|
$endpointIdentifier = $route->getLabel('sdk.namespace', 'unknown') . '.' . $route->getLabel('sdk.method', 'unknown');
|
||||||
|
$newParams = $requestFilter->parse($args->get(), $endpointIdentifier);
|
||||||
|
$args->set($newParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
$localeParam = (string) $request->getParam('locale', $request->getHeader('x-appwrite-locale', ''));
|
||||||
if (\in_array($localeParam, Config::getParam('locale-codes'))) {
|
if (\in_array($localeParam, Config::getParam('locale-codes'))) {
|
||||||
$locale->setDefault($localeParam);
|
$locale->setDefault($localeParam);
|
||||||
};
|
}
|
||||||
|
|
||||||
$route = $utopia->match($request);
|
|
||||||
|
|
||||||
if ($project->isEmpty()) {
|
if ($project->isEmpty()) {
|
||||||
throw new Exception('Project not found', 404);
|
throw new Exception('Project not found', 404);
|
||||||
|
|
@ -280,7 +298,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons
|
||||||
throw new Exception('Password reset is required', 412);
|
throw new Exception('Password reset is required', 412);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, ['utopia', 'request', 'response', 'console', 'project', 'dbForConsole', 'user', 'locale', 'clients']);
|
}, ['args', 'utopia', 'request', 'response', 'console', 'project', 'dbForConsole', 'user', 'locale', 'clients']);
|
||||||
|
|
||||||
App::options(function ($request, $response) {
|
App::options(function ($request, $response) {
|
||||||
/** @var Utopia\Swoole\Request $request */
|
/** @var Utopia\Swoole\Request $request */
|
||||||
|
|
|
||||||
36
composer.lock
generated
36
composer.lock
generated
|
|
@ -2138,16 +2138,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/database",
|
"name": "utopia-php/database",
|
||||||
"version": "0.13.0",
|
"version": "0.13.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/utopia-php/database.git",
|
"url": "https://github.com/utopia-php/database.git",
|
||||||
"reference": "2e13987364f4966ec8a36784d4fb5df3a84e4e78"
|
"reference": "a1b2849c991b6384fe70e3c2d0633256a4fb795b"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/2e13987364f4966ec8a36784d4fb5df3a84e4e78",
|
"url": "https://api.github.com/repos/utopia-php/database/zipball/a1b2849c991b6384fe70e3c2d0633256a4fb795b",
|
||||||
"reference": "2e13987364f4966ec8a36784d4fb5df3a84e4e78",
|
"reference": "a1b2849c991b6384fe70e3c2d0633256a4fb795b",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
|
@ -2195,9 +2195,9 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/utopia-php/database/issues",
|
"issues": "https://github.com/utopia-php/database/issues",
|
||||||
"source": "https://github.com/utopia-php/database/tree/0.13.0"
|
"source": "https://github.com/utopia-php/database/tree/0.13.1"
|
||||||
},
|
},
|
||||||
"time": "2021-12-27T12:59:50+00:00"
|
"time": "2021-12-29T14:04:55+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/domains",
|
"name": "utopia-php/domains",
|
||||||
|
|
@ -5655,16 +5655,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/console",
|
"name": "symfony/console",
|
||||||
"version": "v6.0.1",
|
"version": "v6.0.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/console.git",
|
"url": "https://github.com/symfony/console.git",
|
||||||
"reference": "fafd9802d386bf1c267e0249ddb7ceb14dcfdad4"
|
"reference": "dd434fa8d69325e5d210f63070014d889511fcb3"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/console/zipball/fafd9802d386bf1c267e0249ddb7ceb14dcfdad4",
|
"url": "https://api.github.com/repos/symfony/console/zipball/dd434fa8d69325e5d210f63070014d889511fcb3",
|
||||||
"reference": "fafd9802d386bf1c267e0249ddb7ceb14dcfdad4",
|
"reference": "dd434fa8d69325e5d210f63070014d889511fcb3",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
|
@ -5730,7 +5730,7 @@
|
||||||
"terminal"
|
"terminal"
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/console/tree/v6.0.1"
|
"source": "https://github.com/symfony/console/tree/v6.0.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|
@ -5746,7 +5746,7 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2021-12-09T12:47:37+00:00"
|
"time": "2021-12-27T21:05:08+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/polyfill-intl-grapheme",
|
"name": "symfony/polyfill-intl-grapheme",
|
||||||
|
|
@ -6077,16 +6077,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/string",
|
"name": "symfony/string",
|
||||||
"version": "v6.0.1",
|
"version": "v6.0.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/string.git",
|
"url": "https://github.com/symfony/string.git",
|
||||||
"reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32"
|
"reference": "bae261d0c3ac38a1f802b4dfed42094296100631"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/string/zipball/0cfed595758ec6e0a25591bdc8ca733c1896af32",
|
"url": "https://api.github.com/repos/symfony/string/zipball/bae261d0c3ac38a1f802b4dfed42094296100631",
|
||||||
"reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32",
|
"reference": "bae261d0c3ac38a1f802b4dfed42094296100631",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
|
@ -6142,7 +6142,7 @@
|
||||||
"utf8"
|
"utf8"
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/string/tree/v6.0.1"
|
"source": "https://github.com/symfony/string/tree/v6.0.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|
@ -6158,7 +6158,7 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2021-12-08T15:13:44+00:00"
|
"time": "2021-12-16T22:13:01+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "textalk/websocket",
|
"name": "textalk/websocket",
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ services:
|
||||||
- ./psalm.xml:/usr/src/code/psalm.xml
|
- ./psalm.xml:/usr/src/code/psalm.xml
|
||||||
- ./tests:/usr/src/code/tests
|
- ./tests:/usr/src/code/tests
|
||||||
- ./app:/usr/src/code/app
|
- ./app:/usr/src/code/app
|
||||||
# - ./vendor:/usr/src/code/vendor
|
- ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework
|
||||||
- ./docs:/usr/src/code/docs
|
- ./docs:/usr/src/code/docs
|
||||||
- ./src:/usr/src/code/src
|
- ./src:/usr/src/code/src
|
||||||
# - ./debug:/tmp
|
# - ./debug:/tmp
|
||||||
|
|
|
||||||
17
src/Appwrite/Utopia/Request/Filter.php
Normal file
17
src/Appwrite/Utopia/Request/Filter.php
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Utopia\Request;
|
||||||
|
|
||||||
|
abstract class Filter
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse params to another format.
|
||||||
|
*
|
||||||
|
* @param array $content
|
||||||
|
* @param string $model
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
abstract public function parse(array $content, string $model): array;
|
||||||
|
}
|
||||||
35
src/Appwrite/Utopia/Request/Filters/V11.php
Normal file
35
src/Appwrite/Utopia/Request/Filters/V11.php
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Utopia\Request\Filters;
|
||||||
|
|
||||||
|
use Appwrite\Utopia\Request\Filter;
|
||||||
|
|
||||||
|
class V11 extends Filter
|
||||||
|
{
|
||||||
|
// TODO: Should this class be called be V11 or V12?
|
||||||
|
// Convert 0.11 params format to 0.12 format
|
||||||
|
public function parse(array $content, string $model): array
|
||||||
|
{
|
||||||
|
$parsedResponse = [];
|
||||||
|
|
||||||
|
switch ($model) {
|
||||||
|
case "account.create":
|
||||||
|
$parsedResponse = $this->addUserId($content);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(empty($parsedResponse)) {
|
||||||
|
// TODO: Do we need execption? We dont need to find, right? Not found means no changes
|
||||||
|
// throw new Exception('Received invalid request model : '. $model);
|
||||||
|
$parsedResponse = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $parsedResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addUserId(array $content): array
|
||||||
|
{
|
||||||
|
$content['userId'] = 'unique()';
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue