Consent
in package
A consent holds all information of a single given consent. In other words, it allows to parse the current consent which is written in the current cookie and additionally, allows to modify it.
Table of Contents
Constants
- COOKIE_VALUE_REGEXP = '/^(?<createdAt>\\d+)?:?(?<uuids>(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}[,]?)+):(?<revisionHash>[a-f0-9]{32}):(?<json>.*)$/'
- Regexp to validate and parse the cookie value with named capture groups.
Properties
- $buttonClicked : string
- The clicked button.
- $cookieConsentManagement : CookieConsentManagement
- See `CookieConsentManagement`.
- $created : int|string
- UNIX timestamp or ISO string of the consent creation time.
- $currentCookies : array<string|int, mixed>
- The current cookies which are set on the client.
- $decision : array<string|int, mixed>
- The decision for this consent.
- $gcmConsent : array<string|int, string>
- The Google Consent Mode consent purposes for this consent.
- $previousUuids : array<string|int, string>
- The previous UUIDs for this consent.
- $revisionHash : string
- The revision hash for this consent.
- $tcfString : string
- The TCF string for this consent.
- $uuid : string
- The UUID for this consent.
Methods
- __construct() : mixed
- C'tor.
- commit() : mixed
- A user has given a new consent, let's commit it.
- getButtonClicked() : mixed
- Getter.
- getCookieConsentManagement() : mixed
- Getter.
- getCreated() : mixed
- Getter.
- getDecision() : mixed
- Getter.
- getGcmConsent() : mixed
- Getter.
- getPreviousUuids() : mixed
- Getter.
- getRevisionHash() : mixed
- Getter.
- getTcfString() : mixed
- Getter.
- getUuid() : mixed
- Getter.
- hasConsent() : mixed
- Check if a given technical information (e.g. HTTP Cookie, LocalStorage, ...) has a consent:
- optInOrOptOutExistingDecision() : mixed
- Apply a new decision (e.g. opt-out a single cookie in a cookie group) to a new consent. This is e.g. helpful if you are providing a custom bypass (e.g. Geolocation) and want to overtake an opt-out / opt-in from the previous consent.
- sanitizeDecision() : array<string|int, mixed>
- Validate a passed decision or create a decision.
- setCurrentCookies() : mixed
- Setter.
- getCookieExpire() : mixed
- Calculate the cookie expiration date.
- handleConsentForwarding() : mixed
- When commiting a new transaction, automatically handle the response so the client can forward the consent.
- handleCountryBypass() : mixed
- When country bypass is active, automatically calculate the user country so it can be saved to the database.
- handleGcmConsent() : mixed
- When Google Consent Mode is active, save the consent mode purposes in an own cookie.
- handleTcfString() : mixed
- When TCF is active, save the TCF string.
- invalidateCookies() : mixed
- A cookie got updated to `currentCookies`, so we need to reflect the changes to the current consent.
- parseDecisionFromCookieValue() : array<string|int, mixed>
- Parse a consent from a given cookie value. The result will hold the unique user id and the accepted revision hash.
Constants
COOKIE_VALUE_REGEXP
Regexp to validate and parse the cookie value with named capture groups.
public
mixed
COOKIE_VALUE_REGEXP
= '/^(?<createdAt>\\d+)?:?(?<uuids>(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}[,]?)+):(?<revisionHash>[a-f0-9]{32}):(?<json>.*)$/'
Tags
Properties
$buttonClicked
The clicked button.
private
string
$buttonClicked
$cookieConsentManagement
See `CookieConsentManagement`.
private
CookieConsentManagement
$cookieConsentManagement
$created
UNIX timestamp or ISO string of the consent creation time.
private
int|string
$created
$currentCookies
The current cookies which are set on the client.
private
array<string|int, mixed>
$currentCookies
= []
$decision
The decision for this consent.
private
array<string|int, mixed>
$decision
$gcmConsent
The Google Consent Mode consent purposes for this consent.
private
array<string|int, string>
$gcmConsent
$previousUuids
The previous UUIDs for this consent.
private
array<string|int, string>
$previousUuids
= []
$revisionHash
The revision hash for this consent.
private
string
$revisionHash
$tcfString
The TCF string for this consent.
private
string
$tcfString
$uuid
The UUID for this consent.
private
string
$uuid
Methods
__construct()
C'tor.
public
__construct(CookieConsentManagement $cookieConsentManagement) : mixed
Parameters
- $cookieConsentManagement : CookieConsentManagement
commit()
A user has given a new consent, let's commit it.
public
commit(Transaction $transaction, callable $persistDatabase) : mixed
Parameters
- $transaction : Transaction
- $persistDatabase : callable
-
A function which does not get any arguments but needs to return a persisted ID on the database
getButtonClicked()
Getter.
public
getButtonClicked() : mixed
Tags
getCookieConsentManagement()
Getter.
public
getCookieConsentManagement() : mixed
Tags
getCreated()
Getter.
public
getCreated() : mixed
Tags
getDecision()
Getter.
public
getDecision() : mixed
Tags
getGcmConsent()
Getter.
public
getGcmConsent() : mixed
Tags
getPreviousUuids()
Getter.
public
getPreviousUuids() : mixed
Tags
getRevisionHash()
Getter.
public
getRevisionHash() : mixed
Tags
getTcfString()
Getter.
public
getTcfString() : mixed
Tags
getUuid()
Getter.
public
getUuid() : mixed
Tags
hasConsent()
Check if a given technical information (e.g. HTTP Cookie, LocalStorage, ...) has a consent:
public
hasConsent(string|int $typeOrId[, string $name = null ][, string $host = null ]) : mixed
- When a technical information exists in defined cookies, the Promise is only resolved after given consent
- When no technical information exists, the Promise is immediate resolved
Attention: Do not use this function if you can get the conditional consent into your frontend
coding and use instead the window.consentApi
!
Parameters
- $typeOrId : string|int
- $name : string = null
- $host : string = null
optInOrOptOutExistingDecision()
Apply a new decision (e.g. opt-out a single cookie in a cookie group) to a new consent. This is e.g. helpful if you are providing a custom bypass (e.g. Geolocation) and want to overtake an opt-out / opt-in from the previous consent.
public
optInOrOptOutExistingDecision(array<string|int, mixed>|string $previousDecision, array<string|int, mixed>|string $newDecision, string $overtake) : mixed
Parameters
- $previousDecision : array<string|int, mixed>|string
- $newDecision : array<string|int, mixed>|string
- $overtake : string
-
Can be
optIn
oroptOut
sanitizeDecision()
Validate a passed decision or create a decision.
public
sanitizeDecision(array<string|int, mixed>|string $consent) : array<string|int, mixed>
Parameters
- $consent : array<string|int, mixed>|string
-
A decision array,
all
oressentials
which creates a decision array of all available services
Return values
array<string|int, mixed>setCurrentCookies()
Setter.
public
setCurrentCookies(array<string|int, mixed> $currentCookies) : mixed
Parameters
- $currentCookies : array<string|int, mixed>
getCookieExpire()
Calculate the cookie expiration date.
protected
getCookieExpire() : mixed
handleConsentForwarding()
When commiting a new transaction, automatically handle the response so the client can forward the consent.
protected
handleConsentForwarding(Transaction $transaction, int $persistId) : mixed
Parameters
- $transaction : Transaction
- $persistId : int
handleCountryBypass()
When country bypass is active, automatically calculate the user country so it can be saved to the database.
protected
handleCountryBypass(Transaction $transaction) : mixed
Parameters
- $transaction : Transaction
handleGcmConsent()
When Google Consent Mode is active, save the consent mode purposes in an own cookie.
protected
handleGcmConsent(Transaction $transaction) : mixed
Parameters
- $transaction : Transaction
handleTcfString()
When TCF is active, save the TCF string.
protected
handleTcfString(Transaction $transaction) : mixed
Parameters
- $transaction : Transaction
invalidateCookies()
A cookie got updated to `currentCookies`, so we need to reflect the changes to the current consent.
protected
invalidateCookies(string $cookieKey, string $cookieValue) : mixed
Parameters
- $cookieKey : string
- $cookieValue : string
parseDecisionFromCookieValue()
Parse a consent from a given cookie value. The result will hold the unique user id and the accepted revision hash.
protected
parseDecisionFromCookieValue(string $value) : array<string|int, mixed>
Parameters
- $value : string