示例#1
0
 /**
  * Parses a given fragment. For internal usage.
  *
  * @param  \stdClass                           $json the json bit retrieved from the API that represents any fragment.
  * @return \Prismic\Fragment\FragmentInterface the manipulable object for that fragment.
  */
 public static function parseFragment($json)
 {
     if (is_object($json) && property_exists($json, "type")) {
         if ($json->type === "Image") {
             $data = $json->value;
             $views = array();
             foreach ($json->value->views as $key => $jsonView) {
                 $views[$key] = ImageView::parse($jsonView);
             }
             $mainView = ImageView::parse($data->main, $views);
             return new Image($mainView, $views);
         }
         if ($json->type === "Color") {
             return new Color($json->value);
         }
         if ($json->type === "GeoPoint") {
             return new GeoPoint($json->value->latitude, $json->value->longitude);
         }
         if ($json->type === "Number") {
             return new Number($json->value);
         }
         if ($json->type === "Date") {
             return new Date($json->value);
         }
         if ($json->type === "Timestamp") {
             return new Timestamp($json->value);
         }
         if ($json->type === "Text") {
             return new Text($json->value);
         }
         if ($json->type === "Select") {
             return new Text($json->value);
         }
         if ($json->type === "Embed") {
             return Embed::parse($json->value);
         }
         if ($json->type === "Link.web") {
             return WebLink::parse($json->value);
         }
         if ($json->type === "Link.document") {
             return DocumentLink::parse($json->value);
         }
         if ($json->type === "Link.file") {
             return FileLink::parse($json->value);
         }
         if ($json->type === "Link.image") {
             return ImageLink::parse($json->value);
         }
         if ($json->type === "StructuredText") {
             return StructuredText::parse($json->value);
         }
         if ($json->type === "Group") {
             return Group::parse($json->value);
         }
         if ($json->type === "SliceZone") {
             return SliceZone::parse($json->value);
         }
         return null;
     }
 }
示例#2
0
 /**
  * Parses a given Group fragment. Not meant to be used except for testing.
  *
  * @param  \stdClass                $json the json bit retrieved from the API that represents a Group fragment.
  * @return \Prismic\Fragment\Group  the manipulable object for that Group fragment.
  */
 public static function parse($json)
 {
     $array = array();
     foreach ($json as $subfragmentListJson) {
         $subfragmentList = Group::parseSubfragmentList($subfragmentListJson);
         if (isset($subfragmentList)) {
             array_push($array, $subfragmentList);
         }
     }
     return new Group($array);
 }
示例#3
0
 /**
  * @depends testOffsetExists
  */
 public function testOffsetGet(Group $group)
 {
     foreach ($group->getArray() as $groupDoc) {
         $this->assertInstanceOf('\\Prismic\\Fragment\\Text', $groupDoc['element_one']);
     }
 }