public static function reset() { request::$accept_charsets = NULL; request::$accept_encodings = NULL; request::$accept_languages = NULL; request::$accept_types = NULL; request::$user_agent = NULL; }
/** * Parses client's HTTP Accept request header, and builds array structure representing it. * * @return void */ protected static function parse_accept_header() { // Run this function just once if (request::$accept_types !== NULL) { return; } // Initialize accept_types array request::$accept_types = array(); // No HTTP Accept header found if (empty($_SERVER['HTTP_ACCEPT'])) { // Accept everything request::$accept_types['*']['*'] = 1; return; } // Remove linebreaks and parse the HTTP Accept header foreach (explode(',', str_replace(array("\r", "\n"), '', $_SERVER['HTTP_ACCEPT'])) as $accept_entry) { // Explode each entry in content type and possible quality factor $accept_entry = explode(';', trim($accept_entry), 2); // Explode each content type (e.g. "text/html") $type = explode('/', $accept_entry[0], 2); // Skip invalid content types if (!isset($type[1])) { continue; } // Assume a default quality factor of 1 if no custom q value found $q = (isset($accept_entry[1]) and preg_match('~\\bq\\s*+=\\s*+([.0-9]+)~', $accept_entry[1], $match)) ? (double) $match[1] : 1; // Populate accept_types array if (!isset(request::$accept_types[$type[0]][$type[1]]) or $q > request::$accept_types[$type[0]][$type[1]]) { request::$accept_types[$type[0]][$type[1]] = $q; } } }
/** * Parses a client's HTTP Accept header */ protected static function parse_accept_content_header() { // Run this function just once if (request::$accept_types !== NULL) { return; } // No HTTP Accept header found if (empty($_SERVER['HTTP_ACCEPT'])) { // Accept everything request::$accept_types['*']['*'] = 1; } else { request::$accept_types = array(); foreach (request::parse_accept_header($_SERVER['HTTP_ACCEPT']) as $type => $q) { // Explode each content type (e.g. "text/html") $type = explode('/', $type, 2); // Skip invalid content types if (!isset($type[1])) { continue; } request::$accept_types[$type[0]][$type[1]] = $q; } } }