[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\Query;
|
||||
|
||||
enum ImagePropType
|
||||
{
|
||||
case BOOL;
|
||||
case INT;
|
||||
case STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Image
|
||||
*
|
||||
|
@ -56,10 +63,23 @@ class Image implements \ArrayAccess
|
|||
public ?int $length = 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> */
|
||||
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
|
||||
|
@ -78,10 +98,14 @@ class Image implements \ArrayAccess
|
|||
|
||||
if (is_null($value)) {
|
||||
$value = null;
|
||||
} elseif (in_array($name, self::$bool_props)) {
|
||||
$value = bool_escape((string)$value);
|
||||
} elseif (in_array($name, self::$int_props)) {
|
||||
$value = int_escape((string)$value);
|
||||
} else {
|
||||
if(array_key_exists($name, static::$prop_types)) {
|
||||
$value = match(static::$prop_types[$name]) {
|
||||
ImagePropType::BOOL => bool_escape((string)$value),
|
||||
ImagePropType::INT => int_escape((string)$value),
|
||||
ImagePropType::STRING => (string)$value,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
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::COMMENTS, false);
|
||||
|
||||
Image::$bool_props[] = "approved";
|
||||
Image::$prop_types["approved"] = ImagePropType::BOOL;
|
||||
}
|
||||
|
||||
public function onImageAddition(ImageAdditionEvent $event): void
|
||||
|
|
|
@ -18,7 +18,7 @@ class PrivateImage extends Extension
|
|||
|
||||
public function onInitExt(InitExtEvent $event): void
|
||||
{
|
||||
Image::$bool_props[] = "private";
|
||||
Image::$prop_types["private"] = ImagePropType::BOOL;
|
||||
}
|
||||
|
||||
public function onInitUserConfig(InitUserConfigEvent $event): void
|
||||
|
|
|
@ -27,8 +27,8 @@ class Relationships extends Extension
|
|||
|
||||
public function onInitExt(InitExtEvent $event): void
|
||||
{
|
||||
Image::$bool_props[] = "has_children";
|
||||
Image::$int_props[] = "parent_id";
|
||||
Image::$prop_types["parent_id"] = ImagePropType::INT;
|
||||
Image::$prop_types["has_children"] = ImagePropType::BOOL;
|
||||
}
|
||||
|
||||
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
|
||||
|
|
|
@ -22,7 +22,7 @@ class Trash extends Extension
|
|||
|
||||
public function onInitExt(InitExtEvent $event): void
|
||||
{
|
||||
Image::$bool_props[] = "trash";
|
||||
Image::$prop_types["trash"] = ImagePropType::BOOL;
|
||||
}
|
||||
|
||||
public function onPageRequest(PageRequestEvent $event): void
|
||||
|
|
Reference in a new issue