/** * {@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)); } }
/** * {@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)); } }
/** * {@inheritdoc} */ protected function encode(array $data) { if ($this->prettyPrint) { return Json::prettyPrint($data); } return Json::encode($data); }
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; } }
/** * 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; }
/** * Create a JSON response. * @param mixed Data. * @return TextResponse Response. */ public function respond($response) { return new TextResponse(Http::OK, 'json', Json::encode($response)); }