Esempio n. 1
0
 /**
  * @param EntityRedirect $that
  *
  * @return bool
  */
 public function equals($that)
 {
     if ($that === $this) {
         return true;
     }
     return is_object($that) && get_class($that) === get_called_class() && $this->entityId->equals($that->entityId) && $this->targetId->equals($that->targetId);
 }
Esempio n. 2
0
 /**
  * @dataProvider instanceProvider
  */
 public function testEqualsSimple(EntityId $id)
 {
     $this->assertTrue($id->equals($id));
     $this->assertTrue($id->equals(unserialize(serialize($id))));
     $this->assertFalse($id->equals($id->getSerialization()));
     $this->assertFalse($id->equals($id->getEntityType()));
 }
 /**
  * @dataProvider getEntityProvider
  *
  * @param EntityRevisionLookup $revisionLookup
  * @param EntityId $id
  * @param EntityId|null $expected
  */
 public function testGetEntity(EntityRevisionLookup $revisionLookup, EntityId $id, EntityId $expected = null)
 {
     $entityLookup = new RevisionBasedEntityLookup($revisionLookup);
     $entity = $entityLookup->getEntity($id);
     if ($expected === null) {
         $this->assertNull($entity);
     } else {
         $this->assertTrue($expected->equals($entity->getId()));
     }
 }
 /**
  * @dataProvider getEntityProvider
  */
 public function testGetEntity(EntityId $id, EntityId $expected)
 {
     $lookup = new RedirectResolvingEntityLookup($this->getLookupDouble());
     $entity = $lookup->getEntity($id);
     if ($expected === null) {
         $this->assertNull($entity);
     } else {
         $this->assertTrue($expected->equals($entity->getId()));
     }
 }
 private function propertyMatchesFilter(EntityId $propertyId)
 {
     if (isset($this->requestParams['property'])) {
         try {
             $parsedProperty = $this->idParser->parse($this->requestParams['property']);
         } catch (EntityIdParsingException $e) {
             $this->errorReporter->dieException($e, 'param-invalid');
         }
         /** @var EntityId $parsedProperty */
         return $propertyId->equals($parsedProperty);
     }
     return true;
 }
Esempio n. 6
0
 /**
  * Strip any conflicts with the given $fromId from the array of Error objects
  *
  * @param Error[] $errors
  * @param EntityId $fromId
  *
  * @return Error[]
  */
 private function removeConflictsWithEntity($errors, EntityId $fromId)
 {
     $filtered = array();
     foreach ($errors as $error) {
         if ($error instanceof UniquenessViolation && $fromId->equals($error->getConflictingEntity())) {
             continue;
         }
         $filtered[] = $error;
     }
     return $filtered;
 }
 /**
  * @param array $data
  * @param EntityId|null $entityId
  */
 private function checkEntityId(array $data, EntityId $entityId = null)
 {
     if (isset($data['id'])) {
         if (!$entityId) {
             $this->errorReporter->dieError('Illegal field used in call: "id", must not be given when creating a new entity', 'param-illegal');
         }
         $dataId = $this->idParser->parse($data['id']);
         if (!$entityId->equals($dataId)) {
             $this->errorReporter->dieError('Invalid field used in call: "id", must match id parameter', 'param-invalid');
         }
     }
 }
 /**
  * @param TermIndexEntry[] $terms
  * @param EntityId $entityId
  *
  * @return TermIndexEntry[]
  */
 private function filterSelfConflicts(array $terms, EntityId $entityId)
 {
     return array_filter($terms, function (TermIndexEntry $term) use($entityId) {
         return !$entityId->equals($term->getEntityId());
     });
 }
 /**
  * Returns the aspects used by the given entity on the page
  * represented by this PageEntityUsages object. They aspects
  * will include any modifiers.
  *
  * @param EntityId $id
  *
  * @return string[] List of aspect keys, sorted.
  */
 public function getUsageAspectKeys(EntityId $id)
 {
     $aspects = array();
     foreach ($this->usages as $usage) {
         if ($id->equals($usage->getEntityId())) {
             $aspects[] = $usage->getAspectKey();
         }
     }
     sort($aspects);
     return $aspects;
 }
 /**
  * @param EntityId $entityId
  * @param string[]|null $termTypes
  * @param string[]|null $languageCodes
  *
  * @return TermIndexEntry[]
  */
 public function getTermsOfEntity(EntityId $entityId, array $termTypes = null, array $languageCodes = null)
 {
     $matchingTerms = array();
     if (is_array($termTypes)) {
         $termTypes = array_flip($termTypes);
     }
     if (is_array($languageCodes)) {
         $languageCodes = array_flip($languageCodes);
     }
     foreach ($this->terms as $term) {
         if (is_array($termTypes) && !isset($termTypes[$term->getType()]) || is_array($languageCodes) && !isset($languageCodes[$term->getLanguage()]) || !$entityId->equals($term->getEntityId())) {
             continue;
         }
         $matchingTerms[] = $term;
     }
     return $matchingTerms;
 }