setono/consent-contracts

与同意相关的通用抽象

v1.0.0 2023-02-21 07:18 UTC

This package is auto-updated.

Last update: 2024-09-18 08:22:10 UTC


README

Latest Version Software License Build Status Code Coverage

这个库作为处理库或应用程序中与同意相关实现的构建块。

安装

composer require setono/consent-contracts

用法

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

final class YourService
{
    private ConsentCheckerInterface $consentChecker;
    
    public function __construct(ConsentCheckerInterface $consentChecker)
    {
        $this->consentChecker = $consentChecker;    
    }
    
    public function __invoke()
    {
        if ($this->consentChecker->isGranted(Consents::CONSENT_MARKETING)) {
            // marketing consent is granted, and you can set your marketing related cookie ;)
        }
    }
}

默认同意检查器

此库还提供了两种 ConsentCheckerInterface 的实现,即 DenyAllConsentCheckerGrantAllConsentChecker。如果您未实现同意管理系统,可以使用这两个来提供默认同意。