Search by

setono / consent-contracts

loevgaard

Generic abstraction related to consent

Package info

github.com/Setono/consent-contracts

pkg:composer/setono/consent-contracts

Statistics

Installs: 81 446

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2024-12-17 13:41 UTC

This package is auto-updated.

Last update: 2026-09-21 10:49:10 UTC


README

Latest Version Software License Build Status Code Coverage

This library serves as a building block for handling consent related implementations in your library or application. It gives you a single interface to check against, so your code doesn't need to know which consent management platform (CMP) is in use.

Installation

composer require setono/consent-contracts

Usage

Depend on the ConsentCheckerInterface and ask it whether a given consent has been granted:

<?php
use Setono\Consent\ConsentCheckerInterface;
use Setono\Consent\DefaultConsents;

final class YourService
{
    public function __construct(private readonly ConsentCheckerInterface $consentChecker)
    {
    }

    public function __invoke(): void
    {
        if ($this->consentChecker->isGranted(DefaultConsents::CONSENT_MARKETING)) {
            // marketing consent is granted, and you can set your marketing related cookie ;)
        }
    }
}

Default consents

The DefaultConsents class holds the consent types most consent management platforms use:

Constant Value
DefaultConsents::CONSENT_FUNCTIONAL 'functional'
DefaultConsents::CONSENT_MARKETING 'marketing'
DefaultConsents::CONSENT_STATISTICAL 'statistical'

DefaultConsents::all() returns all of them. You are free to check for your own consent types too, since ConsentCheckerInterface::isGranted() accepts any string.

Note

The Consents class is deprecated since 1.1 and will be removed in 2.0. Use DefaultConsents instead.

Default consent checkers

This library also provides two implementations of the ConsentCheckerInterface, namely the DenyAllConsentChecker and GrantAllConsentChecker. You can use these two to provide default consents if a consent management system isn't implemented.