/** * @see EntityLookup::hasEntity * * If the given entity ID points to a redirect, that redirect is resolved and the * existence of the target entity is checked. * * @param EntityId $entityId * * @return bool * @throws EntityLookupException */ public function hasEntity(EntityId $entityId) { try { return $this->lookup->hasEntity($entityId); } catch (UnresolvedEntityRedirectException $ex) { return $this->lookup->hasEntity($ex->getRedirectTargetId()); } }
/** * @param string $propertyLabelOrId * @param string $languageCode * * @throws PropertyLabelNotResolvedException * @return PropertyId */ public function resolvePropertyId($propertyLabelOrId, $languageCode) { try { $propertyId = new PropertyId($propertyLabelOrId); if (!$this->entityLookup->hasEntity($propertyId)) { throw new PropertyLabelNotResolvedException($propertyLabelOrId, $languageCode); } } catch (InvalidArgumentException $ex) { $propertyId = $this->findPropertyByLabel($propertyLabelOrId, $languageCode); } return $propertyId; }
/** * @see ValueValidator::validate() * * @param EntityIdValue|EntityId $value The ID to validate * * @return Result * @throws InvalidArgumentException */ public function validate($value) { if ($value instanceof EntityIdValue) { $value = $value->getEntityId(); } if (!$value instanceof EntityId) { throw new InvalidArgumentException("Expected an EntityId object"); } $actualType = $value->getEntityType(); $errors = array(); if ($this->entityType !== null && $actualType !== $this->entityType) { $errors[] = Error::newError("Wrong entity type: " . $actualType, null, 'bad-entity-type', array($actualType)); } if (!$this->entityLookup->hasEntity($value)) { $errors[] = Error::newError("Entity not found: " . $value, null, 'no-such-entity', array($value)); } return empty($errors) ? Result::newSuccess() : Result::newError($errors); }
/** * Parses a string to itemId * * @param string $itemString * @return ItemId|null */ private function getItemId($itemString) { try { $itemId = $this->idParser->parse($itemString); if ($itemId instanceof ItemId) { if (!$this->entityLookup->hasEntity($itemId)) { $this->errorMessageKey = "item-not-found"; return null; } return $itemId; } } catch (EntityIdParsingException $e) { $this->errorMessageKey = 'item-id-invalid'; } catch (InvalidArgumentException $e) { $this->errorMessageKey = 'item-id-invalid'; } return null; }
/** * @see EntityLookup::hasEntity * * @param EntityId $entityId * * @return bool * @throws EntityLookupException */ public function hasEntity(EntityId $entityId) { return $this->entityLookup->hasEntity($entityId); }