[core] int_props + bool_props -> prop_types
This commit is contained in:
parent
bbea373c19
commit
fb034af699
5 changed files with 35 additions and 11 deletions
|
@ -8,6 +8,13 @@ use GQLA\Type;
|
||||||
use GQLA\Field;
|
use GQLA\Field;
|
||||||
use GQLA\Query;
|
use GQLA\Query;
|
||||||
|
|
||||||
|
enum ImagePropType
|
||||||
|
{
|
||||||
|
case BOOL;
|
||||||
|
case INT;
|
||||||
|
case STRING;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Image
|
* Class Image
|
||||||
*
|
*
|
||||||
|
@ -56,10 +63,23 @@ class Image implements \ArrayAccess
|
||||||
public ?int $length = null;
|
public ?int $length = null;
|
||||||
public ?string $tmp_file = null;
|
public ?string $tmp_file = null;
|
||||||
|
|
||||||
|
/** @var array<string, ImagePropType> */
|
||||||
|
public static array $prop_types = [
|
||||||
|
"id" => ImagePropType::INT,
|
||||||
|
"owner_id" => ImagePropType::INT,
|
||||||
|
"locked" => ImagePropType::BOOL,
|
||||||
|
"lossless" => ImagePropType::BOOL,
|
||||||
|
"video" => ImagePropType::BOOL,
|
||||||
|
"video_codec" => ImagePropType::STRING,
|
||||||
|
"image" => ImagePropType::BOOL,
|
||||||
|
"audio" => ImagePropType::BOOL,
|
||||||
|
"height" => ImagePropType::INT,
|
||||||
|
"width" => ImagePropType::INT,
|
||||||
|
"filesize" => ImagePropType::INT,
|
||||||
|
"length" => ImagePropType::INT,
|
||||||
|
];
|
||||||
/** @var array<string, mixed> */
|
/** @var array<string, mixed> */
|
||||||
private array $dynamic_props = [];
|
private array $dynamic_props = [];
|
||||||
public static array $bool_props = ["locked", "lossless", "video", "audio", "image"];
|
|
||||||
public static array $int_props = ["id", "owner_id", "height", "width", "filesize", "length"];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One will very rarely construct an image directly, more common
|
* One will very rarely construct an image directly, more common
|
||||||
|
@ -78,10 +98,14 @@ class Image implements \ArrayAccess
|
||||||
|
|
||||||
if (is_null($value)) {
|
if (is_null($value)) {
|
||||||
$value = null;
|
$value = null;
|
||||||
} elseif (in_array($name, self::$bool_props)) {
|
} else {
|
||||||
$value = bool_escape((string)$value);
|
if(array_key_exists($name, static::$prop_types)) {
|
||||||
} elseif (in_array($name, self::$int_props)) {
|
$value = match(static::$prop_types[$name]) {
|
||||||
$value = int_escape((string)$value);
|
ImagePropType::BOOL => bool_escape((string)$value),
|
||||||
|
ImagePropType::INT => int_escape((string)$value),
|
||||||
|
ImagePropType::STRING => (string)$value,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(property_exists($this, $name)) {
|
if(property_exists($this, $name)) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Approval extends Extension
|
||||||
$config->set_default_bool(ApprovalConfig::IMAGES, false);
|
$config->set_default_bool(ApprovalConfig::IMAGES, false);
|
||||||
$config->set_default_bool(ApprovalConfig::COMMENTS, false);
|
$config->set_default_bool(ApprovalConfig::COMMENTS, false);
|
||||||
|
|
||||||
Image::$bool_props[] = "approved";
|
Image::$prop_types["approved"] = ImagePropType::BOOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onImageAddition(ImageAdditionEvent $event): void
|
public function onImageAddition(ImageAdditionEvent $event): void
|
||||||
|
|
|
@ -18,7 +18,7 @@ class PrivateImage extends Extension
|
||||||
|
|
||||||
public function onInitExt(InitExtEvent $event): void
|
public function onInitExt(InitExtEvent $event): void
|
||||||
{
|
{
|
||||||
Image::$bool_props[] = "private";
|
Image::$prop_types["private"] = ImagePropType::BOOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInitUserConfig(InitUserConfigEvent $event): void
|
public function onInitUserConfig(InitUserConfigEvent $event): void
|
||||||
|
|
|
@ -27,8 +27,8 @@ class Relationships extends Extension
|
||||||
|
|
||||||
public function onInitExt(InitExtEvent $event): void
|
public function onInitExt(InitExtEvent $event): void
|
||||||
{
|
{
|
||||||
Image::$bool_props[] = "has_children";
|
Image::$prop_types["parent_id"] = ImagePropType::INT;
|
||||||
Image::$int_props[] = "parent_id";
|
Image::$prop_types["has_children"] = ImagePropType::BOOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
|
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Trash extends Extension
|
||||||
|
|
||||||
public function onInitExt(InitExtEvent $event): void
|
public function onInitExt(InitExtEvent $event): void
|
||||||
{
|
{
|
||||||
Image::$bool_props[] = "trash";
|
Image::$prop_types["trash"] = ImagePropType::BOOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event): void
|
public function onPageRequest(PageRequestEvent $event): void
|
||||||
|
|
Reference in a new issue