1
0
Fork 0
mirror of synced 2024-06-27 02:31:04 +12:00

Split attribute model into primitive types

This commit is contained in:
kodumbeats 2021-08-13 16:57:08 -04:00
parent 2fbc434e25
commit 3172f3073c
4 changed files with 143 additions and 21 deletions

View file

@ -28,25 +28,12 @@ class Attribute extends Model
'default' => '',
'example' => 'string',
])
->addRule('size', [
'type' => self::TYPE_STRING,
'description' => 'Attribute size.',
'default' => 0,
'example' => 128,
])
->addRule('required', [
'type' => self::TYPE_BOOLEAN,
'description' => 'Is attribute required?',
'default' => false,
'example' => true,
])
->addRule('signed', [
'type' => self::TYPE_BOOLEAN,
'description' => 'Is attribute signed?',
'default' => true,
'example' => true,
'required' => false,
])
->addRule('array', [
'type' => self::TYPE_BOOLEAN,
'description' => 'Is attribute an array?',
@ -54,14 +41,6 @@ class Attribute extends Model
'example' => false,
'required' => false
])
->addRule('filters', [
'type' => self::TYPE_STRING,
'description' => 'Attribute filters.',
'default' => [],
'example' => [],
'array' => true,
'required' => false,
])
;
}

View file

@ -0,0 +1,51 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model\Attribute;
class AttributeFloat extends Attribute
{
public function __construct()
{
$this
->addRule('min', [
'type' => self::TYPE_FLOAT,
'description' => 'Minimum value to enforce on new documents.',
'default' => null,
'example' => 0.5,
'array' => false,
'required' => false,
])
->addRule('max', [
'type' => self::TYPE_FLOAT,
'description' => 'Minimum value to enforce on new documents.',
'default' => null,
'example' => 2.5,
'array' => false,
'required' => false,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Float';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_FLOAT;
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model\Attribute;
class AttributeInteger extends Attribute
{
public function __construct()
{
$this
->addRule('min', [
'type' => self::TYPE_INTEGER,
'description' => 'Minimum value to enforce on new documents.',
'default' => null,
'example' => 0,
'array' => false,
'required' => false,
])
->addRule('max', [
'type' => self::TYPE_INTEGER,
'description' => 'Minimum value to enforce on new documents.',
'default' => null,
'example' => 10,
'array' => false,
'required' => false,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Integer';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_INTEGER;
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model\Attribute;
class AttributeString extends Attribute
{
public function __construct()
{
$this
->addRule('size', [
'type' => self::TYPE_STRING,
'description' => 'Attribute size.',
'default' => 0,
'example' => 128,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'String';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_ATTRIBUTE_STRING;
}
}