Skip to content

Commit 8cf9e16

Browse files
committed
Updated to 1.1.6 version
1 parent f9d2c20 commit 8cf9e16

File tree

4 files changed

+107
-8
lines changed

4 files changed

+107
-8
lines changed

README-ES.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,22 @@ Cookie::destroy($key);
102102

103103
**# Return** (boolean)
104104

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 || |
114+
115+
**# Return** (boolean)
116+
105117
### - Obtener prefijo de cookies:
106118

107119
```php
108-
Cookie::getCookiePrefix();
120+
Cookie::getPrefix();
109121
```
110122

111123
**# Return** (string) → prefijo de cookies
@@ -168,10 +180,16 @@ Cookie::destroy('cookie_name');
168180
Cookie::destroy();
169181
```
170182

183+
### - Establecer prefijo para cookies:
184+
185+
```php
186+
Cookie::setPrefix('prefix_');
187+
```
188+
171189
### - Obtener prefijo de cookies:
172190

173191
```php
174-
Cookie::getCookiePrefix();
192+
Cookie::getPrefix();
175193
```
176194

177195
## Tests

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,22 @@ Cookie::destroy($key);
102102

103103
**# Return** (boolean)
104104

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+
105117
### - Get cookie prefix:
106118

107119
```php
108-
Cookie::getCookiePrefix();
120+
Cookie::getPrefix();
109121
```
110122

111123
**# Return** (string) → cookie prefix
@@ -168,10 +180,16 @@ Cookie::destroy('cookie_name');
168180
Cookie::destroy();
169181
```
170182

183+
### - Set cookie prefix:
184+
185+
```php
186+
Cookie::setPrefix('prefix_');
187+
```
188+
171189
### - Get cookie prefix:
172190

173191
```php
174-
Cookie::getCookiePrefix();
192+
Cookie::getPrefix();
175193
```
176194

177195
## Tests

src/Cookie.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Cookie
3131
* @param string $value → the data to save
3232
* @param string $time → expiration time in days
3333
*
34-
* @return bool
34+
* @return boolean
3535
*/
3636
public static function set($key, $value, $time = 365)
3737
{
@@ -79,7 +79,7 @@ public static function pull($key)
7979
*
8080
* @param string $key → cookie name to destroy. Not set to delete all
8181
*
82-
* @return bool
82+
* @return boolean
8383
*/
8484
public static function destroy($key = '')
8585
{
@@ -100,14 +100,33 @@ public static function destroy($key = '')
100100
return false;
101101
}
102102

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+
103122
/**
104123
* Get cookie prefix.
105124
*
106125
* @since 1.1.5
107126
*
108127
* @return string
109128
*/
110-
public static function getCookiePrefix()
129+
public static function getPrefix()
111130
{
112131
return self::$prefix;
113132
}

tests/CookieTest.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function setUp()
5050

5151
$cookie = $this->Cookie;
5252

53-
$this->cookiePrefix = $cookie::getCookiePrefix();
53+
$this->cookiePrefix = $cookie::getPrefix();
5454
}
5555

5656
/**
@@ -197,4 +197,48 @@ public function testDestroyAllCookiesNonExistents()
197197

198198
$this->assertFalse($cookie::destroy());
199199
}
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+
}
200244
}

0 commit comments

Comments
 (0)