Example #1
0
 private function thunkMongoId($id)
 {
     if ($id instanceof MongoId) {
         return $id;
     }
     if ($id[0] == '~') {
         return Genghis_Json::decode(base64_decode(substr($id, 1)));
     }
     return preg_match('/^[a-f0-9]{24}$/i', $id) ? new MongoId($id) : $id;
 }
Example #2
0
 public function renderContent()
 {
     print Genghis_Json::encode($this->data);
 }
Example #3
0
 protected function getRequestData($gfj = true)
 {
     $data = file_get_contents('php://input');
     if ($gfj) {
         try {
             $json = Genghis_Json::decode($data);
         } catch (Genghis_JsonException $e) {
             throw new Genghis_HttpException(400, 'Malformed document');
         }
     } else {
         $json = json_decode($data, true);
     }
     if (empty($json)) {
         throw new Genghis_HttpException(400, 'Malformed document');
     }
     return $json;
 }
Example #4
0
 protected function decodeJson($data, $gfj = true)
 {
     if ($gfj) {
         try {
             return Genghis_Json::decode($data);
         } catch (Genghis_JsonException $e) {
             throw new Genghis_HttpException(400, 'Malformed document');
         }
     } else {
         $json = json_decode($data, true);
         if ($json === false && trim($data) != '') {
             throw new Genghis_HttpException(400, 'Malformed document');
         }
         return $json;
     }
 }