public function determinePeferredFormat($acceptHeader, $allowedFormats = ['json', 'xml', 'html'], $default = 'json')
    {
        if (empty($acceptHeader)) {
            return $default;
        }

        $negotiator = new Negotiator();
        try {
            $elements = $negotiator->getOrderedElements($acceptHeader);
        } catch (InvalidMediaType $e) {
            return $default;
        }

        foreach ($elements as $element) {
            $subpart = $element->getSubPart();
            foreach ($allowedFormats as $format) {
                if (stripos($subpart, $format) !== false) {
                    return $format;
                }
            }
        }

        return $default;
    }