}
// Generates values needed for error messages
+ /**
+ * @param string $message
+ *
+ * @return array
+ */
static function error($message = 'Unknown Error') {
$values = array(
'error_message' => $message,
}
// Generates values needed for non-error responses.
+ /**
+ * @param $params
+ *
+ * @return array
+ */
static function simple($params) {
$values = array('is_error' => 0);
$values += $params;
return $values;
}
+ /**
+ * @return string
+ */
function run() {
$result = self::handle();
return self::output($result);
}
+ /**
+ * @return string
+ */
function bootAndRun() {
$response = $this->loadCMSBootstrap();
if (is_array($response)) {
return $this->run();
}
+ /**
+ * @param $result
+ *
+ * @return string
+ */
static function output(&$result) {
$requestParams = CRM_Utils_Request::exportValues();
return $xml;
}
+ /**
+ * @param $json
+ *
+ * @return string
+ */
static function jsonFormated($json) {
$tabcount = 0;
$result = '';
return $result;
}
+ /**
+ * @return array|int
+ */
static function handle() {
$requestParams = CRM_Utils_Request::exportValues();
if (!empty($r)) {
$q = $r;
}
- if (!empty($q)) {
+ $entity = CRM_Utils_array::value('entity', $requestParams);
+ if ( empty($entity) && !empty($q)) {
$args = explode('/', $q);
// If the function isn't in the civicrm namespace, reject the request.
if ($args[0] != 'civicrm') {
return self::process($args, self::buildParamList());
}
+ /**
+ * @param $args
+ * @param $params
+ *
+ * @return array|int
+ */
static function process(&$args, $params) {
$params['check_permissions'] = TRUE;
$fnName = $apiFile = NULL;
return $result;
}
+ /**
+ * @return array|mixed|null
+ */
static function &buildParamList() {
$requestParams = CRM_Utils_Request::exportValues();
$params = array();
if (array_key_exists('json', $requestParams) && $requestParams['json'][0] == "{") {
$params = json_decode($requestParams['json'], TRUE);
if($params === NULL) {
- echo json_encode(array('is_error' => 1, 'error_message', 'Unable to decode supplied JSON.'));
- CRM_Utils_System::civiExit();
+ CRM_Utils_JSON::output(array('is_error' => 1, 'error_message', 'Unable to decode supplied JSON.'));
}
}
foreach ($requestParams as $n => $v) {
return $params;
}
+ /**
+ * @param $pearError
+ */
static function fatal($pearError) {
header('Content-Type: text/xml');
$error = array();
'reason' => 'CSRF suspected',
)
);
- echo json_encode($error);
- CRM_Utils_System::civiExit();
+ CRM_Utils_JSON::output($error);
}
if (empty($requestParams['entity'])) {
- echo json_encode(civicrm_api3_create_error('missing entity param'));
- CRM_Utils_System::civiExit();
+ CRM_Utils_JSON::output(civicrm_api3_create_error('missing entity param'));
}
if (empty($requestParams['entity'])) {
- echo json_encode(civicrm_api3_create_error('missing entity entity'));
- CRM_Utils_System::civiExit();
+ CRM_Utils_JSON::output(civicrm_api3_create_error('missing entity entity'));
}
if (!empty($requestParams['json'])) {
$params = json_decode($requestParams['json'], TRUE);
$entity = CRM_Utils_String::munge(CRM_Utils_Array::value('entity', $requestParams));
$action = CRM_Utils_String::munge(CRM_Utils_Array::value('action', $requestParams));
if (!is_array($params)) {
- echo json_encode(array('is_error' => 1, 'error_message', 'invalid json format: ?{"param_with_double_quote":"value"}'));
- CRM_Utils_System::civiExit();
+ CRM_Utils_JSON::output(array('is_error' => 1, 'error_message', 'invalid json format: ?{"param_with_double_quote":"value"}'));
}
$params['check_permissions'] = TRUE;
'reason' => 'CSRF suspected',
)
);
- echo json_encode($error);
- CRM_Utils_System::civiExit();
+ CRM_Utils_JSON::output($error);
}
$q = CRM_Utils_Array::value('fnName', $requestParams);