setono/consent-bundle

一个将同意合约集成的 Symfony 扩展包

安装数: 48 102

依赖: 4

建议者: 0

安全: 0

星标: 2

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v1.1.0 2024-04-09 07:00 UTC

This package is auto-updated.

Last update: 2024-09-09 07:57:43 UTC


README

Latest Version Software License Build Status Code Coverage Mutation testing

此扩展包将 同意合约 集成到 Symfony。

安装

composer require setono/consent-bundle

如果您使用 Symfony Flex,则会自动安装并启用此插件。如果不是,请手动将扩展包添加到 bundles.php

配置

默认配置将所有(默认)同意(营销、偏好和统计)设置为 false。如果您想更改这些默认值,可以轻松实现

# config/packages/setono_consent.yaml

setono_consent:
    consents:
        marketing: true
        preferences: true
        statistics: true
        random_consent: true # you can easily add your own consents

上述配置将有效地将所有权限的默认同意更改为 true

使用方法

此扩展包提供了一个 StaticConsentChecker,它使用上述 consents 数组作为输入。然后,您可以自动注入 ConsentCheckerInterface 并检查是否授予了同意

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

final class YourMarketingTrackingService
{
    private ConsentCheckerInterface $consentChecker;
    
    public function __construct(ConsentCheckerInterface $consentChecker) {
        $this->consentChecker = $consentChecker;
    }
    
    public function track(): void
    {
        if(!$this->consentChecker->isGranted(Consents::CONSENT_MARKETING)) {
            return;
        }
        
        // do your marketing tracking
    }
}