/** * @inheritdoc */ public function relationshipNotAcceptable(ResourceIdentifierInterface $identifier, $relationshipKey = null, $error = null) { $base = $this->repository->errorWithPointer(self::RELATIONSHIP_NOT_ACCEPTABLE, $relationshipKey ? P::relationship($relationshipKey) : P::data(), ['type' => $identifier->getType(), 'id' => $identifier->getId()]); $errors = new MutableErrorCollection(); /** @var MutableErrorInterface $err */ foreach (MutableErrorCollection::cast($error ?: $base) as $err) { $add = clone $base; $errors->add($add->merge($err)); } return $errors; }
/** * @param $key * @param RelationshipsInterface $relationships * @param ResourceInterface $resource * @param object|null $record * @return bool */ protected function validateRelationship($key, RelationshipsInterface $relationships, ResourceInterface $resource, $record = null) { if (!is_object($relationships->get($key))) { $this->addError($this->errorFactory->memberObjectExpected($key, P::relationship($key))); return false; } $validator = $this->get($key); $relationship = $relationships->getRelationship($key); if (!$validator->isValid($relationship, $record, $key, $resource)) { $this->addErrors($validator->getErrors()); return false; } return true; }
/** * Validate that a data member exists and it is either a has-one or a has-many relationship. * * @param RelationshipInterface $relationship * @param string|null $key * @return bool */ protected function validateRelationship(RelationshipInterface $relationship, $key = null) { if (!$relationship->has(RelationshipInterface::DATA)) { $this->addError($this->errorFactory->memberRequired(RelationshipInterface::DATA, $key ? P::relationship($key) : P::data())); return false; } if (!$relationship->isHasOne() && !$relationship->isHasMany()) { $this->addError($this->errorFactory->memberRelationshipExpected(RelationshipInterface::DATA, $key ? P::relationship($key) : P::data())); return false; } if (!$this->validateEmpty($relationship, $key)) { return false; } return true; }