From 416d767ff050ac4e4115c9e69363aa6b591dc7dd Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 22 Jun 2020 19:25:01 +0300 Subject: [PATCH] Changed rule structure --- src/Appwrite/Utopia/Response/Result.php | 14 ++++--- src/Appwrite/Utopia/Response/Result/User.php | 41 +++++++++++++++++--- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Result.php b/src/Appwrite/Utopia/Response/Result.php index a65f7ae101..facad4dc99 100644 --- a/src/Appwrite/Utopia/Response/Result.php +++ b/src/Appwrite/Utopia/Response/Result.php @@ -33,13 +33,15 @@ abstract class Result /** * Add a New Rule */ - protected function addRule(string $key, string $type, string $description, string $example): self + protected function addRule(string $key, array $options): self { - $this->rules[$key] = [ - 'type' => $type, - 'description' => $description, - 'example' => $example, - ]; + $this->rules[$key] = array_merge([ + 'type' => '', + 'description' => '', + 'default' => null, + 'example' => '', + 'array' => false, + ], $options); return $this; } diff --git a/src/Appwrite/Utopia/Response/Result/User.php b/src/Appwrite/Utopia/Response/Result/User.php index 2baae62ccb..e9afa14d2f 100644 --- a/src/Appwrite/Utopia/Response/Result/User.php +++ b/src/Appwrite/Utopia/Response/Result/User.php @@ -10,11 +10,42 @@ class User extends Result public function __construct() { $this - ->addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') - ->addRule('name', 'string', 'User name.', 'John Doe') - ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') - ->addRule('emailVerification', 'string', 'Email verification status.', true) - ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) + ->addRule('$id', [ + 'type' => 'string', + 'description' => 'User ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'User name.', + 'default' => '', + 'example' => 'John Doe', + ]) + ->addRule('email', [ + 'type' => 'string', + 'description' => 'User email address.', + 'default' => '', + 'example' => 'john@appwrite.io', + ]) + ->addRule('emailVerification', [ + 'type' => 'boolean', + 'description' => 'Email verification status.', + 'default' => false, + 'example' => true, + ]) + ->addRule('prefs', [ + 'type' => 'json', + 'description' => 'User preferences as a key-value object', + 'default' => new \stdClass, + 'example' => ['theme' => 'dark', 'timezone' => 'UTC'], + ]) + ->addRule('roles', [ + 'type' => 'string', + 'description' => 'User list of roles', + 'default' => [], + 'example' => [], + 'array' => true, + ]) ; }