Jacwright\RestServer\RestServer::getFormat PHP Method

getFormat() public method

public getFormat ( )
    public function getFormat()
    {
        $format = RestFormat::PLAIN;
        $accept_mod = null;
        if (isset($_SERVER["HTTP_ACCEPT"])) {
            $accept_mod = preg_replace('/\\s+/i', '', $_SERVER['HTTP_ACCEPT']);
            // ensures that exploding the HTTP_ACCEPT string does not get confused by whitespaces
        }
        $accept = explode(',', $accept_mod);
        $override = '';
        if (isset($_REQUEST['format']) || isset($_SERVER['HTTP_FORMAT'])) {
            // give GET/POST precedence over HTTP request headers
            $override = isset($_SERVER['HTTP_FORMAT']) ? $_SERVER['HTTP_FORMAT'] : '';
            $override = isset($_REQUEST['format']) ? $_REQUEST['format'] : $override;
            $override = trim($override);
        }
        // Check for trailing dot-format syntax like /controller/action.format -> action.json
        if (preg_match('/\\.(\\w+)$/i', strtok($_SERVER["REQUEST_URI"], '?'), $matches)) {
            $override = $matches[1];
        }
        // Give GET parameters precedence before all other options to alter the format
        $override = isset($_GET['format']) ? $_GET['format'] : $override;
        if (isset(RestFormat::$formats[$override])) {
            $format = RestFormat::$formats[$override];
        } elseif (in_array(RestFormat::JSON, $accept)) {
            $format = RestFormat::JSON;
        }
        return $format;
    }