setono / consent-bundle
A Symfony bundle that integrates the consent contracts
Installs: 49 419
Dependents: 4
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
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
This bundle integrates the consent contracts into Symfony.
Installation
composer require setono/consent-bundle
This installs and enables the plugin automatically if you're using Symfony Flex. If not, add the bundle manually
to bundles.php
.
Configuration
The default configuration has all (default) consents (marketing, preferences, and statistics) set to false
. If you want to
change these defaults, you can easily do so:
# config/packages/setono_consent.yaml setono_consent: consents: marketing: true preferences: true statistics: true random_consent: true # you can easily add your own consents
The above configuration will effectively change the default consent to true
for all permissions.
Usage
The bundle provides a StaticConsentChecker
that uses the above consents
array as an input.
You can then autowire the ConsentCheckerInterface
and check for a granted consent:
<?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 } }