상속: extends Exception
예제 #1
0
 /**
  * @param string $fieldName
  * @param FieldDefinition $type
  * @throws InvalidArgumentException
  */
 private function addFieldDefinition(string $fieldName, FieldDefinition $type)
 {
     if (array_key_exists(mb_strtolower($fieldName), $this->definitions)) {
         throw InvalidArgumentException::fieldNameAlreadyExists($fieldName, $this->name);
     }
     $this->definitions[mb_strtolower($fieldName)] = $type;
 }
예제 #2
0
 /**
  * @param $serializedValue
  *
  * @return float
  * @throws InvalidArgumentException
  */
 public function deserialize($serializedValue)
 {
     if (null === $serializedValue && $this->isNullable()) {
         return $this->default === null ? null : $this->default;
     }
     if (!is_string($serializedValue)) {
         throw InvalidArgumentException::expected('string', $serializedValue);
     }
     return (double) $serializedValue;
 }
예제 #3
0
 /**
  * @param string $serializedValue
  *
  * @return null|Association
  * @throws InvalidArgumentException
  */
 public function deserialize($serializedValue)
 {
     if (null === $serializedValue && $this->isNullable()) {
         return null;
     }
     if (!is_string($serializedValue)) {
         throw InvalidArgumentException::expected('string', $serializedValue);
     }
     return new Association($this->schema, $this->typeSchema, ['id' => $serializedValue]);
 }
예제 #4
0
 /**
  * @param TypeSchema $definition
  * @return bool
  * @throws InvalidArgumentException
  */
 public function isValid(TypeSchema $definition) : bool
 {
     if (mb_strtolower($definition->name()) !== mb_strtolower($this->typeSchemaName())) {
         throw InvalidArgumentException::unexpectedModel($definition->name(), $this->typeSchemaName());
     }
     foreach ($this->fields as $fieldName => $value) {
         $field = $definition->getFieldDefinition($fieldName);
         if (!$field->isValid($value)) {
             return false;
         }
     }
     return true;
 }