jeffersongoncalves / laravel-privacy
Shared privacy engine for the LGPD, GDPR, CCPA, US state and Quebec Law 25 suites: personal data declarations, inventory, anonymization, k-anonymity, retention with tombstones, hash-chained audit log and consent ledger.
Package info
github.com/jeffersongoncalves/laravel-privacy
pkg:composer/jeffersongoncalves/laravel-privacy
Requires
- php: ^8.2
- illuminate/console: ^12.0|^13.0
- illuminate/contracts: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- illuminate/validation: ^12.0|^13.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.24
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The engine shared by the privacy suites for Laravel. You don't install it on its own: install the suite of your law, which pulls it in.
| Suite | Law |
|---|---|
| laravel-lgpd | Brazil: LGPD (Lei 13.709/2018) |
| laravel-gdpr | EU: GDPR (Regulation (EU) 2016/679) |
| laravel-ccpa | California: CCPA/CPRA |
| laravel-us-privacy | The other US state privacy laws |
| laravel-quebec | Quebec: Law 25 |
What it holds
The parts that work the same under every law live here, tested once:
| Part | Classes |
|---|---|
| Personal data declarations | Attributes\PersonalDataAttribute, Contracts\HasPersonalData, Concerns\InteractsWithPersonalData, Contracts\AnonymizeStrategy + Concerns\AppliesAnonymizeStrategy |
| Inventory and k-anonymity | Privacy, Generalize, Commands\InventoryCommand, Commands\KAnonymityCommand |
| Retention | Retention\RetentionManager, Retention\Tombstone, Retention\Listeners\RecordTombstones, the retention commands |
| Audit log | AuditLog\AuditLogger, AuditLog\AuditLog, AuditLog\Concerns\AuditsPersonalData, AuditLog\Commands\VerifyCommand |
| Consent ledger | Consent\ConsentManager, Consent\ConsentRecord, Consent\Concerns\HasConsents, Consent\ConsentController |
What depends on the law stays in each suite: the #[PersonalData] attribute and its enums (data categories, legal
bases, flags such as sold or outsideQuebec), the requests and their deadlines, incidents, vendors, minors, notices.
Suites side by side
Each suite subclasses these classes and names its own config, tables, attribute and events. A model declared with
JeffersonGoncalves\Gdpr\Attributes\PersonalData is only seen by the GDPR suite, and its anonymization fires
JeffersonGoncalves\Gdpr\Events\PersonalDataAnonymized, which only the GDPR retention and audit log listen to. So
an app serving Brazil and Europe can install the LGPD and GDPR suites together.
Building a suite
A suite's classes are thin subclasses. The main class names its config file:
use JeffersonGoncalves\Privacy\Privacy; class Gdpr extends Privacy { protected string $config = 'gdpr'; // gdpr.models, gdpr.hash_key protected string $contract = HasPersonalData::class; // the suite's contract (extends the core one) }
The attribute extends PersonalDataAttribute and fills column, retention and anonymize. Property types are
invariant, so it takes its AnonymizeStrategy enum as a plain parameter and assigns it:
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class PersonalData extends PersonalDataAttribute { public function __construct( public string $column, public DataCategory $category = DataCategory::Personal, public ?string $retention = null, AnonymizeStrategy $anonymize = AnonymizeStrategy::Nullify, ) { $this->anonymize = $anonymize; } public function toArray(): array { /* the inventory row */ } } enum AnonymizeStrategy: string implements \JeffersonGoncalves\Privacy\Contracts\AnonymizeStrategy { use \JeffersonGoncalves\Privacy\Concerns\AppliesAnonymizeStrategy; const HASH_KEY = 'gdpr.hash_key'; case Nullify = 'nullify'; case Hash = 'hash'; case Mask = 'mask'; case Keep = 'keep'; }
The traits name the suite's attribute, event, logger or manager through abstract static methods
(personalDataAttribute(), personalDataAnonymizedEvent(), auditLogger(), consentManager(),
consentRecordModel()), and the engine classes take their config key and models as properties
(RetentionManager::$config / $tombstone, AuditLogger::$config / $model, ConsentManager::$config / $model /
$event, ConsentRecord::$actionEnum). See any of the suites above for the full set.
Testing
composer test
Changelog
See CHANGELOG.
License
The MIT License (MIT). See License File.
