From 580c3f4ffe9608d2beb56d418c68b3b112420e76 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Nov 2019 12:49:51 +0000 Subject: another bulk of composer updates (cherry picked from commit 6685381fd8db507493c3d7c1793f8c05c681bbce) --- vendor/sabre/http/lib/functions.php | 183 ++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 100 deletions(-) (limited to 'vendor/sabre/http/lib/functions.php') diff --git a/vendor/sabre/http/lib/functions.php b/vendor/sabre/http/lib/functions.php index d94119623..197a9e661 100644 --- a/vendor/sabre/http/lib/functions.php +++ b/vendor/sabre/http/lib/functions.php @@ -1,8 +1,11 @@ setTimezone(new \DateTimeZone('GMT')); - return $dateTime->format('D, d M Y H:i:s \G\M\T'); + return $dateTime->format('D, d M Y H:i:s \G\M\T'); } /** @@ -101,11 +107,12 @@ function toDate(DateTime $dateTime) { * implying that no accept header was sent. * * @param string|null $acceptHeaderValue - * @param array $availableOptions + * @param array $availableOptions + * * @return string|null */ -function negotiateContentType($acceptHeaderValue, array $availableOptions) { - +function negotiateContentType($acceptHeaderValue, array $availableOptions) +{ if (!$acceptHeaderValue) { // Grabbing the first in the list. return reset($availableOptions); @@ -130,9 +137,10 @@ function negotiateContentType($acceptHeaderValue, array $availableOptions) { $lastChoice = null; foreach ($proposals as $proposal) { - // Ignoring broken values. - if (is_null($proposal)) continue; + if (null === $proposal) { + continue; + } // If the quality is lower we don't have to bother comparing. if ($proposal['quality'] < $lastQuality) { @@ -140,12 +148,11 @@ function negotiateContentType($acceptHeaderValue, array $availableOptions) { } foreach ($options as $optionIndex => $option) { - - if ($proposal['type'] !== '*' && $proposal['type'] !== $option['type']) { + if ('*' !== $proposal['type'] && $proposal['type'] !== $option['type']) { // no match on type. continue; } - if ($proposal['subType'] !== '*' && $proposal['subType'] !== $option['subType']) { + if ('*' !== $proposal['subType'] && $proposal['subType'] !== $option['subType']) { // no match on subtype. continue; } @@ -165,31 +172,25 @@ function negotiateContentType($acceptHeaderValue, array $availableOptions) { // subtype. We need to calculate a score for how specific the // match was. $specificity = - ($proposal['type'] !== '*' ? 20 : 0) + - ($proposal['subType'] !== '*' ? 10 : 0) + + ('*' !== $proposal['type'] ? 20 : 0) + + ('*' !== $proposal['subType'] ? 10 : 0) + count($option['parameters']); - // Does this entry win? if ( ($proposal['quality'] > $lastQuality) || ($proposal['quality'] === $lastQuality && $specificity > $lastSpecificity) || ($proposal['quality'] === $lastQuality && $specificity === $lastSpecificity && $optionIndex < $lastOptionIndex) ) { - $lastQuality = $proposal['quality']; $lastSpecificity = $specificity; $lastOptionIndex = $optionIndex; $lastChoice = $availableOptions[$optionIndex]; - } - } - } return $lastChoice; - } /** @@ -217,10 +218,11 @@ function negotiateContentType($acceptHeaderValue, array $availableOptions) { * uses them. * * @param string|string[] $input + * * @return array */ -function parsePrefer($input) { - +function parsePrefer($input): array +{ $token = '[!#$%&\'*+\-.^_`~A-Za-z0-9]+'; // Work in progress @@ -241,7 +243,6 @@ REGEX; $output = []; foreach (getHeaderValues($input) as $value) { - if (!preg_match($regex, $value, $matches)) { // Ignore continue; @@ -249,22 +250,22 @@ REGEX; // Mapping old values to their new counterparts switch ($matches['name']) { - case 'return-asynch' : + case 'return-asynch': $output['respond-async'] = true; break; - case 'return-representation' : + case 'return-representation': $output['return'] = 'representation'; break; - case 'return-minimal' : + case 'return-minimal': $output['return'] = 'minimal'; break; - case 'strict' : + case 'strict': $output['handling'] = 'strict'; break; - case 'lenient' : + case 'lenient': $output['handling'] = 'lenient'; break; - default : + default: if (isset($matches['value'])) { $value = trim($matches['value'], '"'); } else { @@ -273,11 +274,9 @@ REGEX; $output[strtolower($matches['name'])] = empty($value) ? true : $value; break; } - } return $output; - } /** @@ -296,25 +295,26 @@ REGEX; * * @param string|string[] $values * @param string|string[] $values2 - * @return string[] */ -function getHeaderValues($values, $values2 = null) { - - $values = (array)$values; +function getHeaderValues($values, $values2 = null): array +{ + $values = (array) $values; if ($values2) { - $values = array_merge($values, (array)$values2); + $values = array_merge($values, (array) $values2); } + + $result = array(); foreach ($values as $l1) { foreach (explode(',', $l1) as $l2) { $result[] = trim($l2); } } - return $result; + return $result; } /** - * Parses a mime-type and splits it into: + * Parses a mime-type and splits it into:. * * 1. type * 2. subtype @@ -322,10 +322,11 @@ function getHeaderValues($values, $values2 = null) { * 4. parameters * * @param string $str + * * @return array */ -function parseMimeType($str) { - +function parseMimeType(string $str): array +{ $parameters = []; // If no q= parameter appears, then quality = 1. $quality = 1; @@ -333,17 +334,22 @@ function parseMimeType($str) { $parts = explode(';', $str); // The first part is the mime-type. - $mimeType = array_shift($parts); + $mimeType = trim(array_shift($parts)); + + if ('*' === $mimeType) { + $mimeType = '*/*'; + } - $mimeType = explode('/', trim($mimeType)); - if (count($mimeType) !== 2) { + $mimeType = explode('/', $mimeType); + if (2 !== count($mimeType)) { // Illegal value - return null; + var_dump($mimeType); + die(); + throw new InvalidArgumentException('Not a valid mime-type: '.$str); } list($type, $subType) = $mimeType; foreach ($parts as $part) { - $part = trim($part); if (strpos($part, '=')) { list($partName, $partValue) = @@ -357,89 +363,66 @@ function parseMimeType($str) { // the parameter list. Anything after the q= counts as an // 'accept extension' and could introduce new semantics in // content-negotation. - if ($partName !== 'q') { + if ('q' !== $partName) { $parameters[$partName] = $part; } else { - $quality = (float)$partValue; + $quality = (float) $partValue; break; // Stop parsing parts } - } return [ - 'type' => $type, - 'subType' => $subType, - 'quality' => $quality, + 'type' => $type, + 'subType' => $subType, + 'quality' => $quality, 'parameters' => $parameters, ]; - } /** * Encodes the path of a url. * * slashes (/) are treated as path-separators. - * - * @param string $path - * @return string */ -function encodePath($path) { - - return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\)\/:@])/', function($match) { - - return '%' . sprintf('%02x', ord($match[0])); - +function encodePath(string $path): string +{ + return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\)\/:@])/', function ($match) { + return '%'.sprintf('%02x', ord($match[0])); }, $path); - } /** - * Encodes a 1 segment of a path + * Encodes a 1 segment of a path. * * Slashes are considered part of the name, and are encoded as %2f - * - * @param string $pathSegment - * @return string */ -function encodePathSegment($pathSegment) { - - return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\):@])/', function($match) { - - return '%' . sprintf('%02x', ord($match[0])); - +function encodePathSegment(string $pathSegment): string +{ + return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\):@])/', function ($match) { + return '%'.sprintf('%02x', ord($match[0])); }, $pathSegment); } /** - * Decodes a url-encoded path - * - * @param string $path - * @return string + * Decodes a url-encoded path. */ -function decodePath($path) { - +function decodePath(string $path): string +{ return decodePathSegment($path); - } /** - * Decodes a url-encoded path segment - * - * @param string $path - * @return string + * Decodes a url-encoded path segment. */ -function decodePathSegment($path) { - +function decodePathSegment(string $path): string +{ $path = rawurldecode($path); $encoding = mb_detect_encoding($path, ['UTF-8', 'ISO-8859-1']); switch ($encoding) { - - case 'ISO-8859-1' : + case 'ISO-8859-1': $path = utf8_encode($path); - } return $path; - } -- cgit v1.2.3