/** * Validates this ChangeOp * * @see ChangeOp::validate() * * @since 0.5 * * @param Entity $entity * * @return Result */ public function validate(Entity $entity) { $languageValidator = $this->termValidatorFactory->getLanguageValidator(); $termValidator = $this->termValidatorFactory->getLabelValidator($entity->getType()); $fingerprintValidator = $this->termValidatorFactory->getFingerprintValidator($entity->getType()); // check that the language is valid $result = $languageValidator->validate($this->languageCode); if ($result->isValid() && $this->label !== null) { // Check that the new label is valid $result = $termValidator->validate($this->label); } if (!$result->isValid()) { return $result; } // Check if the new fingerprint of the entity is valid (e.g. if the label is unique) $fingerprint = unserialize(serialize($entity->getFingerprint())); $this->updateFingerprint($fingerprint); $result = $fingerprintValidator->validateFingerprint($fingerprint, $entity->getId(), array($this->languageCode)); return $result; }
/** * Validates this ChangeOp * * @see ChangeOp::validate() * * @since 0.5 * * @param EntityDocument $entity * * @return Result */ public function validate(EntityDocument $entity) { if (!$entity instanceof FingerprintHolder) { throw new InvalidArgumentException('$entity must be a FingerprintHolder'); } $languageValidator = $this->termValidatorFactory->getLanguageValidator(); $termValidator = $this->termValidatorFactory->getLabelValidator($entity->getType()); $fingerprintValidator = $this->termValidatorFactory->getFingerprintValidator($entity->getType()); // check that the language is valid $result = $languageValidator->validate($this->languageCode); if ($result->isValid() && $this->label !== null) { // Check that the new label is valid $result = $termValidator->validate($this->label); } if (!$result->isValid()) { return $result; } // Check if the new fingerprint of the entity is valid (e.g. if the label is unique) $fingerprint = unserialize(serialize($entity->getFingerprint())); $this->updateFingerprint($fingerprint); $result = $fingerprintValidator->validateFingerprint($fingerprint, $entity->getId(), array($this->languageCode)); return $result; }
/** * Validates this ChangeOp * * @see ChangeOp::validate() * * @since 0.5 * * @param EntityDocument $entity * * @throws ChangeOpException * @return Result */ public function validate(EntityDocument $entity) { $languageValidator = $this->termValidatorFactory->getLanguageValidator(); $termValidator = $this->termValidatorFactory->getLabelValidator($entity->getType()); // check that the language is valid $result = $languageValidator->validate($this->languageCode); if (!$result->isValid()) { return $result; } // It should be possible to remove invalid aliases, but not to add/set new invalid ones if ($this->action === 'set' || $this->action === '' || $this->action === 'add') { // Check that the new aliases are valid foreach ($this->aliases as $alias) { $result = $termValidator->validate($alias); if (!$result->isValid()) { return $result; } } } elseif ($this->action !== 'remove') { throw new ChangeOpException('Bad action: ' . $this->action); } //XXX: Do we want to check the updated fingerprint, as we do for labels and descriptions? return $result; }