/** * @param Snak $snak */ private function processSnak(Snak $snak) { $propertyId = $snak->getPropertyId(); $this->entityIds[$propertyId->getSerialization()] = $propertyId; if ($snak instanceof PropertyValueSnak) { $this->processDataValue($snak->getDataValue()); } }
/** * @param Snak $snak * * @return string */ public function formatSnak(Snak $snak) { if ($snak instanceof PropertyValueSnak) { $value = $snak->getDataValue(); return $this->formatValue($value); } else { return $snak->getType(); } }
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; }
private function validateSnak(Snak $snak) { if (!$snak instanceof PropertyValueSnak) { return true; } $dataValue = $snak->getDataValue(); if (!$this->dataValueChecker->supportsDataValue($dataValue)) { return true; } return $this->dataValueChecker->checkDataValue($dataValue); }
/** * @see SnakFormatter::formatSnak * * @param Snak $snak * * @return string Either plain text, wikitext or HTML, depending on the SnakFormatter provided. */ public function formatSnak(Snak $snak) { if ($snak instanceof PropertyValueSnak) { $value = $snak->getDataValue(); if ($value instanceof EntityIdValue) { $entityId = $value->getEntityId(); $this->addLabelUsage($value->getEntityId()); $this->usageAccumulator->addTitleUsage($entityId); } } return $this->snakFormatter->formatSnak($snak); }
/** * @param Snak $snak */ private function processSnak(Snak $snak) { if ($snak instanceof PropertyValueSnak) { $id = $snak->getPropertyId(); $value = $snak->getDataValue(); if ($value instanceof StringValue && $this->propertyDataTypeMatcher->isMatchingDataType($id, 'commonsMedia')) { $fileName = str_replace(' ', '_', $value->getValue()); if ($fileName !== '') { $this->fileNames[$fileName] = null; } } } }
/** * @param Snak $snak */ private function processSnak(Snak $snak) { if ($snak instanceof PropertyValueSnak) { $id = $snak->getPropertyId(); $value = $snak->getDataValue(); if ($value instanceof StringValue && $this->propertyDataTypeMatcher->isMatchingDataType($id, 'url')) { $url = $value->getValue(); if ($url !== '') { $this->urls[$url] = null; } } } }
/** * @since 0.2 * * @param Snak $mainSnak * @param EntityId|Item|Property|string $target * @param EditInfo|null $editInfo * * @return string the GUID of the claim * @throws UnexpectedValueException */ public function create(Snak $mainSnak, $target, EditInfo $editInfo = null) { if (is_string($target)) { $entityId = $target; } elseif ($target instanceof EntityId) { $entityId = $target->getSerialization(); } elseif ($target instanceof Item || $target instanceof Property) { $entityId = $target->getId()->getSerialization(); } else { throw new UnexpectedValueException('$target needs to be an EntityId, Entity or string'); } $params = array('entity' => $entityId, 'snaktype' => $mainSnak->getType(), 'property' => $mainSnak->getPropertyId()->getSerialization()); if ($mainSnak instanceof PropertyValueSnak) { $serializedDataValue = $this->dataValueSerializer->serialize($mainSnak->getDataValue()); $params['value'] = json_encode($serializedDataValue['value']); } $result = $this->api->postRequest('wbcreateclaim', $params, $editInfo); return $result['claims']['id']; }
private function copySnak(Snak $mainSnak) { $newPropertyId = $this->entityMappingStore->getLocalId($mainSnak->getPropertyId()->getSerialization()); switch ($mainSnak->getType()) { case 'somevalue': return new PropertySomeValueSnak(new PropertyId($newPropertyId)); case 'novalue': return new PropertyNoValueSnak(new PropertyId($newPropertyId)); default: $value = $mainSnak->getDataValue(); if ($value instanceof EntityIdValue) { $localId = $this->entityMappingStore->getLocalId($value->getEntityId()->getSerialization()); if (!$localId) { $this->logger->error("Entity not found for {$localId}."); } $value = new EntityIdValue($this->idParser->parse($localId)); } return new PropertyValueSnak(new PropertyId($newPropertyId), $value); } }
protected function makeSetQualifierRequest($statementGuid, $snakhash, Snak $qualifier, EntityId $entityId) { $params = array('action' => 'wbsetqualifier', 'claim' => $statementGuid, 'snakhash' => $snakhash, 'snaktype' => $qualifier->getType(), 'property' => $qualifier->getPropertyId()->getSerialization()); if ($qualifier instanceof PropertyValueSnak) { $dataValue = $qualifier->getDataValue(); $params['value'] = FormatJson::encode($dataValue->getArrayValue()); } $this->makeValidRequest($params); /** @var StatementListProvider $entity */ $entity = WikibaseRepo::getDefaultInstance()->getEntityLookup()->getEntity($entityId); $statements = $entity->getStatements(); $statement = $statements->getFirstStatementWithGuid($params['claim']); $this->assertNotNull($statement); $this->assertTrue($statement->getQualifiers()->hasSnak($qualifier), 'The qualifier should exist in the qualifier list after making the request'); }
private function isSnakMorePrecise(Snak $a, Snak $b) { if ($a instanceof PropertyValueSnak && $b instanceof PropertyValueSnak) { return $a->getPropertyId()->equals($b->getPropertyId()) && $this->isDataValueMorePrecise($a->getDataValue(), $b->getDataValue()); } return $a->equals($b); }
public function formatSnakAsText(Snak $snak) { if ($snak instanceof PropertyValueSnak) { return $this->formatValueAsText($snak->getDataValue()); } else { return $snak->getType(); } }
/** * Validates a Snak. * For a PropertyValueSnak, this is done using the validators from the DataType * that is associated with the Snak's property. * Other Snak types are currently not validated. * * @see ValueValidator::validate() * * @param Snak $snak The value to validate * * @throws InvalidArgumentException * @return Result */ public function validate($snak) { if (!$snak instanceof Snak) { throw new InvalidArgumentException('Snak expected'); } // XXX: instead of an instanceof check, we could have multiple validators // with a canValidate() method, to determine which validator to use // for a given snak. $propertyId = $snak->getPropertyId(); try { $typeId = $this->propertyDataTypeLookup->getDataTypeIdForProperty($propertyId); if ($snak instanceof PropertyValueSnak) { $dataValue = $snak->getDataValue(); $result = $this->validateDataValue($dataValue, $typeId); } else { $result = Result::newSuccess(); } } catch (PropertyDataTypeLookupException $ex) { $result = Result::newError(array(Error::newError("Property {$propertyId} not found!", null, 'no-such-property', array($propertyId)))); } return $result; }
/** * @param Snak $snak * * @return string|null */ private function getString(Snak $snak) { if ($snak instanceof PropertyValueSnak) { $value = $snak->getDataValue(); if ($value instanceof StringValue) { return $value->getValue(); } } return null; }