← All changes
|
vendor/wpfluent/framework/src/WPFluent/Http/Cookie.php
+82
-2
1.3.21
→
1.6.5
View file →
| @@ -66,10 +66,90 @@ | ||
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | + * Set a cookie whose value is base64(json($value)). | |
| 71 | + * | |
| 72 | + * Pairs with Request::cookie(), which auto-detects this exact format | |
| 73 | + * and decodes back to the original value on read. Use this when you | |
| 74 | + * need to store arrays/objects in a cookie — strings, numbers, and | |
| 75 | + * scalars work just fine through plain set() and don't need encoding. | |
| 76 | + * | |
| 77 | + * @param string $name | |
| 78 | + * @param mixed $value Anything json_encode can serialize | |
| 79 | + * @param int|DateTimeInterface $minutes | |
| 80 | + * @param string $path | |
| 81 | + * @param string $domain | |
| 82 | + * @param bool $secure | |
| 83 | + * @param bool $httponly | |
| 84 | + * @param string $samesite | |
| 85 | + * | |
| 86 | + * @return void | |
| 87 | + */ | |
| 88 | + public static function setEncoded( | |
| 89 | + $name, | |
| 90 | + $value, | |
| 91 | + $minutes = 0, | |
| 92 | + $path = '/', | |
| 93 | + $domain = '', | |
| 94 | + $secure = false, | |
| 95 | + $httponly = false, | |
| 96 | + $samesite = 'Lax' | |
| 97 | + ) { | |
| 98 | + static::set( | |
| 99 | + $name, | |
| 100 | + base64_encode(json_encode($value)), | |
| 101 | + $minutes, | |
| 102 | + $path, | |
| 103 | + $domain, | |
| 104 | + $secure, | |
| 105 | + $httponly, | |
| 106 | + $samesite | |
| 107 | + ); | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Queue a cookie whose value is base64(json($value)) for send_headers. | |
| 112 | + * | |
| 113 | + * Same encoding contract as setEncoded() — pairs with Request::cookie() | |
| 114 | + * auto-decode on the read side. | |
| 115 | + * | |
| 116 | + * @param string $name | |
| 117 | + * @param mixed $value | |
| 118 | + * @param int|DateTimeInterface $minutes | |
| 119 | + * @param string $path | |
| 120 | + * @param string $domain | |
| 121 | + * @param bool $secure | |
| 122 | + * @param bool $httponly | |
| 123 | + * @param string $samesite | |
| 124 | + * | |
| 125 | + * @return void | |
| 126 | + */ | |
| 127 | + public static function queueEncoded( | |
| 128 | + $name, | |
| 129 | + $value, | |
| 130 | + $minutes = 0, | |
| 131 | + $path = '/', | |
| 132 | + $domain = '', | |
| 133 | + $secure = false, | |
| 134 | + $httponly = false, | |
| 135 | + $samesite = 'Lax' | |
| 136 | + ) { | |
| 137 | + static::queue( | |
| 138 | + $name, | |
| 139 | + base64_encode(json_encode($value)), | |
| 140 | + $minutes, | |
| 141 | + $path, | |
| 142 | + $domain, | |
| 143 | + $secure, | |
| 144 | + $httponly, | |
| 145 | + $samesite | |
| 146 | + ); | |
| 147 | + } | |
| 148 | + | |
| 149 | + /** | |
| 70 | 150 | * Set a cookie that lasts 5 years. |
| 71 | - * | |
| 151 | + * | |
| 72 | 152 | * @param string $name |
| 73 | 153 | * @param mixed $value |
| 74 | 154 | * @param string $path = '/' |
| 75 | 155 | * @param string $domain |
| @@ -75,9 +155,9 @@ | ||
| 75 | 155 | * @param string $domain |
| 76 | 156 | * @param bool $secure |
| 77 | 157 | * @param bool $httponly |
| 78 | 158 | * @param string $samesite |
| 79 | - * | |
| 159 | + * | |
| 80 | 160 | * @return void |
| 81 | 161 | */ |
| 82 | 162 | public static function setForever( |
| 83 | 163 | $name, |