Example #1
0
 /**
  * Casts a value to the column's type.
  *
  * @param mixed $value The value to cast
  * @param Connection $connection The Connection this column belongs to
  * @return mixed type-casted value
  */
 public function cast($value, $connection)
 {
     if ($value === null) {
         return null;
     }
     switch ($this->type) {
         case self::STRING:
             return (string) $value;
         case self::INTEGER:
             return (int) $value;
         case self::DECIMAL:
             return (double) $value;
         case self::DATETIME:
         case self::DATE:
             if (!$value) {
                 return null;
             }
             if ($value instanceof DateTime) {
                 return $value;
             }
             return $connection->string_to_datetime($value);
     }
     return $value;
 }
Example #2
0
 public function string_to_datetime($string)
 {
     return parent::string_to_datetime(str_replace('.000000', '', $string));
 }