Skip to content

Repository files navigation

Abstraction for consent related implementations

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.

About

Abstraction for consent related implementations

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages