Total Complexity | 4 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
15 | class CookieTest implements DaftRoute |
||
16 | { |
||
17 | public static function DaftRouterHandleRequest(Request $request, array $args) : Response |
||
18 | { |
||
19 | $resp = new Response(''); |
||
20 | |||
21 | $cookie = new Cookie( |
||
22 | $args['name'], |
||
23 | $args['value'], |
||
24 | 123, |
||
25 | '', |
||
26 | null, |
||
27 | '1' === $args['secure'], |
||
28 | '1' === $args['http'], |
||
29 | false, |
||
30 | $args['same-site'] |
||
31 | ); |
||
32 | |||
33 | $resp->headers->setCookie($cookie); |
||
34 | |||
35 | return $resp; |
||
36 | } |
||
37 | |||
38 | public static function DaftRouterRoutes() : array |
||
39 | { |
||
40 | return [ |
||
41 | '/cookie-test/{name:[^\/]+}/{value:[^\/]+}/{secure:[0-1]}/{http:[0-1]}/{same-site:(?:lax|strict)}' => ['GET'], |
||
42 | ]; |
||
43 | } |
||
44 | |||
45 | public static function DaftRouterHttpRoute(array $args, string $method = 'GET') : string |
||
46 | { |
||
47 | if ( |
||
48 | ! isset( |
||
49 | $args['name'], |
||
50 | $args['value'], |
||
51 | $args['secure'], |
||
52 | $args['http'], |
||
53 | $args['same-site'] |
||
54 | ) |
||
55 | ) { |
||
56 | throw new InvalidArgumentException('cookie args not specified!'); |
||
57 | } |
||
58 | |||
59 | return sprintf( |
||
60 | '/cookie-test/%s/%s/%u/%u/%s', |
||
61 | $args['name'], |
||
62 | $args['value'], |
||
63 | $args['secure'], |
||
64 | $args['http'], |
||
65 | $args['same-site'] |
||
66 | ); |
||
69 |