protected function convertMediaType($requestBody, $mediaType)
    {
        $mediaTypeParts = MediaTypes::parseMediaType($mediaType);
        if (!isset($mediaTypeParts['subtype']) || $mediaTypeParts['subtype'] === '') {
            return [];
        }
        $result = [];
        switch ($mediaTypeParts['subtype']) {
            case 'json':
            case 'x-json':
            case 'javascript':
            case 'x-javascript':
                $result = json_decode($requestBody, true);
                if ($result === null) {
                    return [];
                }
            break;
            case 'xml':
                $entityLoaderValue = libxml_disable_entity_loader(true);
                try {
                    $xmlElement = new \SimpleXMLElement(urldecode($requestBody), LIBXML_NOERROR);
                    libxml_disable_entity_loader($entityLoaderValue);
                } catch (\Exception $exception) {
                    libxml_disable_entity_loader($entityLoaderValue);
                    return [];
                }
                $result = Arrays::convertObjectToArray($xmlElement);
            break;
            case 'x-www-form-urlencoded':
            default:
                parse_str($requestBody, $result);
            break;
        }
        return $result;
    }
protected function convertMediaType($requestBody, $mediaType)
    {
        $mediaTypeParts = MediaTypes::parseMediaType($mediaType);
        if (!isset($mediaTypeParts['subtype']) || $mediaTypeParts['subtype'] === '') {
            return [];
        }
        $result = [];
        switch ($mediaTypeParts['subtype']) {
            case 'json':
            case 'x-json':
            case 'javascript':
            case 'x-javascript':
                $result = json_decode($requestBody, true);
                if ($result === null) {
                    return [];
                }
            break;
            case 'xml':
                $entityLoaderValue = libxml_disable_entity_loader(true);
                try {
                    $xmlElement = new \SimpleXMLElement(urldecode($requestBody), LIBXML_NOERROR);
                    libxml_disable_entity_loader($entityLoaderValue);
                } catch (\Exception $exception) {
                    libxml_disable_entity_loader($entityLoaderValue);
                    return [];
                }
                $result = Arrays::convertObjectToArray($xmlElement);
            break;
            case 'x-www-form-urlencoded':
            default:
                parse_str($requestBody, $result);
            break;
        }
        return $result;
    }
protected function convertMediaType ( $ requestBody , $ mediaType ) { $ mediaTypeParts = MediaTypes :: parseMediaType ( $ mediaType ) ; if ( ! isset ( $ mediaTypeParts [ 'subtype' ] ) || $ mediaTypeParts [ 'subtype' ] === '' ) { return [ ] ; } $ result = [ ] ; switch ( $ mediaTypeParts [ 'subtype' ] ) { case 'json' : case 'x-json' : case 'javascript' : case 'x-javascript' : $ result = json_decode ( $ requestBody , true ) ; if ( $ result === null ) { return [ ] ; } break ; case 'xml' : $ entityLoaderValue = libxml_disable_entity_loader ( true ) ; try { $ xmlElement = new \ SimpleXMLElement ( urldecode ( $ requestBody ) , LIBXML_NOERROR ) ; libxml_disable_entity_loader ( $ entityLoaderValue ) ; } catch ( \ Exception $ exception ) { libxml_disable_entity_loader ( $ entityLoaderValue ) ; return [ ] ; } $ result = Arrays :: convertObjectToArray ( $ xmlElement ) ; break ; case 'x-www-form-urlencoded' : default : parse_str ( $ requestBody , $ result ) ; break ; } return $ result ; }
Converts the given request body according to the specified media type
Override this method in your custom TypeConverter to support additional media types

@param string $requestBody the raw request body
@param string $mediaType the configured media type (for example "application/json")
@return array
@api
Converts the given request body according to the specified media type Override this method in your custom TypeConverter to support additional media types