Skip to content

Commit

Permalink
AbstractModel is now JsonObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Athlon1600 committed Nov 3, 2023
1 parent 7033cb3 commit 9c2e33d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
35 changes: 0 additions & 35 deletions src/Models/AbstractModel.php

This file was deleted.

38 changes: 38 additions & 0 deletions src/Models/JsonObject.php
@@ -0,0 +1,38 @@
<?php

namespace YouTube\Models;

use YouTube\Utils\Utils;

abstract class JsonObject
{
protected array $_data = [];

final public function __construct(array $data)
{
$this->_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);
}
}
2 changes: 1 addition & 1 deletion src/Models/StreamFormat.php
Expand Up @@ -2,7 +2,7 @@

namespace YouTube\Models;

class StreamFormat extends AbstractModel
class StreamFormat extends JsonObject
{
public ?int $itag = null;
public ?string $mimeType = null;
Expand Down

0 comments on commit 9c2e33d

Please sign in to comment.