diff --git a/pandora_console/include/rest-api/models/Model.php b/pandora_console/include/rest-api/models/Model.php new file mode 100644 index 0000000000..563467f9d0 --- /dev/null +++ b/pandora_console/include/rest-api/models/Model.php @@ -0,0 +1,64 @@ +validateData($unknownData); + $this->data = $this->decode($unknownData); + } + + + public static function fromArray(array $data): self + { + return new self($data); + } + + + public function toJson(): string + { + return \json_encode($this->data); + } + + + public function __toString(): string + { + return $this->toJson(); + } + + + protected static function parseBool(mixed $value): boolean + { + if (\is_bool($value) === true) { + return $value; + } else if (\is_numeric($value) === true) { + return $value > 0; + } else if (\is_string($value) === true) { + return $value === '1' || $value === 'true'; + } else { + return false; + } + } + + + protected static function notEmptyStringOr(mixed $val, string $def): mixed + { + return (\is_string($val) === true && count($val) > 0) ? $val : $def; + } + + +}