1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Cookies plugin for Craft CMS |
||
5 | * |
||
6 | * @link https://nystudio107.com/ |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
7 | * @copyright Copyright (c) nystudio107 |
||
0 ignored issues
–
show
|
|||
8 | * @license MIT License https://opensource.org/licenses/MIT |
||
9 | */ |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | namespace nystudio107\cookies\variables; |
||
12 | |||
13 | use nystudio107\cookies\Cookies; |
||
14 | |||
15 | /** |
||
16 | * Cookies template variables |
||
17 | * |
||
18 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
19 | * @package Cookies |
||
0 ignored issues
–
show
|
|||
20 | * @since 1.1.0 |
||
0 ignored issues
–
show
|
|||
21 | */ |
||
0 ignored issues
–
show
|
|||
22 | class CookiesVariable |
||
23 | { |
||
24 | /** |
||
0 ignored issues
–
show
|
|||
25 | * Set a cookie |
||
26 | */ |
||
0 ignored issues
–
show
|
|||
27 | public function set( |
||
28 | string $name = "", |
||
29 | string $value = "", |
||
30 | int $expire = 0, |
||
31 | string $path = "/", |
||
32 | string $domain = "", |
||
33 | bool $secure = false, |
||
34 | bool $httpOnly = false, |
||
35 | string $sameSite = 'Lax', |
||
36 | ): void { |
||
37 | Cookies::$plugin->cookies->set( |
||
38 | $name, |
||
39 | $value, |
||
40 | $expire, |
||
41 | $path, |
||
42 | $domain, |
||
43 | $secure, |
||
44 | $httpOnly, |
||
45 | $sameSite |
||
46 | ); |
||
47 | } |
||
48 | |||
49 | /** |
||
0 ignored issues
–
show
|
|||
50 | * Get a cookie |
||
51 | */ |
||
0 ignored issues
–
show
|
|||
52 | public function get(string $name): string |
||
53 | { |
||
54 | return Cookies::$plugin->cookies->get($name); |
||
55 | } |
||
56 | |||
57 | /** |
||
0 ignored issues
–
show
|
|||
58 | * Set a secure cookie |
||
59 | */ |
||
0 ignored issues
–
show
|
|||
60 | public function setSecure( |
||
61 | string $name = "", |
||
62 | string $value = "", |
||
63 | int $expire = 0, |
||
64 | string $path = "/", |
||
65 | string $domain = "", |
||
66 | bool $secure = false, |
||
67 | bool $httpOnly = false, |
||
68 | string $sameSite = 'Lax', |
||
69 | ): void { |
||
70 | Cookies::$plugin->cookies->setSecure( |
||
71 | $name, |
||
72 | $value, |
||
73 | $expire, |
||
74 | $path, |
||
75 | $domain, |
||
76 | $secure, |
||
77 | $httpOnly, |
||
78 | $sameSite |
||
79 | ); |
||
80 | } |
||
81 | |||
82 | /** |
||
0 ignored issues
–
show
|
|||
83 | * Get a secure cookie |
||
84 | */ |
||
0 ignored issues
–
show
|
|||
85 | public function getSecure(string $name): string |
||
86 | { |
||
87 | return Cookies::$plugin->cookies->getSecure($name); |
||
88 | } |
||
89 | } |
||
90 |