b3b565147f2c4810f6f7f9cf572a6e98dac375a5
[yaffs-website] / vendor / zendframework / zend-diactoros / src / functions / parse_cookie_header.php
1 <?php
2 /**
3  * @see       https://github.com/zendframework/zend-diactoros for the canonical source repository
4  * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5  * @license   https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
6  */
7
8 namespace Zend\Diactoros;
9
10 use function preg_match_all;
11 use function urldecode;
12
13 /**
14  * Parse a cookie header according to RFC 6265.
15  *
16  * PHP will replace special characters in cookie names, which results in other cookies not being available due to
17  * overwriting. Thus, the server request should take the cookies from the request header instead.
18  *
19  * @param string $cookieHeader A string cookie header value.
20  * @return array key/value cookie pairs.
21  */
22 function parseCookieHeader($cookieHeader)
23 {
24     preg_match_all('(
25         (?:^\\n?[ \t]*|;[ ])
26         (?P<name>[!#$%&\'*+-.0-9A-Z^_`a-z|~]+)
27         =
28         (?P<DQUOTE>"?)
29             (?P<value>[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*)
30         (?P=DQUOTE)
31         (?=\\n?[ \t]*$|;[ ])
32     )x', $cookieHeader, $matches, PREG_SET_ORDER);
33
34     $cookies = [];
35
36     foreach ($matches as $match) {
37         $cookies[$match['name']] = urldecode($match['value']);
38     }
39
40     return $cookies;
41 }