コード例 #1
0
 /**
  * @param ResourceInterface $resource
  * @param object|null $record
  * @return bool
  */
 protected function validateRelationships(ResourceInterface $resource, $record = null)
 {
     $raw = $resource->get(ResourceInterface::RELATIONSHIPS);
     /** Relationships member must be an object. */
     if ($resource->has(ResourceInterface::RELATIONSHIPS) && !is_object($raw)) {
         $this->addError($this->errorFactory->memberObjectExpected(ResourceInterface::RELATIONSHIPS, P::relationships()));
         return false;
     }
     /** Ok if no relationships validator or one that returns true for `isValid()` */
     if (!$this->relationships || $this->relationships->isValid($resource, $record)) {
         return true;
     }
     /** Ensure there is at least one error message. */
     if (0 < count($this->relationships->getErrors())) {
         $this->addErrors($this->relationships->getErrors());
     } else {
         $this->addError($this->errorFactory->resourceInvalidRelationships());
     }
     return false;
 }
コード例 #2
0
 /**
  * @param RelationshipsInterface $relationships
  * @return bool
  */
 protected function validateRequired(RelationshipsInterface $relationships)
 {
     $valid = true;
     foreach ($this->required as $key) {
         if (!$relationships->has($key)) {
             $this->addError($this->errorFactory->memberRequired($key, P::relationships()));
             $valid = false;
         }
     }
     return $valid;
 }
コード例 #3
0
 /**
  * @inheritdoc
  */
 public function resourceInvalidRelationships()
 {
     return $this->repository->errorWithPointer(self::RESOURCE_INVALID_RELATIONSHIPS, P::relationships());
 }