Skip to content

Repository files navigation

Symfony Consent Bundle

Latest VersionSoftware LicenseBuild StatusCode CoverageMutation testing

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

Consents

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.yamlsetono_consent:
consents:
marketing: truepreferences: truestatistics: truerandom_consent: true # you can easily add your own consents

The above configuration will effectively change the default consent to true for all permissions.

Consent checker

If you want to use a different consent checker, you can easily do so by implementing the ConsentCheckerInterface and setting your own service id as the consent checker:

# config/packages/setono_consent.yamlsetono_consent:
consent_checker: <your service id>

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:

<?phpuseSetono\Consent\Consents;
useSetono\Consent\ConsentCheckerInterface;
finalclass YourMarketingTrackingService
{
privateConsentCheckerInterface$consentChecker;
publicfunction__construct(ConsentCheckerInterface$consentChecker) {
$this->consentChecker = $consentChecker;
}
publicfunctiontrack(): void
{
if(!$this->consentChecker->isGranted(Consents::CONSENT_MARKETING)) {
return;
}
// do your marketing tracking
}
}

About

Integrate consent contracts into Symfony. Makes it a breeze to handle consents in Symfony bundles and applications

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages