File tree Expand file tree Collapse file tree 4 files changed +107
-8
lines changed Expand file tree Collapse file tree 4 files changed +107
-8
lines changed Original file line number Diff line number Diff line change @@ -102,10 +102,22 @@ Cookie::destroy($key);
102
102
103
103
** # Return** (boolean)
104
104
105
+ ### - Establecer prefijo para cookies:
106
+
107
+ ``` php
108
+ Cookie::setPrefix($prefix);
109
+ ```
110
+
111
+ | Atributo | Descripción | Tipo | Requerido | Predeterminado
112
+ | --- | --- | --- | --- | --- |
113
+ | $prefix | Prefijo para las cookies. | string | Sí | |
114
+
115
+ ** # Return** (boolean)
116
+
105
117
### - Obtener prefijo de cookies:
106
118
107
119
``` php
108
- Cookie::getCookiePrefix ();
120
+ Cookie::getPrefix ();
109
121
```
110
122
111
123
** # Return** (string) → prefijo de cookies
@@ -168,10 +180,16 @@ Cookie::destroy('cookie_name');
168
180
Cookie::destroy();
169
181
```
170
182
183
+ ### - Establecer prefijo para cookies:
184
+
185
+ ``` php
186
+ Cookie::setPrefix('prefix_');
187
+ ```
188
+
171
189
### - Obtener prefijo de cookies:
172
190
173
191
``` php
174
- Cookie::getCookiePrefix ();
192
+ Cookie::getPrefix ();
175
193
```
176
194
177
195
## Tests
Original file line number Diff line number Diff line change @@ -102,10 +102,22 @@ Cookie::destroy($key);
102
102
103
103
** # Return** (boolean)
104
104
105
+ ### - Set cookie prefix:
106
+
107
+ ``` php
108
+ Cookie::setPrefix($prefix);
109
+ ```
110
+
111
+ | Attribute | Description | Type | Required | Default
112
+ | --- | --- | --- | --- | --- |
113
+ | $prefix | Cookie prefix. | string | Yes | |
114
+
115
+ ** # Return** (boolean)
116
+
105
117
### - Get cookie prefix:
106
118
107
119
``` php
108
- Cookie::getCookiePrefix ();
120
+ Cookie::getPrefix ();
109
121
```
110
122
111
123
** # Return** (string) → cookie prefix
@@ -168,10 +180,16 @@ Cookie::destroy('cookie_name');
168
180
Cookie::destroy();
169
181
```
170
182
183
+ ### - Set cookie prefix:
184
+
185
+ ``` php
186
+ Cookie::setPrefix('prefix_');
187
+ ```
188
+
171
189
### - Get cookie prefix:
172
190
173
191
``` php
174
- Cookie::getCookiePrefix ();
192
+ Cookie::getPrefix ();
175
193
```
176
194
177
195
## Tests
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ class Cookie
31
31
* @param string $value → the data to save
32
32
* @param string $time → expiration time in days
33
33
*
34
- * @return bool
34
+ * @return boolean
35
35
*/
36
36
public static function set ($ key , $ value , $ time = 365 )
37
37
{
@@ -79,7 +79,7 @@ public static function pull($key)
79
79
*
80
80
* @param string $key → cookie name to destroy. Not set to delete all
81
81
*
82
- * @return bool
82
+ * @return boolean
83
83
*/
84
84
public static function destroy ($ key = '' )
85
85
{
@@ -100,14 +100,33 @@ public static function destroy($key = '')
100
100
return false ;
101
101
}
102
102
103
+ /**
104
+ * Set cookie prefix.
105
+ *
106
+ * @since 1.1.6
107
+ *
108
+ * @param string $prefix → cookie prefix
109
+ *
110
+ * @return boolean
111
+ */
112
+ public static function setPrefix ($ prefix )
113
+ {
114
+ if (!empty ($ prefix ) && is_string ($ prefix )) {
115
+ self ::$ prefix = $ prefix ;
116
+ return true ;
117
+ }
118
+
119
+ return false ;
120
+ }
121
+
103
122
/**
104
123
* Get cookie prefix.
105
124
*
106
125
* @since 1.1.5
107
126
*
108
127
* @return string
109
128
*/
110
- public static function getCookiePrefix ()
129
+ public static function getPrefix ()
111
130
{
112
131
return self ::$ prefix ;
113
132
}
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public function setUp()
50
50
51
51
$ cookie = $ this ->Cookie ;
52
52
53
- $ this ->cookiePrefix = $ cookie ::getCookiePrefix ();
53
+ $ this ->cookiePrefix = $ cookie ::getPrefix ();
54
54
}
55
55
56
56
/**
@@ -197,4 +197,48 @@ public function testDestroyAllCookiesNonExistents()
197
197
198
198
$ this ->assertFalse ($ cookie ::destroy ());
199
199
}
200
+
201
+ /**
202
+ * Get cookie prefix.
203
+ *
204
+ * @runInSeparateProcess
205
+ *
206
+ * @since 1.1.6
207
+ */
208
+ public function testGetCookiePrefix ()
209
+ {
210
+ $ cookie = $ this ->Cookie ;
211
+
212
+ $ this ->assertContains ($ cookie ::getPrefix (), 'jst_ ' );
213
+ }
214
+
215
+ /**
216
+ * Set cookie prefix.
217
+ *
218
+ * @runInSeparateProcess
219
+ *
220
+ * @since 1.1.6
221
+ */
222
+ public function testSetCookiePrefix ()
223
+ {
224
+ $ cookie = $ this ->Cookie ;
225
+
226
+ $ this ->assertTrue ($ cookie ::setPrefix ('prefix_ ' ));
227
+ }
228
+
229
+ /**
230
+ * Set cookie prefix incorrectly.
231
+ *
232
+ * @runInSeparateProcess
233
+ *
234
+ * @since 1.1.6
235
+ */
236
+ public function testSetCookieIncorrectly ()
237
+ {
238
+ $ cookie = $ this ->Cookie ;
239
+
240
+ $ this ->assertFalse ($ cookie ::setPrefix ('' ));
241
+ $ this ->assertFalse ($ cookie ::setPrefix (5 ));
242
+ $ this ->assertFalse ($ cookie ::setPrefix (true ));
243
+ }
200
244
}
You can’t perform that action at this time.
0 commit comments