Ejemplo n.º 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 static::castIntegerSafely($value);
         case self::DECIMAL:
             return (double) $value;
         case self::DATETIME:
         case self::DATE:
             if (!$value) {
                 return null;
             }
             if ($value instanceof DateTime) {
                 return $value;
             }
             if ($value instanceof DateTime) {
                 return new DateTime($value->format('Y-m-d H:i:s T'));
             }
             return $connection->stringToDatetime($value);
     }
     return $value;
 }
 public function stringToDatetime($string)
 {
     return parent::stringToDatetime(str_replace('.000000', '', $string));
 }