diff --git a/src/Instagram/Hydrator/ReelsHydrator.php b/src/Instagram/Hydrator/ReelsHydrator.php index f978130..508abfd 100644 --- a/src/Instagram/Hydrator/ReelsHydrator.php +++ b/src/Instagram/Hydrator/ReelsHydrator.php @@ -52,13 +52,9 @@ public function reelsBaseHydrator(\StdClass $node): Reels }, $node->video_versions)); if (property_exists($node, 'caption')) { - $reels->setCaption($node->caption->text); - $reels->setHashtags(InstagramHelper::buildHashtags($node->caption->text)); - } - - if (property_exists($node, 'caption')) { - if (property_exists($node->caption, 'text')) { + if (!empty($node->caption)) { $reels->setCaption($node->caption->text); + $reels->setHashtags(InstagramHelper::buildHashtags($node->caption->text)); } } diff --git a/src/Instagram/Model/Reels.php b/src/Instagram/Model/Reels.php index 271b036..ef405d5 100644 --- a/src/Instagram/Model/Reels.php +++ b/src/Instagram/Model/Reels.php @@ -425,4 +425,47 @@ public function getUser(): User { return $this->user; } + + /** + * @return array + */ + public function toArray(): array + { + return [ + "id" => $this->getId(), + "shortCode" => $this->getShortCode(), + "link" => $this->getLink(), + "likes" => $this->getLikes(), + "isLiked" => $this->isLiked(), + "comments" => $this->getComments(), + "views" => $this->getViews(), + "plays" => $this->getPlays(), + "duration" => $this->getDuration(), + "height" => $this->getHeight(), + "width" => $this->getWidth(), + "hasAudio" => $this->getHasAudio(), + "images" => array_map(function ($image) { + return (array) $image; + }, $this->getImages()), + "videos" => array_map(function ($video) { + return (array) $video; + }, $this->getVideos()), + "caption" => $this->getCaption(), + "location" => $this->getLocation(), + "date" => $this->getDate(), + "hashtags" => $this->getHashtags(), + "userTags" => array_map(function ($user) { + return $user->toArray(); + }, $this->getUserTags()), + "user" => $this->getUser()->toArray() + ]; + } + + /** + * @return array + */ + public function __serialize(): array + { + return $this->toArray(); + } } diff --git a/src/Instagram/Model/ReelsFeed.php b/src/Instagram/Model/ReelsFeed.php index 00308e3..ae0d9a5 100644 --- a/src/Instagram/Model/ReelsFeed.php +++ b/src/Instagram/Model/ReelsFeed.php @@ -52,4 +52,26 @@ public function hasMaxId(): bool { return $this->getMaxId() !== null; } + + /** + * @return array + */ + public function toArray(): array + { + return [ + "reels" => array_map(function ($reels) { + return $reels->toArray(); + }, $this->getReels()), + "hasMaxId" => $this->hasMaxId(), + "maxId" => $this->getMaxId(), + ]; + } + + /** + * @return array + */ + public function __serialize(): array + { + return $this->toArray(); + } }