/** * @inheritdoc */ public function resourceInvalidAttributesMessages(MessageBag $messageBag, $attributePrefix = null, $statusCode = self::STATUS_INVALID_ATTRIBUTES) { $prototype = $this->repository->error(self::RESOURCE_INVALID_ATTRIBUTES_MESSAGES); $prototype = Error::cast($prototype)->setStatus($statusCode); $prefix = $attributePrefix ? P::attribute($attributePrefix) : P::attributes(); $errors = new ErrorBag($messageBag, $prototype, $prefix); return $errors->toArray(); }
/** * @param ResourceInterface $resource * @param object|null $record * @return bool */ protected function validateAttributes(ResourceInterface $resource, $record = null) { $raw = $resource->get(ResourceInterface::ATTRIBUTES); /** Attributes member must be an object. */ if ($resource->has(ResourceInterface::ATTRIBUTES) && !is_object($raw)) { $this->addError($this->errorFactory->memberObjectExpected(ResourceInterface::ATTRIBUTES, P::attributes())); return false; } /** Ok if no attributes validator or one that returns true for `isValid()` */ if (!$this->attributes || $this->attributes->isValid($resource, $record)) { return true; } /** Ensure that at least one error message is added. */ if (0 < count($this->attributes->getErrors())) { $this->addErrors($this->attributes->getErrors()); } else { $this->addError($this->errorFactory->resourceInvalidAttributes()); } return false; }
/** * @inheritdoc */ public function resourceInvalidAttributes() { return $this->repository->errorWithPointer(self::RESOURCE_INVALID_ATTRIBUTES, P::attributes()); }