11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Escopecz \MauticFormSubmit ;
46
57/**
@@ -12,35 +14,25 @@ class Cookie
1214 * because when cookie is set with setCookie
1315 * it's accessible on the next script run only,
1416 * not at the same run.
15- *
16- * @var array
1717 */
18- protected $ store = [];
18+ protected array $ store = [];
1919
2020 /**
2121 * Get cookie with FILTER_SANITIZE_STRING
22- *
23- * @param string $key
24- *
25- * @return string|null
2622 */
27- public function get ($ key )
23+ public function get (string $ key ): string | false | null
2824 {
2925 if (isset ($ this ->store [$ key ])) {
30- return filter_var ($ this ->store [$ key ], FILTER_SANITIZE_STRING );
26+ return filter_var ($ this ->store [$ key ], FILTER_SANITIZE_SPECIAL_CHARS );
3127 }
3228
33- return filter_input (INPUT_COOKIE , $ key , FILTER_SANITIZE_STRING );
29+ return filter_input (INPUT_COOKIE , $ key , FILTER_SANITIZE_SPECIAL_CHARS );
3430 }
3531
3632 /**
3733 * Get cookie with FILTER_SANITIZE_NUMBER_INT
38- *
39- * @param string $key
40- *
41- * @return int|null
4234 */
43- public function getInt ($ key )
35+ public function getInt (string $ key ): int
4436 {
4537 if (isset ($ this ->store [$ key ])) {
4638 return (int ) filter_var ($ this ->store [$ key ], FILTER_SANITIZE_NUMBER_INT );
@@ -49,63 +41,39 @@ public function getInt($key)
4941 return (int ) filter_input (INPUT_COOKIE , $ key , FILTER_SANITIZE_NUMBER_INT );
5042 }
5143
52- /**
53- * Set a cookie value
54- *
55- * @param string $key
56- * @param mixed $value
57- *
58- * @return bool
59- */
60- public function set ($ key , $ value )
44+ public function set (string $ key , mixed $ value ): bool
6145 {
6246 $ this ->store [$ key ] = $ value ;
6347
64- return setcookie ($ key , $ value );
48+ return setcookie ($ key , ( string ) $ value );
6549 }
6650
67- /**
68- * Unset the key from the cookie
69- *
70- * @param string $key
71- *
72- * @return Cookie
73- */
74- public function clear ($ key )
51+ public function clear (string $ key ): static
7552 {
76- setcookie ($ key , '' , time () - 3600 );
53+ setcookie ($ key , '' , [ ' expires ' => time () - 3600 ] );
7754 unset($ _COOKIE [$ key ]);
7855 unset($ this ->store [$ key ]);
7956
8057 return $ this ;
8158 }
8259
83- /**
84- * Returns $_COOKIE
85- *
86- * @return array
87- */
88- public function getSuperGlobalCookie ()
60+ public function getSuperGlobalCookie (): array
8961 {
9062 return $ _COOKIE ;
9163 }
9264
9365 /**
9466 * Return all cookies as array merged with current state
95- *
96- * @return array
9767 */
98- public function toArray ()
68+ public function toArray (): array
9969 {
10070 return array_merge ($ this ->getSuperGlobalCookie (), $ this ->store );
10171 }
10272
10373 /**
10474 * Creates unique cookie file in system tmp dir and returns absolute path to it.
105- *
106- * @return string|false
10775 */
108- public function createCookieFile ()
76+ public function createCookieFile (): string | false
10977 {
11078 return tempnam (sys_get_temp_dir (), 'mauticcookie ' );
11179 }
0 commit comments