Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function encode(DataType $type, $value)
 {
     $value = $type->convert($value);
     if (!isset($value)) {
         if ($type->isInteger() and $type->serial) {
             return 'DEFAULT';
         }
         return 'NULL';
     }
     switch ($type->type) {
         case DataType::INTEGER:
             return intval($value);
         case DataType::FLOAT:
             return floatval($value);
         case DataType::BOOLEAN:
             return $value ? 'TRUE' : 'FALSE';
         case DataType::DATE:
             return $this->db->quoteString(gmdate('Y-m-d', $value));
         case DataType::DATETIME:
             return $this->db->quoteString(gmdate('Y-m-d H:i:s', $value));
         case DataType::STRING:
         case DataType::TEXT:
         case DataType::BINARY:
         case DataType::ENUM:
             return $this->db->quoteString($value);
         case DataType::OBJECT:
             return $this->db->quoteString(Json::encode($value));
     }
 }