phpnomad / privacy
1.0.0
2024-12-18 17:21 UTC
Requires (Dev)
- phpnomad/tests: ^0.1.0
This package is auto-updated.
Last update: 2026-04-15 08:19:38 UTC
README
phpnomad/privacy defines a small contract for answering a single question: can the current request be tracked? Application code that emits analytics, user-identifying events, or logs checks the bound strategy first, so consent policy lives in one place instead of being scattered across every call site.
Installation
composer require phpnomad/privacy
Overview
- Ships a single interface,
TrackingPermissionStrategy, with one method:canTrack(): bool. - Lets you centralize tracking consent in one replaceable strategy instead of repeating checks across analytics, event, and logging code.
- Stays platform-agnostic. The strategy you bind decides whether consent comes from a DNT header, a cookie banner, login state, or application-specific rules.
- Integration packages such as
phpnomad/wordpress-integrationship default strategies you can replace by binding your own in an initializer. - Has no runtime dependencies. It's a contract-only package that sits between your tracking code and whatever policy you choose to enforce.
Usage
Implement the interface in your application:
<?php namespace MyApp\Strategies; use PHPNomad\Privacy\Interfaces\TrackingPermissionStrategy; class CookieConsentTrackingStrategy implements TrackingPermissionStrategy { public function canTrack(): bool { return isset($_COOKIE['consent']) && $_COOKIE['consent'] === 'accepted'; } }
Bind it in your initializer alongside your other strategies:
<?php namespace MyApp; use MyApp\Strategies\CookieConsentTrackingStrategy; use PHPNomad\Loader\Interfaces\HasClassDefinitions; use PHPNomad\Privacy\Interfaces\TrackingPermissionStrategy; class AppInitializer implements HasClassDefinitions { public function getClassDefinitions(): array { return [ CookieConsentTrackingStrategy::class => TrackingPermissionStrategy::class, ]; } }
Then any code that emits tracking-sensitive output can ask the bound strategy before doing so.
Documentation
Full PHPNomad documentation lives at phpnomad.com.
License
MIT. See LICENSE.txt.