2020-06-05 21:53:06 +12:00
|
|
|
<?php
|
|
|
|
|
2020-06-23 00:17:14 +12:00
|
|
|
namespace Appwrite\Utopia\Response;
|
2020-06-05 21:53:06 +12:00
|
|
|
|
2020-06-24 03:01:20 +12:00
|
|
|
abstract class Model
|
2020-06-05 21:53:06 +12:00
|
|
|
{
|
2020-11-08 11:14:36 +13:00
|
|
|
const TYPE_STRING = 'string';
|
|
|
|
const TYPE_INTEGER = 'integer';
|
|
|
|
const TYPE_FLOAT = 'float';
|
|
|
|
const TYPE_BOOLEAN = 'boolean';
|
|
|
|
const TYPE_JSON = 'json';
|
|
|
|
|
2020-11-12 11:01:31 +13:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $none = false;
|
|
|
|
|
2020-10-27 13:08:29 +13:00
|
|
|
/**
|
2020-10-30 02:07:56 +13:00
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $any = false;
|
|
|
|
|
2020-11-12 18:12:14 +13:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $public = true;
|
|
|
|
|
2020-10-30 02:07:56 +13:00
|
|
|
/**
|
|
|
|
* @var array
|
2020-10-27 13:08:29 +13:00
|
|
|
*/
|
2020-06-05 21:53:06 +12:00
|
|
|
protected $rules = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Name
|
2021-10-07 03:22:38 +13:00
|
|
|
*
|
2020-06-05 21:53:06 +12:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
abstract public function getName():string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Collection
|
2021-10-07 03:22:38 +13:00
|
|
|
*
|
2020-06-05 21:53:06 +12:00
|
|
|
* @return string
|
|
|
|
*/
|
2020-06-24 03:01:20 +12:00
|
|
|
abstract public function getType():string;
|
2020-06-05 21:53:06 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Rules
|
2021-10-07 03:22:38 +13:00
|
|
|
*
|
2020-10-27 13:08:29 +13:00
|
|
|
* @return array
|
2020-06-05 21:53:06 +12:00
|
|
|
*/
|
|
|
|
public function getRules(): array
|
|
|
|
{
|
|
|
|
return $this->rules;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a New Rule
|
|
|
|
*/
|
2020-06-23 04:25:01 +12:00
|
|
|
protected function addRule(string $key, array $options): self
|
2020-06-05 21:53:06 +12:00
|
|
|
{
|
2020-06-23 04:25:01 +12:00
|
|
|
$this->rules[$key] = array_merge([
|
2020-11-08 11:14:36 +13:00
|
|
|
'require' => true,
|
2020-06-23 04:25:01 +12:00
|
|
|
'type' => '',
|
|
|
|
'description' => '',
|
|
|
|
'default' => null,
|
|
|
|
'example' => '',
|
|
|
|
'array' => false,
|
|
|
|
], $options);
|
2020-06-05 21:53:06 +12:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2020-10-30 02:07:56 +13:00
|
|
|
|
2020-11-08 11:14:36 +13:00
|
|
|
public function getRequired()
|
|
|
|
{
|
|
|
|
$list = [];
|
|
|
|
|
2021-10-07 03:22:38 +13:00
|
|
|
foreach ($this->rules as $key => $rule) {
|
|
|
|
if (isset($rule['require']) || $rule['require']) {
|
2020-11-08 11:14:36 +13:00
|
|
|
$list[] = $key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
2020-11-12 11:01:31 +13:00
|
|
|
/**
|
|
|
|
* Is None
|
2021-10-07 03:22:38 +13:00
|
|
|
*
|
2020-11-12 11:01:31 +13:00
|
|
|
* Use to check if response is empty
|
2021-10-07 03:22:38 +13:00
|
|
|
*
|
2020-11-12 11:01:31 +13:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isNone(): bool
|
|
|
|
{
|
|
|
|
return $this->none;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is Any
|
2021-10-07 03:22:38 +13:00
|
|
|
*
|
2020-11-12 11:01:31 +13:00
|
|
|
* Use to check if response is a wildcard
|
2021-10-07 03:22:38 +13:00
|
|
|
*
|
2020-11-12 11:01:31 +13:00
|
|
|
* @return bool
|
|
|
|
*/
|
2020-10-30 02:07:56 +13:00
|
|
|
public function isAny(): bool
|
|
|
|
{
|
|
|
|
return $this->any;
|
|
|
|
}
|
2020-11-12 18:12:14 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is Public
|
2021-10-07 03:22:38 +13:00
|
|
|
*
|
2020-11-12 18:12:14 +13:00
|
|
|
* Should this model be publicly available in docs and spec files?
|
2021-10-07 03:22:38 +13:00
|
|
|
*
|
2020-11-12 18:12:14 +13:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isPublic(): bool
|
|
|
|
{
|
|
|
|
return $this->public;
|
|
|
|
}
|
2021-10-07 03:22:38 +13:00
|
|
|
}
|