1
0
Fork 0
mirror of synced 2024-09-29 08:51:28 +13:00
appwrite/src/Appwrite/Utopia/Response/Model.php

123 lines
2 KiB
PHP
Raw Normal View History

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;
/**
* @var bool
*/
protected $any = false;
/**
* @var bool
*/
protected $public = true;
/**
* @var array
*/
2020-06-05 21:53:06 +12:00
protected $rules = [];
/**
* Get Name
*
2020-06-05 21:53:06 +12:00
* @return string
*/
abstract public function getName():string;
/**
* Get Collection
*
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
*
* @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-11-08 11:14:36 +13:00
public function getRequired()
{
$list = [];
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
*
2020-11-12 11:01:31 +13:00
* Use to check if response is empty
*
2020-11-12 11:01:31 +13:00
* @return bool
*/
public function isNone(): bool
{
return $this->none;
}
/**
* Is Any
*
2020-11-12 11:01:31 +13:00
* Use to check if response is a wildcard
*
2020-11-12 11:01:31 +13:00
* @return bool
*/
public function isAny(): bool
{
return $this->any;
}
/**
* Is Public
*
* Should this model be publicly available in docs and spec files?
*
* @return bool
*/
public function isPublic(): bool
{
return $this->public;
}
}