1 | <?php |
||
2 | |||
3 | namespace Bytic\Cookie; |
||
4 | |||
5 | class Cookie extends \Symfony\Component\HttpFoundation\Cookie |
||
6 | { |
||
7 | public function setName($name) |
||
8 | { |
||
9 | $this->name = $name; |
||
10 | return $this; |
||
11 | } |
||
12 | |||
13 | /** |
||
14 | * @param $value |
||
15 | * @return $this |
||
16 | */ |
||
17 | public function setValue($value): self |
||
18 | { |
||
19 | $this->value = $value; |
||
20 | |||
21 | return $this; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @param $domain |
||
26 | * @return $this |
||
27 | */ |
||
28 | public function setDomain($domain): self |
||
29 | { |
||
30 | $this->domain = $domain; |
||
31 | |||
32 | return $this; |
||
33 | } |
||
34 | |||
35 | public function setPath($path): self |
||
36 | { |
||
37 | $this->path = $path; |
||
38 | |||
39 | return $this; |
||
40 | } |
||
41 | |||
42 | public function setExpire($expire) |
||
43 | { |
||
44 | $this->expire = $expire; |
||
45 | |||
46 | return $this; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return int |
||
51 | */ |
||
52 | public function getExpire() |
||
53 | { |
||
54 | return $this->getExpiresTime(); |
||
55 | } |
||
56 | |||
57 | public function setExpireTimer($expires) |
||
58 | { |
||
59 | $this->expire = time() + $expires; |
||
60 | |||
61 | return $this; |
||
62 | } |
||
63 | |||
64 | public function setSecured($secured) |
||
65 | { |
||
66 | $this->secure = $secured; |
||
67 | |||
68 | return $this; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @return bool |
||
73 | */ |
||
74 | public function isExpired(): bool |
||
75 | { |
||
76 | if (is_int($this->expire) && $this->expire < time()) { |
||
77 | return true; |
||
78 | } else { |
||
79 | return false; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function save(): bool |
||
87 | { |
||
88 | $domain = ($this->getDomain() != 'localhost') ? $this->getDomain() : false; |
||
89 | |||
90 | return setcookie( |
||
91 | $this->getName(), |
||
92 | $this->getValue(), |
||
93 | $this->getExpire(), |
||
94 | $this->getPath(), |
||
95 | $domain, |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
96 | $this->isSecure() |
||
97 | ); |
||
98 | } |
||
99 | } |
||
100 |