/** * Validates a set of Arpa requests. * * ### Request: ### * * ~~~ * { * "arpa": [ { * "identifier": <string>, * "reverse_dns": <string> * },0..n ] * } * ~~~ * * ### Response: ### * * ~~~ * true * ~~~ * * ### Errors: ### * * * 508 - Invalid request, missing required parameters or input validation failed. * * @access public * @param mixed $request Request parameters * @return Response True if record is valid, error message with parse errors otherwise. */ public function validate($request) { $response = new FormattedResponse($request); $data = $request->parseData(); if (empty($data) || !isset($data->arpa) || !is_array($data->arpa)) { $response->code = Response::BADREQUEST; $response->error = "Request body was malformed. Ensure that all mandatory properties have been set."; $response->error_detail = "MISSING_REQUIRED_PARAMETERS"; return $response; } Validator::resetCounter(); $details = array(); $output = array(); $i = 0; foreach ($data->arpa as $d) { $i++; if (!isset($d->identifier) || !isset($d->reverse_dns)) { $output[] = sprintf("Missing required parameters in Arpa %d", $i); continue; } $validator = new ArpaValidator($d); if (!$validator->validates()) { $output[] = sprintf("Validation errors in Arpa %d:", $i); $output[] = $validator->getFormattedErrors(false); $details[] = $validator->getErrorDetails(); } continue; } if (empty($output)) { $response->code = Response::OK; $response->body = true; $response->log_message = "Arpa records were successfully validated."; } else { $response->code = Response::BADREQUEST; $response->error = implode("\n", $output); $response->error_detail = $details; } return $response; }