AdamStipak\RestRoute::detectFormat PHP Method

detectFormat() private method

private detectFormat ( Nette\Http\IRequest $request ) : string
$request Nette\Http\IRequest
return string
    private function detectFormat(IRequest $request)
    {
        $header = $request->getHeader('Accept');
        // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
        foreach ($this->formats as $format => $fullFormatName) {
            $fullFormatName = Strings::replace($fullFormatName, '/\\//', '\\/');
            if (Strings::match($header, "/{$fullFormatName}/")) {
                return $format;
            }
        }
        // Try retrieve fallback from URL.
        $path = $request->getUrl()->getPath();
        $formats = array_keys($this->formats);
        $formats = implode('|', $formats);
        if (Strings::match($path, "/\\.({$formats})\$/")) {
            list($path, $format) = explode('.', $path);
            return $format;
        }
        return $this->defaultFormat;
    }