Skip to content

Commit 2faaf72

Browse files
committed
Cookie 1.1.0
1 parent ad6aa6a commit 2faaf72

File tree

3 files changed

+55
-45
lines changed

3 files changed

+55
-45
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v1.1.0, 2018-04-12
2+
* PHP7 Support added
3+
14
# v1.0.1, 2015-10-17
25
* MIT LICENSE instead of GNU GPL v3
36

Cookie.php

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,39 @@
11
<?php
22

3-
/**
4-
* This file is part of the Force Components.
5-
*
6-
* (c) Romanenko Sergey / Awilum <awilum@msn.com>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
3+
/**
4+
* @package Flextype Components
5+
*
6+
* @author Sergey Romanenko <awilum@yandex.ru>
7+
* @link http://components.flextype.org
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
namespace Flextype\Component\Cookie;
1114

1215
class Cookie
1316
{
14-
/**
15-
* Protected constructor since this is a static class.
16-
*
17-
* @access protected
18-
*/
19-
protected function __construct()
20-
{
21-
// Nothing here
22-
}
2317

2418
/**
25-
* Send a cookie
19+
* Set a cookie
2620
*
27-
* <code>
28-
* Cookie::set('limit', 10);
29-
* </code>
21+
* Cookie::set('username', 'Awilum');
3022
*
3123
* @param string $key A name for the cookie.
3224
* @param mixed $value The value to be stored. Keep in mind that they will be serialized.
33-
* @param integer $expire The number of seconds that this cookie will be available.
25+
* @param int $expire The number of seconds that this cookie will be available.
3426
* @param string $path The path on the server in which the cookie will be availabe. Use / for the entire domain, /foo if you just want it to be available in /foo.
3527
* @param string $domain The domain that the cookie is available on. Use .example.com to make it available on all subdomains of example.com.
36-
* @param boolean $secure Should the cookie be transmitted over a HTTPS-connection? If true, make sure you use a secure connection, otherwise the cookie won't be set.
37-
* @param boolean $httpOnly Should the cookie only be available through HTTP-protocol? If true, the cookie can't be accessed by Javascript, ...
38-
* @return boolean
28+
* @param bool $secure Should the cookie be transmitted over a HTTPS-connection? If true, make sure you use a secure connection, otherwise the cookie won't be set.
29+
* @param bool $httpOnly Should the cookie only be available through HTTP-protocol? If true, the cookie can't be accessed by Javascript, ...
30+
* @return bool
3931
*/
40-
public static function set($key, $value, $expire = 86400, $domain = '', $path = '/', $secure = false, $httpOnly = false)
32+
public static function set(string $key, $value, int $expire = 86400, string $domain = '', string $path = '/', bool $secure = false, bool $httpOnly = false) : bool
4133
{
4234
// Redefine vars
43-
$key = (string) $key;
4435
$value = serialize($value);
45-
$expire = time() + (int) $expire;
46-
$path = (string) $path;
47-
$domain = (string) $domain;
48-
$secure = (bool) $secure;
49-
$httpOnly = (bool) $httpOnly;
36+
$expire = time() + $expire;
5037

5138
// Set cookie
5239
return setcookie($key, $value, $expire, $path, $domain, $secure, $httpOnly);
@@ -55,14 +42,12 @@ public static function set($key, $value, $expire = 86400, $domain = '', $path =
5542
/**
5643
* Get a cookie
5744
*
58-
* <code>
59-
* $limit = Cookie::get('limit');
60-
* </code>
45+
* $username = Cookie::get('username');
6146
*
6247
* @param string $key The name of the cookie that should be retrieved.
6348
* @return mixed
6449
*/
65-
public static function get($key)
50+
public static function get(string $key)
6651
{
6752
// Redefine key
6853
$key = (string) $key;
@@ -91,13 +76,11 @@ public static function get($key)
9176
/**
9277
* Delete a cookie
9378
*
94-
* <code>
95-
* Cookie::delete('limit');
96-
* </code>
79+
* Cookie::delete('username');
9780
*
9881
* @param string $name The name of the cookie that should be deleted.
9982
*/
100-
public static function delete($key)
83+
public static function delete(string $key) : void
10184
{
10285
unset($_COOKIE[$key]);
10386
}

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
# Cookie
2-
The cookie class
1+
# Cookie Component
2+
![version](https://img.shields.io/badge/version-1.1.0-brightgreen.svg?style=flat-square "Version")
3+
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/flextype-components/cookie/blob/master/LICENSE)
34

5+
Cookie component contains methods that assist in working with cookies.
6+
7+
### Installation
8+
9+
```
10+
composer require flextype-components/cookie
11+
```
12+
13+
### Usage
14+
15+
```php
16+
use Flextype\Component\Cookie\Cookie;
17+
```
18+
19+
Set a cookie
420
```php
5-
Cookie::set('limit', 10);
6-
$limit = Cookie::get('limit');
21+
Cookie::set('username', 'Awilum');
722
```
823

24+
Get a cookie
25+
```php
26+
$username = Cookie::get('username');
27+
```
28+
29+
Delete a cookie
30+
```php
31+
Cookie::delete('username');
32+
```
933

1034
## License
11-
See [LICENSE](https://github.com/force-components/Cookie/blob/master/LICENSE)
35+
See [LICENSE](https://github.com/flextype-components/cookie/blob/master/LICENSE)

0 commit comments

Comments
 (0)