/** * @param array $data * @return Snak * @throws Exception */ public function newFromArray(array $data) { if (!isset($data['snaktype']) || !isset($data['property'])) { throw new Exeption('Invalid Snak serialization'); } $dataValue = isset($data['datavalue']) ? \DataValues\DataValueFactory::singleton()->newDataValue($data['datavalue']['type'], $data['datavalue']['value']) : null; return new self($data['snaktype'], $data['property'], $dataValue); }
/** * @param string $json A JSON-encoded DataValue * * @throws UsageException * @throws LogicException * @return DataValue */ private function decodeDataValue($json) { $data = json_decode($json, true); if (!is_array($data)) { $this->errorReporter->dieError('Failed to decode datavalue', 'baddatavalue'); } try { $value = $this->dataValueFactory->newFromArray($data); return $value; } catch (IllegalValueException $ex) { $this->errorReporter->dieException($ex, 'baddatavalue'); } throw new LogicException('ApiErrorReporter::dieException did not throw a UsageException'); }