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;