35 $month =
'(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)';
36 $weekday =
'(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)';
37 $wkday =
'(Mon|Tue|Wed|Thu|Fri|Sat|Sun)';
38 $time =
'([0-1]\d|2[0-3])(\:[0-5]\d){2}';
39 $date3 = $month .
' ([12]\d|3[01]| [1-9])';
40 $date2 =
'(0[1-9]|[12]\d|3[01])\-' . $month .
'\-\d{2}';
42 $date1 =
'(0[1-9]|[12]\d|3[01]) ' . $month .
' [1-9]\d{3}';
46 $asctime_date = $wkday .
' ' . $date3 .
' ' .
$time .
' [1-9]\d{3}';
48 $rfc850_date = $weekday .
', ' . $date2 .
' ' .
$time .
' GMT';
50 $rfc1123_date = $wkday .
', ' . $date1 .
' ' .
$time .
' GMT';
52 $HTTP_date =
"($rfc1123_date|$rfc850_date|$asctime_date)";
55 $dateString = trim($dateString,
' ');
56 if (!preg_match(
'/^' . $HTTP_date .
'$/', $dateString))
60 if (strpos($dateString,
' GMT') ===
false)
61 $dateString .=
' GMT';
81 $dateTime = clone $dateTime;
83 return $dateTime->format(
'D, d M Y H:i:s \G\M\T');
109 if (!$acceptHeaderValue) {
111 return reset($availableOptions);
114 $proposals = array_map(
115 'Sabre\HTTP\parseMimeType',
116 explode(
',', $acceptHeaderValue)
120 $availableOptions = array_values($availableOptions);
123 'Sabre\HTTP\parseMimeType',
128 $lastSpecificity = 0;
129 $lastOptionIndex = 0;
132 foreach ($proposals as $proposal) {
135 if (is_null($proposal))
continue;
138 if ($proposal[
'quality'] < $lastQuality) {
142 foreach (
$options as $optionIndex => $option) {
144 if ($proposal[
'type'] !==
'*' && $proposal[
'type'] !== $option[
'type']) {
148 if ($proposal[
'subType'] !==
'*' && $proposal[
'subType'] !== $option[
'subType']) {
155 foreach ($option[
'parameters'] as $paramName => $paramValue) {
156 if (!array_key_exists($paramName, $proposal[
'parameters'])) {
159 if ($paramValue !== $proposal[
'parameters'][$paramName]) {
168 ($proposal[
'type'] !==
'*' ? 20 : 0) +
169 ($proposal[
'subType'] !==
'*' ? 10 : 0) +
170 count($option[
'parameters']);
175 ($proposal[
'quality'] > $lastQuality) ||
176 ($proposal[
'quality'] === $lastQuality && $specificity > $lastSpecificity) ||
177 ($proposal[
'quality'] === $lastQuality && $specificity === $lastSpecificity && $optionIndex < $lastOptionIndex)
180 $lastQuality = $proposal[
'quality'];
181 $lastSpecificity = $specificity;
182 $lastOptionIndex = $optionIndex;
183 $lastChoice = $availableOptions[$optionIndex];
224 $token =
'[!#$%&\'*+\-.^_`~A-Za-z0-9]+';
227 $word =
'(?: [a-zA-Z0-9]+ | "[a-zA-Z0-9]*" )';
237 (?: \
s* ; (?: .*))? # Prefer parameters (ignored)
245 if (!preg_match($regex, $value, $matches)) {
251 switch ($matches[
'name']) {
252 case 'return-asynch' :
253 $output[
'respond-async'] =
true;
255 case 'return-representation' :
256 $output[
'return'] =
'representation';
258 case 'return-minimal' :
262 $output[
'handling'] =
'strict';
265 $output[
'handling'] =
'lenient';
268 if (isset($matches[
'value'])) {
269 $value = trim($matches[
'value'],
'"');
273 $output[strtolower($matches[
'name'])] = empty($value) ? true : $value;
308 foreach (explode(
',', $l1) as $l2) {
333 $parts = explode(
';', $str);
336 $mimeType = array_shift($parts);
338 $mimeType = explode(
'/', trim($mimeType));
339 if (count($mimeType) !== 2) {
343 list(
$type, $subType) = $mimeType;
345 foreach ($parts as $part) {
348 if (strpos($part,
'=')) {
349 list($partName, $partValue) =
350 explode(
'=', $part, 2);
360 if ($partName !==
'q') {
361 $parameters[$partName] = $part;
363 $quality = (float)$partValue;
371 'subType' => $subType,
372 'quality' => $quality,
373 'parameters' => $parameters,
388 return preg_replace_callback(
'/([^A-Za-z0-9_\-\.~\(\)\/:@])/',
function($match) {
390 return '%' . sprintf(
'%02x', ord($match[0]));
406 return preg_replace_callback(
'/([^A-Za-z0-9_\-\.~\(\):@])/',
function($match) {
408 return '%' . sprintf(
'%02x', ord($match[0]));
434 $encoding = mb_detect_encoding(
$path, [
'UTF-8',
'ISO-8859-1']);
decodePathSegment($path)
Decodes a url-encoded path segment.
encodePath($path)
Encodes the path of a url.
toDate(DateTime $dateTime)
Transforms a DateTime object to a valid HTTP/1.1 Date header value.
negotiateContentType($acceptHeaderValue, array $availableOptions)
This function can be used to aid with content negotiation.
decodePath($path)
Decodes a url-encoded path.
parsePrefer($input)
Parses the Prefer header, as defined in RFC7240.
encodePathSegment($pathSegment)
Encodes a 1 segment of a path.
parseDate($dateString)
A collection of useful helpers for parsing or generating various HTTP headers.
getHeaderValues($values, $values2=null)
This method splits up headers into all their individual values.
parseMimeType($str)
Parses a mime-type and splits it into: