public function testSerialization() { $crs = new Named('urn:ogc:def:crs:OGC:1.3:CRS84'); $expected = array('type' => 'name', 'properties' => array('name' => 'urn:ogc:def:crs:OGC:1.3:CRS84')); $this->assertSame('name', $crs->getType()); $this->assertSame($expected['properties'], $crs->getProperties()); $this->assertSame($expected, $crs->jsonSerialize()); }
/** * @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); }