private function getSerialized(AbstractQuery $query) { if ($query instanceof CollectionQuery) { return '(' . implode(' ' . $query->getType() . ' ', $this->serializeQueries($query->getSubQueries())) . ')'; } return $this->commandsSerializer->serialize($query); }
/** * @since 0.2 * * @param Reference $reference new reference value * @param Statement|StatementGuid|string $statement Statement object or GUID which has the reference * @param Reference|string $targetReference target (old) reference of hash * @param EditInfo|null $editInfo * * @return bool * @throws UnexpectedValueException */ public function set(Reference $reference, $statement, $targetReference = null, EditInfo $editInfo = null) { if (is_string($statement)) { $guid = $statement; } else { if ($statement instanceof StatementGuid) { $guid = $statement->getSerialization(); } else { if ($statement instanceof Statement) { $guid = $statement->getGuid(); } else { throw new UnexpectedValueException('Could not get statement guid from $target'); } } } if (!is_string($guid)) { throw new UnexpectedValueException('Unexpected statement guid got from $target'); } $referenceSerialization = $this->referenceSerializer->serialize($reference); $params = array('statement' => $guid, 'snaks' => json_encode($referenceSerialization['snaks']), 'snaks-order' => json_encode($referenceSerialization['snaks-order'])); if (!is_null($targetReference)) { if ($targetReference instanceof Reference) { $targetReference = $reference->getHash(); } if (!is_string($targetReference)) { throw new UnexpectedValueException('Could not get reference hash from $targetReference'); } $params['reference'] = $targetReference; } $this->api->postRequest('wbsetreference', $params, $editInfo); return true; }
private function getDataSection() { $data = []; foreach ($this->item->statements as $simpleStatement) { $data[$simpleStatement->propertyName] = $this->statementSerializer->serialize($simpleStatement); } return $data; }
private function getSerialized(ReferenceList $references) { $serialization = array(); foreach ($references as $reference) { $serialization[] = $this->referenceSerializer->serialize($reference); } return $serialization; }
private function getSerialized(MediaInfo $mediaInfo) { $serialization = array('type' => $mediaInfo->getType(), 'labels' => $this->termListSerializer->serialize($mediaInfo->getLabels()), 'descriptions' => $this->termListSerializer->serialize($mediaInfo->getDescriptions()), 'statements' => $this->statementListSerializer->serialize($mediaInfo->getStatements())); $id = $mediaInfo->getId(); if ($id !== null) { $serialization['id'] = $id->getSerialization(); } return $serialization; }
/** * @since 0.2 * * @param DataValue $value * @param string $dataTypeId * @param GenericOptions $options * * @returns string */ public function format(DataValue $value, $dataTypeId, GenericOptions $options = null) { if ($options === null) { $options = new GenericOptions(); } $params = array('datavalue' => json_encode($this->dataValueSerializer->serialize($value)), 'datatype' => $dataTypeId, 'options' => json_encode($options->getOptions())); $result = $this->api->getRequest(new SimpleRequest('wbformatvalue', $params)); return $result['result']; }
/** * @since 0.5 * * @param Statement $statement * @param EditInfo|null $editInfo * * @throws InvalidArgumentException * @return bool * * @todo allow setting of indexes */ public function set(Statement $statement, EditInfo $editInfo = null) { if ($statement->getGuid() === null) { throw new InvalidArgumentException('Can not set a statement that does not have a GUID'); } $params = array('claim' => $this->statementSerializer->serialize($statement)); $this->api->postRequest('wbsetclaim', $params, $editInfo); return true; }
/** * @param TermList $termList * * @return array */ private function getSerialized(TermList $termList) { $serialization = array(); foreach ($termList->getIterator() as $term) { $serialization[$term->getLanguageCode()] = $this->termSerializer->serialize($term); } if ($this->useObjectsForMaps) { $serialization = (object) $serialization; } return $serialization; }
private function getSerialized(Snak $snak) { $serialization = array('snaktype' => $snak->getType(), 'property' => $snak->getPropertyId()->getSerialization()); if ($this->serializeWithHash) { $serialization['hash'] = $snak->getHash(); } if ($snak instanceof PropertyValueSnak) { $serialization['datavalue'] = $this->dataValueSerializer->serialize($snak->getDataValue()); } return $serialization; }
/** * @param AliasGroupList $aliasGroupList * * @return array */ private function getSerialized(AliasGroupList $aliasGroupList) { $serialization = array(); foreach ($aliasGroupList->getIterator() as $aliasGroup) { $serialization[$aliasGroup->getLanguageCode()] = $this->aliasGroupSerializer->serialize($aliasGroup); } if ($this->useObjectsForMaps) { $serialization = (object) $serialization; } return $serialization; }
private function getDataSection() { $data = []; foreach ($this->item->statements as $simpleStatement) { $propertyId = $simpleStatement->propertyId->getSerialization(); if (array_key_exists($propertyId, $this->propertyMap)) { $data[$this->propertyMap[$propertyId]] = $this->statementSerializer->serialize($simpleStatement); } } return $data; }
private function getSerialized(SnakList $snaks) { $serialization = array(); /** * @var Snak $snak */ foreach ($snaks as $snak) { $serialization[$snak->getPropertyId()->getSerialization()][] = $this->snakSerializer->serialize($snak); } if ($this->useObjectsForMaps) { $serialization = (object) $serialization; } return $serialization; }
private function getSerialized(StatementList $statementList) { $serialization = array(); foreach ($statementList->toArray() as $statement) { $idSerialization = $statement->getPropertyId()->getSerialization(); if (!array_key_exists($idSerialization, $serialization)) { $serialization[$idSerialization] = array(); } $serialization[$idSerialization][] = $this->statementSerializer->serialize($statement); } if ($this->useObjectsForMaps) { $serialization = (object) $serialization; } return $serialization; }
private function addQualifiersToSerialization(Statement $statement, &$serialization) { $qualifiers = $statement->getQualifiers(); if ($qualifiers->count() !== 0) { $serialization['qualifiers'] = $this->qualifierSnaksSerializer->serialize($qualifiers); $serialization['qualifiers-order'] = $this->buildQualifiersOrderList($qualifiers); } }
private function addSiteLinksToSerialization(Item $item, array &$serialization) { $serialization['sitelinks'] = array(); foreach ($item->getSiteLinkList()->toArray() as $siteLink) { $serialization['sitelinks'][$siteLink->getSiteId()] = $this->siteLinkSerializer->serialize($siteLink); } if ($this->useObjectsForMaps) { $serialization['sitelinks'] = (object) $serialization['sitelinks']; } }
/** * @since 0.1 * @param Revision $revision * @param EditInfo|null $editInfo * * @throws RuntimeException * @throws InvalidArgumentException * @returns Item|Property new version of the entity */ public function save(Revision $revision, EditInfo $editInfo = null) { if (!$revision->getContent()->getData() instanceof EntityDocument) { throw new RuntimeException('Can only save Content of EntityDocuments'); } /** @var Item|Property $entity */ $entity = $revision->getContent()->getData(); $serialized = $this->entitySerializer->serialize($entity); $params = array('data' => json_encode($serialized)); $revId = $revision->getId(); if (!is_null($revId)) { $params['baserevid'] = $revId; } $entityId = $entity->getId(); if (!is_null($entityId)) { $params['id'] = $entityId->getSerialization(); // Always clear so that removing elements is possible $params['clear'] = 'true'; // Add more detail to the default "Cleared an entity" summary // Note: this is later overridden if a summary is provided in the EditInfo $params['summary'] = 'Edited a ' . $entity->getType(); } else { $params['new'] = $entity->getType(); } // If no editInfo is explicitly passed call back to the one in the revision? if ($editInfo === null) { $editInfo = $revision->getEditInfo(); } if ($editInfo->getBot()) { $params['bot'] = true; } if ($editInfo->getMinor()) { $params['minor'] = true; } $summary = $editInfo->getSummary(); if (!empty($summary)) { $params['summary'] = $summary; } $result = $this->api->postRequest('wbeditentity', $params, $editInfo); return $this->entityDeserializer->deserialize($result['entity']); }
/** * Encodes an Entity into a blob for storage. * * @see EntityHandler::serializeContent() * * @param EntityDocument $entity * @param string|null $format The desired serialization format. * * @throws InvalidArgumentException If the format is not supported. * @throws MWContentSerializationException * @return string A blob representing the given Entity. */ public function encodeEntity(EntityDocument $entity, $format) { try { $data = $this->entitySerializer->serialize($entity); $blob = $this->encodeEntityContentData($data, $format); if ($this->maxBlobSize > 0 && strlen($blob) > $this->maxBlobSize) { throw new MWContentSerializationException('Content too big! Entity: ' . $entity->getId()); } return $blob; } catch (SerializationException $ex) { MWExceptionHandler::logException($ex); throw new MWContentSerializationException($ex->getMessage(), 0, $ex); } }
/** * @param EntityId $entityId * * @throws EntityLookupException * @throws StorageException * * @return string|null */ protected function generateDumpForEntityId(EntityId $entityId) { try { $entity = $this->entityLookup->getEntity($entityId); if (!$entity) { throw new EntityLookupException($entityId, 'Entity not found: ' . $entityId->getSerialization()); } } catch (MWContentSerializationException $ex) { throw new StorageException('Deserialization error for ' . $entityId->getSerialization()); } catch (RevisionedUnresolvedRedirectException $e) { // Redirects aren't supposed to be in the JSON dumps return null; } $data = $this->entitySerializer->serialize($entity); $data = $this->injectEntitySerializationWithDataTypes($data); // HACK: replace empty arrays with objects at the first level of the array foreach ($data as &$element) { if (empty($element)) { $element = new stdClass(); } } $json = $this->encode($data); return $json; }
private function serializeProperty() : array { return array_merge(['type' => $this->property->type], $this->entitySerializer->serialize($this->property)); }
/** * @param AbstractQuery $query * @return ItemId[] * * @throws WikibaseQueryApiException */ public function doQuery(AbstractQuery $query) { $result = $this->api->doQuery(['q' => $this->querySerializer->serialize($query)]); return $this->parseItemList($result['items']); }
/** * @param EntityDocument $entityDocument * @return array */ public function buildDocumentForEntity(EntityDocument $entityDocument) { return $this->addIndexedDataToSerialization($this->filterLanguages($this->entitySerializer->serialize($entityDocument))); }
private function getSerialized(TypedSnak $typedSnak) { $serialization = $this->snakSerializer->serialize($typedSnak->getSnak()); $serialization['datatype'] = $typedSnak->getDataTypeId(); return $serialization; }
private function getSerialized(Reference $reference) { return array('hash' => $reference->getHash(), 'snaks' => $this->snaksSerializer->serialize($reference->getSnaks()), 'snaks-order' => $this->buildSnakListOrderList($reference->getSnaks())); }
private function assertSerializesWithoutException(Serializer $serializer, $object) { $serializer->serialize($object); $this->assertTrue(true, 'No exception occurred during serialization'); }
/** * @param Entity $entity * * @return array */ public function serializeEntity(Entity $entity) { $data = $this->serializer->serialize($entity); return $data; }
public function testWithUnsupportedObject() { $this->setExpectedException('Serializers\\Exceptions\\UnsupportedObjectException'); $this->serializer->serialize(new PropertyNoValueSnak(42)); }
private function serializeProperty() { $serialization = $this->foundationalSerializer->serialize($this->property); $serialization['type'] = $this->property->type; return $serialization; }
private function addStatementListToSerialization(Property $property, array &$serialization) { $serialization['claims'] = $this->statementListSerializer->serialize($property->getStatements()); }