|
| 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 | |
0 commit comments