Skip to content

Commit 0739984

Browse files
authored
Merge pull request ExpressionEngine#734 from ExpressionEngine/feature/7.x/cookie-registry
document cookie registry service and model
2 parents f3c1873 + 7079c49 commit 0739984

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
lang: php
3+
---
4+
5+
<!--
6+
This source file is part of the open source project
7+
ExpressionEngine User Guide (https://github.com/ExpressionEngine/ExpressionEngine-User-Guide)
8+
9+
@link https://expressionengine.com/
10+
@copyright Copyright (c) 2003-2023, Packet Tide, LLC (https://packettide.com)
11+
@license https://expressionengine.com/license Licensed under Apache License, Version 2.0
12+
-->
13+
14+
# Cookie Settings Model
15+
16+
**class `ExpressionEngine\Model\Cookie\CookieSetting`**
17+
18+
[TOC]
19+
20+
## Properties
21+
22+
- `cookie_id`
23+
- `cookie_provider`
24+
- `cookie_name`
25+
- `cookie_lifetime`
26+
- `cookie_enforced_lifetime`
27+
- `cookie_title`
28+
- `cookie_description`
29+
30+
## Relationships
31+
32+
- `ConsentRequestVersion`

docs/development/models/working-with-models.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ These are the most commonly used models in ExpressionEngine. For a full list, se
3333
- [Channel Field Model](development/models/channel-field.md)
3434
- [Comment Model](development/models/comment.md)
3535
- [Comment Subscription Model](development/models/comment-subscription.md)
36+
- [Cookie Settings Model](development/models/cookie-settings.md)
3637
- [CP Log Model](development/models/cp-log.md)
3738
- [Developer Log Model](development/models/developer-log.md)
3839
- [Email Console Log Model](development/models/email-console-cache.md)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<!--
2+
This source file is part of the open source project
3+
ExpressionEngine User Guide (https://github.com/ExpressionEngine/ExpressionEngine-User-Guide)
4+
5+
@link https://expressionengine.com/
6+
@copyright Copyright (c) 2003-2023, Packet Tide, LLC (https://packettide.com)
7+
@license https://expressionengine.com/license Licensed under Apache License, Version 2.0
8+
-->
9+
10+
# Cookie Registry Service
11+
12+
[TOC]
13+
14+
For the cookies set in ExpressionEngine, site owners can set the cookie lifetime, title and description in [Cookie Settings](control-panel/settings/cookie-settings.md).
15+
16+
`CookieRegistry` is the underlying service that makes saving and using those settings possible.
17+
18+
NOTE: Normally, the add-ons that have their cookies properly [registered](development/addon-setup-php-file.html#cookies) do not need to call this service directly.
19+
20+
## Cookie Registry Constants
21+
22+
There are 4 different types of cookies that can be registered, and this class is defining a constant for each of those.
23+
24+
// Necessary cookies (0)
25+
ee('CookieRegistry)::NECESSARY;
26+
27+
//Functionality cookies (1)
28+
ee('CookieRegistry)::FUNCTIONALITY;
29+
30+
// Performance cookies (2)
31+
ee('CookieRegistry)::PERFORMANCE;
32+
33+
// Targeting cookies (4)
34+
ee('CookieRegistry)::TARGETING;
35+
36+
## Cookie Registry Methods
37+
38+
**class `ExpressionEngine\Service\Consent\CookieRegistry`**
39+
40+
### `registerNecessary($name)`
41+
42+
Register a cookie as Necessary
43+
44+
| Parameter | Type | Description |
45+
| ------------- | --------- | ----------------------------------------------------- |
46+
| \$name | `String` | Name of the cookie |
47+
48+
### `registerFunctionality($name)`
49+
50+
Register a cookie as Functionality
51+
52+
| Parameter | Type | Description |
53+
| ------------- | --------- | ----------------------------------------------------- |
54+
| \$name | `String` | Name of the cookie |
55+
56+
57+
### `registerPerformance($name)`
58+
59+
Register a cookie as Performance
60+
61+
| Parameter | Type | Description |
62+
| ------------- | --------- | ----------------------------------------------------- |
63+
| \$name | `String` | Name of the cookie |
64+
65+
66+
### `registerTargeting($name)`
67+
68+
Register a cookie as Targeting
69+
70+
| Parameter | Type | Description |
71+
| ------------- | --------- | ----------------------------------------------------- |
72+
| \$name | `String` | Name of the cookie |
73+
74+
75+
### `isNecessary($name)`
76+
77+
Check whether cookie is Necessary. Returns `true` or `false`
78+
79+
| Parameter | Type | Description |
80+
| ------------- | --------- | ----------------------------------------------------- |
81+
| \$name | `String` | Name of the cookie |
82+
83+
### `isFunctionality($name)`
84+
85+
Check whether cookie is Functionality. Returns `true` or `false`
86+
87+
| Parameter | Type | Description |
88+
| ------------- | --------- | ----------------------------------------------------- |
89+
| \$name | `String` | Name of the cookie |
90+
91+
### `isPerformance($name)`
92+
93+
Check whether cookie is Performance. Returns `true` or `false`
94+
95+
| Parameter | Type | Description |
96+
| ------------- | --------- | ----------------------------------------------------- |
97+
| \$name | `String` | Name of the cookie |
98+
99+
### `isTargeting($name)`
100+
101+
Check whether cookie is Targeting. Returns `true` or `false`
102+
103+
| Parameter | Type | Description |
104+
| ------------- | --------- | ----------------------------------------------------- |
105+
| \$name | `String` | Name of the cookie |
106+
107+
### `isRegistered($name)`
108+
109+
Check whether or not the cookie is in the registry. Returns `true` or `false`
110+
111+
| Parameter | Type | Description |
112+
| ------------- | --------- | ----------------------------------------------------- |
113+
| \$name | `String` | Name of the cookie |
114+
115+
### `getType($name)`
116+
117+
Get Cookie Type. Returns type int (from the list of constants) of registered cookie, `false` if cookie is not registered
118+
119+
| Parameter | Type | Description |
120+
| ------------- | --------- | ----------------------------------------------------- |
121+
| \$name | `String` | Name of the cookie |
122+
123+
### `loadCookiesSettings()`
124+
125+
Load settings of all cookies into memory
126+
127+
### `registerCookieSettings()`
128+
129+
Register settings for the given cookie into memory
130+
131+
| Parameter | Type | Description |
132+
| ------------- | ---------------- | -------------------------------------------- |
133+
| \$cookie | `CookieSetting` | Cookie object instance |
134+
135+
136+
### `getCookieSettings($name)`
137+
138+
Get lifetime for cookie to be set. Returns cookie lifetime in seconds, or `null`` if value provided in code should be used
139+
140+
| Parameter | Type | Description |
141+
| ------------- | --------- | ----------------------------------------------------- |
142+
| \$name | `String` | Name of the cookie |

docs/toc_sections/_advanced_usage_toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@
326326
href: development/services/consent.md
327327
- name: Cookie
328328
href: development/services/cookie.md
329+
- name: Cookie Registry
330+
href: development/services/cookie-registry.md
329331
- name: CSV Library
330332
href: development/services/csv.md
331333
- name: Encrypt Service
@@ -426,6 +428,8 @@
426428
href: development/models/comment.md
427429
- name: Comment Subscription Model
428430
href: development/models/comment-subscription.md
431+
- name: Cookie Settings Model
432+
href: development/models/cookie-settings.md
429433
- name: CP Log Model
430434
href: development/models/cp-log.md
431435
- name: Developer Log Model

0 commit comments

Comments
 (0)