示例#1
0
 /**
  * {@inheritdoc}
  */
 public function encode(DataType $type, $value)
 {
     $value = $type->convert($value);
     if (!isset($value)) {
         if ($type->isInteger() and $type->autoIncrement) {
             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));
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function encode(DataType $type, $value)
 {
     $value = $type->convert($value);
     if (!isset($value)) {
         return 'NULL';
     }
     switch ($type->type) {
         case DataType::INTEGER:
             return intval($value);
         case DataType::FLOAT:
             return floatval($value);
         case DataType::BOOLEAN:
             return $value ? 1 : 0;
         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));
     }
 }
示例#3
0
文件: JsonStore.php 项目: jivoo/jivoo
 /**
  * {@inheritdoc}
  */
 protected function encode(array $data)
 {
     if ($this->prettyPrint) {
         return Json::prettyPrint($data);
     }
     return Json::encode($data);
 }
示例#4
0
 protected function update()
 {
     $messages = $this->Message->where('id > %i', $this->lastMessage)->orderBy('id');
     foreach ($messages as $message) {
         $this->trigger(Json::encode(array('id' => $message->id, 'author' => $message->author, 'message' => $message->message)));
         $this->lastMessage = $message->id;
     }
 }
示例#5
0
文件: Console.php 项目: jivoo/jivoo
 /**
  * Output tool creation JavaScript.
  * @return string JavaScript.
  */
 public function outputTools()
 {
     $output = 'if (typeof JIVOO !== "object") {';
     $output .= 'console.error("Jivoo module not found!");';
     $output .= '} else if (typeof JIVOO.devbar !== "object") {';
     $output .= 'console.error("Jivoo Devbar module not found!");';
     $output .= '} else {';
     foreach ($this->tools as $id => $tool) {
         if ($tool['ajax']) {
             $output .= 'JIVOO.devbar.addAjaxTool(';
         } else {
             $output .= 'JIVOO.devbar.addLinkTool(';
         }
         $output .= Json::encode($id) . ', ';
         $output .= Json::encode($tool['name']) . ', ';
         $link = $this->m->Routing->getLink($tool['route']);
         $output .= Json::encode($link);
         if ($tool['ajax'] and $tool['ajaxOnly']) {
             $output .= ', true';
         }
         $output .= ');';
     }
     $output .= '}';
     return $output;
 }
示例#6
0
 /**
  * Create a JSON response.
  * @param mixed Data.
  * @return TextResponse Response.
  */
 public function respond($response)
 {
     return new TextResponse(Http::OK, 'json', Json::encode($response));
 }