Completed
Push — master ( 9fe7e8...7331b7 )
by Aurimas
12:47
created

CookieParamParser::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 9.4286
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace Thruster\Component\Http\Parser;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
/**
8
 * Class CookieParamParser
9
 *
10
 * @package Thruster\Component\Http\Parser
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
class CookieParamParser implements ParserInterface
14
{
15
    /**
16
     * @inheritDoc
17
     */
18
    public function parse(ServerRequestInterface $request) : ServerRequestInterface
19
    {
20
        $headerValues = $request->getHeader('Cookie');
21
        $cookies = [];
22
23
        foreach ($headerValues as $headerValue) {
24
            $parts = explode(';', str_replace('; ', ';', $headerValue));
25
26
            foreach ($parts as $part) {
27
                list($key, $value) = explode('=', $part);
28
29
                $cookies[$key] = $value;
30
            }
31
        }
32
33
        return $request->withCookieParams($cookies);
34
    }
35
36
}
37