From 32f917c78ac22544d113d21aac571da90d1c0a2c Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 22 Jun 2020 15:17:14 +0300 Subject: [PATCH] Updated namespace structure --- app/controllers/api/account.php | 3 +- app/init.php | 2 +- src/Appwrite/Response/Result/Sessions.php | 37 ------------------- .../{Response => Utopia}/Response.php | 11 +++--- src/Appwrite/{ => Utopia}/Response/Result.php | 2 +- .../{ => Utopia}/Response/Result/File.php | 4 +- .../{ => Utopia}/Response/Result/Files.php | 4 +- .../{ => Utopia}/Response/Result/Health.php | 4 +- .../{ => Utopia}/Response/Result/Log.php | 4 +- .../{ => Utopia}/Response/Result/Prefs.php | 4 +- .../{ => Utopia}/Response/Result/Session.php | 4 +- .../{ => Utopia}/Response/Result/Token.php | 4 +- .../{ => Utopia}/Response/Result/User.php | 6 +-- 13 files changed, 27 insertions(+), 62 deletions(-) delete mode 100644 src/Appwrite/Response/Result/Sessions.php rename src/Appwrite/{Response => Utopia}/Response.php (89%) rename src/Appwrite/{ => Utopia}/Response/Result.php (95%) rename src/Appwrite/{ => Utopia}/Response/Result/File.php (91%) rename src/Appwrite/{ => Utopia}/Response/Result/Files.php (91%) rename src/Appwrite/{ => Utopia}/Response/Result/Health.php (91%) rename src/Appwrite/{ => Utopia}/Response/Result/Log.php (88%) rename src/Appwrite/{ => Utopia}/Response/Result/Prefs.php (91%) rename src/Appwrite/{ => Utopia}/Response/Result/Session.php (88%) rename src/Appwrite/{ => Utopia}/Response/Result/Token.php (88%) rename src/Appwrite/{ => Utopia}/Response/Result/User.php (86%) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index c2c2c642a..b4d9beb21 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -133,7 +133,8 @@ $utopia->post('/v1/account') ->setParam('resource', 'users/'.$user->getId()) ; - $response->dynamic($user); + $response->json($user->getArrayCopy()); + //$response->dynamic($user); } ); diff --git a/app/init.php b/app/init.php index 69795f56c..c6f531e08 100644 --- a/app/init.php +++ b/app/init.php @@ -22,7 +22,7 @@ use Appwrite\Database\Document; use Appwrite\Database\Validator\Authorization; use Appwrite\Database\Adapter\MySQL as MySQLAdapter; use Appwrite\Database\Adapter\Redis as RedisAdapter; -use Appwrite\Response\Response; +use Appwrite\Utopia\Response; use PHPMailer\PHPMailer\PHPMailer; const APP_NAME = 'Appwrite'; diff --git a/src/Appwrite/Response/Result/Sessions.php b/src/Appwrite/Response/Result/Sessions.php deleted file mode 100644 index b778655a2..000000000 --- a/src/Appwrite/Response/Result/Sessions.php +++ /dev/null @@ -1,37 +0,0 @@ -addRule('$id', 'string', 'Session ID.', '5e5ea5c16897e') - ->addRule('expire', 'integer', 'Session expiration date in UNIX format.', 1583261121) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'Session'; - } - - /** - * Get Collection - * - * @return string - */ - public function getCollection():string - { - return Database::SYSTEM_COLLECTION_TOKENS; - } -} \ No newline at end of file diff --git a/src/Appwrite/Response/Response.php b/src/Appwrite/Utopia/Response.php similarity index 89% rename from src/Appwrite/Response/Response.php rename to src/Appwrite/Utopia/Response.php index 4abb0c36c..cd25802cc 100644 --- a/src/Appwrite/Response/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -1,10 +1,11 @@ setResult(new User) + ->setResult(new User()) ; } @@ -47,7 +48,7 @@ class Response extends UtopiaResponse public function getResult(string $key): Result { if(!isset($this->results[$key])) { - throw new Exception('Undefined result'); + throw new Exception('Undefined result: '.$key); } return $this->results[$key]; @@ -66,7 +67,7 @@ class Response extends UtopiaResponse foreach($result->getRules() as $key => $rule) { if(!isset($data[$key])) { - throw new Exception('Missing result key'); + throw new Exception('Missing response key: ' . $key); } $output[$key] = $data[$key]; diff --git a/src/Appwrite/Response/Result.php b/src/Appwrite/Utopia/Response/Result.php similarity index 95% rename from src/Appwrite/Response/Result.php rename to src/Appwrite/Utopia/Response/Result.php index adc1c9f7d..a65f7ae10 100644 --- a/src/Appwrite/Response/Result.php +++ b/src/Appwrite/Utopia/Response/Result.php @@ -1,6 +1,6 @@