Example #1
0
 /**
  * @param Property $property
  * @param $value
  * @return mixed
  * @throws RequirementValidationException
  */
 public function validate(Property $property, $value)
 {
     if ($value === null) {
         return;
     }
     if (PropertyType::isNumeric($property->getType())) {
         if ($value > $this->length) {
             throw RequirementValidationException::make($property, $this, $value);
         }
     } else {
         if (mb_strlen($value) > $this->length) {
             throw RequirementValidationException::make($property, $this, $value);
         }
     }
 }
Example #2
0
 /**
  * @param DescriptionBuilder $builder
  * @return array
  */
 public function toSwagger(DescriptionBuilder $builder)
 {
     $response = [];
     // Is this a native type?
     if (PropertyType::isNative($this->getType())) {
         /*
         $response = [
             'type' => $this->getType()
         ];
         */
     } else {
         $schema = $builder->getRelationshipSchema(ResourceDefinitionLibrary::make($this->getType()), $this->getContext(), $this->getCardinality());
         $response = ['schema' => $schema];
     }
     if (isset($this->description)) {
         $response['description'] = $this->description;
     }
     if ($this->headers) {
         $response['headers'] = $this->headers->toSwagger($builder);
     }
     return $response;
 }