Changed rule structure

This commit is contained in:
Eldad Fux
2020-06-22 19:25:01 +03:00
parent 2b4d93b6e4
commit 416d767ff0
2 changed files with 44 additions and 11 deletions
+8 -6
View File
@@ -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;
}
+36 -5
View File
@@ -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,
])
;
}