Example #1
0
 /**
  * @param $data
  *
  * Return [isEmpty, data]
  *
  * @return array
  * @throws SkipField
  * @throws ValidationError
  */
 public function validateEmptyValues($data)
 {
     if ($this->readOnly) {
         return [true, $this->getDefault()];
     }
     if (EmptyType::isEmpty($data)) {
         if ($this->root instanceof Serializer and $this->root->partial()) {
             throw new SkipField();
         }
         if ($this->required) {
             $this->fail('required');
         }
         return [true, $this->getDefault()];
     }
     if ($data === null) {
         if (!$this->allowNull) {
             $this->fail('invalid');
         }
         return [true, null];
     }
     return [false, $data];
 }
Example #2
0
 /**
  * @return \Generator
  */
 public function getWritableFields()
 {
     /* @var $field Field */
     foreach ($this->fields as $field) {
         if (!$field->readOnly or !EmptyType::isEmpty($field->default())) {
             (yield $field);
         }
     }
 }