ApiController::parseInput PHP Method

parseInput() protected method

protected parseInput ( )
    protected function parseInput()
    {
        $body = Yii::app()->request->rawBody;
        if (!$body) {
            $this->sendError('No input received');
        }
        if (isset($_SERVER['CONTENT_TYPE']) && preg_match('/json/', $_SERVER['CONTENT_TYPE'])) {
            $input = Yii::app()->fhirMarshal->parseJson($body);
            if (!$input) {
                $this->sendError('Failed to parse input as JSON');
            }
        } else {
            libxml_use_internal_errors(true);
            $input = Yii::app()->fhirMarshal->parseXml($body);
            if (!$input) {
                if ($errors = libxml_get_errors()) {
                    $issues = array();
                    foreach ($errors as $error) {
                        $issues[] = new services\FhirOutcomeIssue(array('severity' => self::$xml_error_map[$error->level], 'type' => FhirValueSet::ISSUETYPE_INVALID_STRUCTURE, 'details' => trim($error->message ?: 'XML parse error') . " (line {$error->line})"));
                    }
                    $this->sendResource(new services\FhirOutcome(array('issues' => $issues)), 400);
                } else {
                    $this->sendError('Invalid XML input');
                }
            }
        }
        return $input;
    }