src/AppBundle/Prismic/BlogPost.php line 76

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Prismic;
  3. use DateTime;
  4. use Prismic\Dom\RichText;
  5. use stdClass;
  6. class BlogPost
  7. {
  8.     /**
  9.      * @var string
  10.      */
  11.     public $uid;
  12.     /**
  13.      * @var string
  14.      */
  15.     public $published_at;
  16.     /**
  17.      * @var string
  18.      */
  19.     public $title;
  20.     /**
  21.      * @var string
  22.      */
  23.     public $subtitle;
  24.     /**
  25.      * @var string
  26.      */
  27.     public $body;
  28.     /**
  29.      * @var string
  30.      */
  31.     public $imageUrl;
  32.     /**
  33.      * @var string
  34.      */
  35.     public $imageAlt;
  36.     /**
  37.      * @param stdClass $document
  38.      */
  39.     public function __construct(stdClass $document)
  40.     {
  41.         $this->uid $document->slug ?? null;
  42.         $this->published_at = (new DateTime($document->published_at))->format('d/m/Y');
  43.         $this->title $document->title ?? null;
  44.         $this->subtitle $document->subtitle ?? null;
  45.         $this->body $document->body ?? null;
  46.         $image $document->image;
  47.         if($image){
  48.             $this->imageUrl $image->url ?? null;
  49.             $this->imageAlt $image->alt ?? null;
  50.         }
  51.     }
  52.     /**
  53.      * @param stdClass $document
  54.      *
  55.      * @return self
  56.      */
  57.     public static function create(stdClass $document): self
  58.     {
  59.         return new static($document);
  60.     }
  61. }