setono / consent-bundle
一个将同意合约集成的 Symfony 扩展包
v1.1.0
2024-04-09 07:00 UTC
Requires
- php: >=8.1
- setono/consent-contracts: ^1.0
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/http-foundation: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- infection/infection: ^0.27.11
- matthiasnoback/symfony-config-test: ^4.3 || ^5.1
- matthiasnoback/symfony-dependency-injection-test: ^4.3 || ^5.1
- nyholm/symfony-bundle-test: ^3.0
- phpunit/phpunit: ^9.6
- psalm/plugin-phpunit: ^0.19
- psalm/plugin-symfony: ^5.1
- setono/code-quality-pack: ^2.7
README
此扩展包将 同意合约 集成到 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 } }