From 9c2e33da8b85f55d75cf3ff21ea788c99b3115be Mon Sep 17 00:00:00 2001 From: Athlon1600 Date: Thu, 2 Nov 2023 21:36:22 -0500 Subject: [PATCH] AbstractModel is now JsonObject --- src/Models/AbstractModel.php | 35 --------------------------------- src/Models/JsonObject.php | 38 ++++++++++++++++++++++++++++++++++++ src/Models/StreamFormat.php | 2 +- 3 files changed, 39 insertions(+), 36 deletions(-) delete mode 100644 src/Models/AbstractModel.php create mode 100644 src/Models/JsonObject.php diff --git a/src/Models/AbstractModel.php b/src/Models/AbstractModel.php deleted file mode 100644 index 9daf1bf..0000000 --- a/src/Models/AbstractModel.php +++ /dev/null @@ -1,35 +0,0 @@ -fillFromArray($array); - } - } - - public static function fromArray($array) - { - return new static($array); - } - - private function fillFromArray($array) - { - foreach ($array as $key => $val) { - if (property_exists($this, $key)) { - $this->{$key} = $val; - } - } - } - - /** - * @return array - */ - public function toArray() - { - return get_object_vars($this); - } -} \ No newline at end of file diff --git a/src/Models/JsonObject.php b/src/Models/JsonObject.php new file mode 100644 index 0000000..13c3681 --- /dev/null +++ b/src/Models/JsonObject.php @@ -0,0 +1,38 @@ +_data = $data; + + foreach ($data as $key => $val) { + if (property_exists($this, $key)) { + $this->{$key} = $val; + } + } + } + + /** + * Get an item from an array using "dot" notation. + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function deepGet(string $key, $default = null) + { + return Utils::arrayGet($this->_data, $key, $default); + } + + public function toArray(): array + { + return get_object_vars($this); + } +} \ No newline at end of file diff --git a/src/Models/StreamFormat.php b/src/Models/StreamFormat.php index fffaf35..23b1a67 100644 --- a/src/Models/StreamFormat.php +++ b/src/Models/StreamFormat.php @@ -2,7 +2,7 @@ namespace YouTube\Models; -class StreamFormat extends AbstractModel +class StreamFormat extends JsonObject { public ?int $itag = null; public ?string $mimeType = null;