diff --git a/core/imageboard/image.php b/core/imageboard/image.php index 0d61f2fd..f2c1f1a1 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -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 */ + 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 */ 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)) { diff --git a/ext/approval/main.php b/ext/approval/main.php index beb35087..6fe93007 100644 --- a/ext/approval/main.php +++ b/ext/approval/main.php @@ -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 diff --git a/ext/private_image/main.php b/ext/private_image/main.php index d7dfbe9d..24024a6c 100644 --- a/ext/private_image/main.php +++ b/ext/private_image/main.php @@ -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 diff --git a/ext/relationships/main.php b/ext/relationships/main.php index 211b90f1..b763210e 100644 --- a/ext/relationships/main.php +++ b/ext/relationships/main.php @@ -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 diff --git a/ext/trash/main.php b/ext/trash/main.php index 0f204377..57518cf6 100644 --- a/ext/trash/main.php +++ b/ext/trash/main.php @@ -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