Exemplo n.º 1
0
 /**
  * Set value of specific field.
  *
  * @param  string                    $name
  * @param  mixed                     $value
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function &setFieldValue($name, $value)
 {
     if ($value === null) {
         parent::setFieldValue($name, null);
     } else {
         switch ($name) {
             case 'id':
                 return parent::setFieldValue($name, (int) $value);
             case 'type':
             case 'first_name':
             case 'last_name':
             case 'email':
             case 'homepage_url':
             case 'password':
                 return parent::setFieldValue($name, (string) $value);
             default:
                 throw new \InvalidArgumentException("Field {$name} does not exist in this table");
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function &setFieldValue($name, $value)
 {
     if ($value === null) {
         parent::setFieldValue($name, null);
     } else {
         switch ($name) {
             case 'id':
             case 'account_id':
                 return parent::setFieldValue($name, (int) $value);
             case 'day':
                 return parent::setFieldValue($name, $this->getDateTimeValueInstanceFrom($value));
             case 'stats':
                 return parent::setFieldValue($name, $this->isLoading() ? $value : json_encode($value));
             default:
                 if ($this->isLoading()) {
                     return parent::setFieldValue($name, $value);
                 } else {
                     if ($this->isGeneratedField($name)) {
                         throw new \LogicException("Generated field {$name} cannot be set by directly assigning a value");
                     } else {
                         throw new \InvalidArgumentException("Field {$name} does not exist in this table");
                     }
                 }
         }
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Set value of specific field.
  *
  * @param  string                   $name
  * @param  mixed                    $value
  * @return mixed
  * @throws InvalidArgumentException
  */
 public function &setFieldValue($name, $value)
 {
     if ($value === null) {
         parent::setFieldValue($name, null);
     } else {
         switch ($name) {
             case 'id':
                 parent::setFieldValue($name, (int) $value);
                 break;
             case 'name':
                 parent::setFieldValue($name, (string) $value);
                 break;
             case 'birthday':
                 parent::setFieldValue($name, $this->getDateValueInstanceFrom($value));
                 break;
             case 'created_at':
             case 'updated_at':
                 return parent::setFieldValue($name, $this->getDateTimeValueInstanceFrom($value));
             default:
                 throw new InvalidArgumentException("'{$name}' is not a known field");
         }
     }
     return $this;
 }