Example #1
0
 /**
  * Parses a given block (for internal use)
  *
  * @param  \stdClass  $json the json bit retrieved from the API that represents a block.
  *
  * @return \Prismic\Fragment\Block\BlockInterface  the manipulable object for that block.
  */
 public static function parseBlock($json)
 {
     $label = NULL;
     if (property_exists($json, "label")) {
         $label = $json->label;
     }
     if (preg_match('/heading(\\d)/', $json->type, $level)) {
         $p = StructuredText::parseText($json);
         return new HeadingBlock($p->getText(), $p->getSpans(), $level[1], $label);
     }
     if ($json->type == 'paragraph') {
         $p = StructuredText::parseText($json);
         return new ParagraphBlock($p->getText(), $p->getSpans(), $label);
     }
     if ($json->type == 'list-item') {
         $p = StructuredText::parseText($json);
         return new ListItemBlock($p->getText(), $p->getSpans(), false, $label);
     }
     if ($json->type == 'o-list-item') {
         $p = StructuredText::parseText($json);
         return new ListItemBlock($p->getText(), $p->getSpans(), true, $label);
     }
     if ($json->type == 'image') {
         $view = ImageView::parse($json);
         return new ImageBlock($view, $label);
     }
     if ($json->type == 'embed') {
         return new EmbedBlock(Embed::parse($json), $label);
     }
     if ($json->type == 'preformatted') {
         $p = StructuredText::parseText($json);
         return new PreformattedBlock($p->getText(), $p->getSpans(), $label);
     }
     return null;
 }