<?php
namespace AppBundle\Prismic;
use DateTime;
use Prismic\Dom\RichText;
use stdClass;
class BlogPost
{
/**
* @var string
*/
public $uid;
/**
* @var string
*/
public $published_at;
/**
* @var string
*/
public $title;
/**
* @var string
*/
public $subtitle;
/**
* @var string
*/
public $body;
/**
* @var string
*/
public $imageUrl;
/**
* @var string
*/
public $imageAlt;
/**
* @param stdClass $document
*/
public function __construct(stdClass $document)
{
$this->uid = $document->slug ?? null;
$this->published_at = (new DateTime($document->published_at))->format('d/m/Y');
$this->title = $document->title ?? null;
$this->subtitle = $document->subtitle ?? null;
$this->body = $document->body ?? null;
$image = $document->image;
if($image){
$this->imageUrl = $image->url ?? null;
$this->imageAlt = $image->alt ?? null;
}
}
/**
* @param stdClass $document
*
* @return self
*/
public static function create(stdClass $document): self
{
return new static($document);
}
}