Skip to content

document cookie registry service and model #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/development/models/cookie-settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
lang: php
---

<!--
This source file is part of the open source project
ExpressionEngine User Guide (https://github.com/ExpressionEngine/ExpressionEngine-User-Guide)

@link https://expressionengine.com/
@copyright Copyright (c) 2003-2023, Packet Tide, LLC (https://packettide.com)
@license https://expressionengine.com/license Licensed under Apache License, Version 2.0
-->

# Cookie Settings Model

**class `ExpressionEngine\Model\Cookie\CookieSetting`**

[TOC]

## Properties

- `cookie_id`
- `cookie_provider`
- `cookie_name`
- `cookie_lifetime`
- `cookie_enforced_lifetime`
- `cookie_title`
- `cookie_description`

## Relationships

- `ConsentRequestVersion`
1 change: 1 addition & 0 deletions docs/development/models/working-with-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ These are the most commonly used models in ExpressionEngine. For a full list, se
- [Channel Field Model](development/models/channel-field.md)
- [Comment Model](development/models/comment.md)
- [Comment Subscription Model](development/models/comment-subscription.md)
- [Cookie Settings Model](development/models/cookie-settings.md)
- [CP Log Model](development/models/cp-log.md)
- [Developer Log Model](development/models/developer-log.md)
- [Email Console Log Model](development/models/email-console-cache.md)
Expand Down
142 changes: 142 additions & 0 deletions docs/development/services/cookie-registry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<!--
This source file is part of the open source project
ExpressionEngine User Guide (https://github.com/ExpressionEngine/ExpressionEngine-User-Guide)

@link https://expressionengine.com/
@copyright Copyright (c) 2003-2023, Packet Tide, LLC (https://packettide.com)
@license https://expressionengine.com/license Licensed under Apache License, Version 2.0
-->

# Cookie Registry Service

[TOC]

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).

`CookieRegistry` is the underlying service that makes saving and using those settings possible.

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.

## Cookie Registry Constants

There are 4 different types of cookies that can be registered, and this class is defining a constant for each of those.

// Necessary cookies (0)
ee('CookieRegistry)::NECESSARY;

//Functionality cookies (1)
ee('CookieRegistry)::FUNCTIONALITY;

// Performance cookies (2)
ee('CookieRegistry)::PERFORMANCE;

// Targeting cookies (4)
ee('CookieRegistry)::TARGETING;

## Cookie Registry Methods

**class `ExpressionEngine\Service\Consent\CookieRegistry`**

### `registerNecessary($name)`

Register a cookie as Necessary

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |

### `registerFunctionality($name)`

Register a cookie as Functionality

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |


### `registerPerformance($name)`

Register a cookie as Performance

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |


### `registerTargeting($name)`

Register a cookie as Targeting

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |


### `isNecessary($name)`

Check whether cookie is Necessary. Returns `true` or `false`

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |

### `isFunctionality($name)`

Check whether cookie is Functionality. Returns `true` or `false`

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |

### `isPerformance($name)`

Check whether cookie is Performance. Returns `true` or `false`

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |

### `isTargeting($name)`

Check whether cookie is Targeting. Returns `true` or `false`

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |

### `isRegistered($name)`

Check whether or not the cookie is in the registry. Returns `true` or `false`

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |

### `getType($name)`

Get Cookie Type. Returns type int (from the list of constants) of registered cookie, `false` if cookie is not registered

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |

### `loadCookiesSettings()`

Load settings of all cookies into memory

### `registerCookieSettings()`

Register settings for the given cookie into memory

| Parameter | Type | Description |
| ------------- | ---------------- | -------------------------------------------- |
| \$cookie | `CookieSetting` | Cookie object instance |


### `getCookieSettings($name)`

Get lifetime for cookie to be set. Returns cookie lifetime in seconds, or `null`` if value provided in code should be used

| Parameter | Type | Description |
| ------------- | --------- | ----------------------------------------------------- |
| \$name | `String` | Name of the cookie |
4 changes: 4 additions & 0 deletions docs/toc_sections/_advanced_usage_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@
href: development/services/consent.md
- name: Cookie
href: development/services/cookie.md
- name: Cookie Registry
href: development/services/cookie-registry.md
- name: CSV Library
href: development/services/csv.md
- name: Encrypt Service
Expand Down Expand Up @@ -426,6 +428,8 @@
href: development/models/comment.md
- name: Comment Subscription Model
href: development/models/comment-subscription.md
- name: Cookie Settings Model
href: development/models/cookie-settings.md
- name: CP Log Model
href: development/models/cp-log.md
- name: Developer Log Model
Expand Down