Example #1
0
 function serve()
 {
     $this->debug_messages = array();
     global $HTTP_RAW_POST_DATA;
     $incoming = new JSON_RPC_Server_Request($HTTP_RAW_POST_DATA);
     if (!$incoming->parse_request()) {
         if ($this->debug) {
             $this->debug_messages['HTTP_RAW_POST_DATA'] = $HTTP_RAW_POST_DATA;
         }
         $response = $this->set_server_error('parse_error');
         echo $response->create_server_response();
         return;
     }
     if ($this->debug) {
         $this->debug_messages['incoming'] = $incoming->data_object;
     }
     if (is_array($incoming->data_object)) {
         // batch (multi)
         if ($this->debug) {
             $this->debug_messages['is_batch'] = true;
         }
         $call_count = count($incoming->data_object);
         if ($call_count > $this->max_batch_call) {
             // not allowed too many procedure call at once
             $response = $this->set_server_error('max_procedure');
             echo $response->create_server_response();
             return;
         }
         $batch_result = array();
         foreach ($incoming->data_object as $key => $cur_data_object) {
             $response = $this->_execute($cur_data_object);
             if (isset($cur_data_object->id) && $cur_data_object->id != '') {
                 // not notification
                 $batch_result[] = $response->create_server_response(false);
                 if ($this->debug) {
                     $this->debug_messages['batch_result[' . $key . ']'] = $batch_result[count($batch_result) - 1];
                 }
             } else {
                 if ($this->debug) {
                     $this->debug_messages['batch_result[' . $key . ']'] = 'notification';
                 }
             }
         }
         if (count($batch_result) > 0) {
             $batch_result = '[' . implode($batch_result, ',') . ']';
             $response->display_header($batch_result);
             echo $batch_result;
         }
     } else {
         // single
         if ($this->debug) {
             $this->debug_messages['is_batch'] = false;
         }
         $response = $this->_execute($incoming->data_object);
         if (isset($incoming->data_object->id) && $incoming->data_object->id != '') {
             // not notification
             if ($this->debug) {
                 $this->debug_messages['result'] = $response->data_object;
             }
             echo $response->create_server_response();
         } else {
             if ($this->debug) {
                 $this->debug_messages['result'] = 'notification';
             }
         }
     }
 }
Example #2
0
 function serve()
 {
     global $HTTP_RAW_POST_DATA;
     $incoming = new JSON_RPC_Server_Request($HTTP_RAW_POST_DATA);
     if (!$incoming->parse_response()) {
         $response = $this->send_error('parse_error');
         echo $response->create_server_response();
         return;
     }
     $response = $this->_execute($incoming->data_object);
     echo $response->create_server_response();
 }