1 | <?php |
||
2 | /** |
||
3 | * A simple object model for an HTTP cookie |
||
4 | * |
||
5 | * @package Elgg.Core |
||
6 | * @subpackage Http |
||
7 | * @see elgg_set_cookie() |
||
8 | * @see http://php.net/manual/en/function.setcookie.php |
||
9 | * @see http://php.net/manual/en/function.session-set-cookie-params.php |
||
10 | * @since 1.9.0 |
||
11 | * |
||
12 | * @property-read string $name Name of the cookie |
||
13 | */ |
||
14 | class ElggCookie { |
||
15 | /** @var string */ |
||
16 | private $name; |
||
17 | |||
18 | /** @var string */ |
||
19 | public $value = ""; |
||
20 | |||
21 | /** @var int */ |
||
22 | public $expire = 0; |
||
23 | |||
24 | /** @var string */ |
||
25 | public $path = "/"; |
||
26 | |||
27 | /** @var string */ |
||
28 | public $domain = ""; |
||
29 | |||
30 | /** @var bool */ |
||
31 | public $secure = false; |
||
32 | |||
33 | /** @var bool */ |
||
34 | public $httpOnly = false; |
||
35 | |||
36 | /** |
||
37 | * Constructor |
||
38 | * |
||
39 | * @param string $name The name of the cookie. |
||
40 | */ |
||
41 | 7 | public function __construct($name) { |
|
42 | 7 | $this->name = $name; |
|
1 ignored issue
–
show
Bug
introduced
by
Loading history...
|
|||
43 | 7 | } |
|
44 | |||
45 | /** |
||
46 | * Get an attribute |
||
47 | * |
||
48 | * @param string $name Attribute name |
||
49 | * @return mixed |
||
50 | */ |
||
51 | public function __get($name) { |
||
52 | // allow reading the private name attribute |
||
53 | if ($name === 'name') { |
||
54 | return $this->name; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Set the time the cookie expires |
||
60 | * |
||
61 | * Example: $cookie->setExpiresTime("+30 days"); |
||
62 | * |
||
63 | * @param string $time A time string appropriate for strtotime() |
||
64 | * @return void |
||
65 | */ |
||
66 | public function setExpiresTime($time) { |
||
67 | $this->expire = strtotime($time); |
||
68 | } |
||
69 | } |
||
70 |