/**
  * @see JsonUnserializable::jsonUnserialize()
  */
 public static final function jsonUnserialize($json)
 {
     if (!is_array($json) && !is_object($json)) {
         throw UnserializationException::invalidValue('CRS', $json, 'array or object');
     }
     $json = new \ArrayObject($json);
     if (!$json->offsetExists('type')) {
         throw UnserializationException::missingProperty('CRS', 'type', 'string');
     }
     if (!$json->offsetExists('properties')) {
         throw UnserializationException::missingProperty('CRS', 'properties', 'array or object');
     }
     $type = (string) $json['type'];
     $properties = $json['properties'];
     switch ($type) {
         case 'link':
             return Linked::jsonUnserializeFromProperties($properties);
         case 'name':
             return Named::jsonUnserializeFromProperties($properties);
     }
     throw UnserializationException::unsupportedType('CRS', $type);
 }
Exemplo n.º 2
0
 public function testSerializationWithoutHrefType()
 {
     $crs = new Linked('http://example.com/crs/42');
     $expected = array('type' => 'link', 'properties' => array('href' => 'http://example.com/crs/42'));
     $this->assertSame($expected, $crs->jsonSerialize());
 }