brandoriented/doctrine-encryption-bundle
Pros:
Cons:
doctrine/orm + doctrine/dbal for Laravel).retrieved, saved) to mirror Doctrine’s prePersist/preUpdate.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| PHP 8.x Compatibility | High | Test with PHP 8.1+; patch if needed. |
| Doctrine 3.x+ Support | High | Verify compatibility or fork if broken. |
| Security Vulnerabilities | Critical | Audit encryption logic; upgrade dependencies. |
| Performance Overhead | Medium | Benchmark prePersist/preUpdate hooks. |
| Key Management | High | Replace YAML keys with .env or KMS. |
| Lack of Laravel Support | High | Build adapters or use Symfony components directly. |
spatie/laravel-encryption).Target Stack:
doctrine/dbal and doctrine/orm packages) for Doctrine compatibility.symfony/dependency-injection, symfony/config) for bundle integration.Compatibility Matrix:
| Component | Laravel Native | Doctrine Bundle | Workaround Needed? |
|---|---|---|---|
| Encryption Logic | ❌ | ✅ | Extract class or use Symfony |
| Entity Annotations | ❌ (Eloquent) | ✅ | Custom trait/event system |
| Twig Decryption | ✅ (via filters) | ✅ | Adapt bundle’s Twig extension |
| Doctrine Events | ❌ | ✅ | Eloquent events or hybrid |
Phase 1: Proof of Concept (PoC)
doctrine/orm and doctrine/dbal in Laravel.Phase 2: Hybrid Integration
DBAL.@Encrypted behavior:
trait Encryptable {
protected static function booted() {
static::saving(function ($model) {
$model->encryptSensitiveFields();
});
static::retrieved(function ($model) {
$model->decryptSensitiveFields();
});
}
}
Phase 3: Full Adoption
toArray() or API responses).retrieved event fires after hydration, unlike Doctrine’s postLoad. This may cause N+1 decryption queries if not optimized.{{ user.firstname|app.decryptFilter }} {# Custom filter #}
.env:
# config/doctrine_encryption.yaml
doctrine_encryption:
key: '%env(ENCRYPTION_KEY)%'
iv: '%env(ENCRYPTION_IV)%'
@Encrypted equivalent for Eloquent (Phase 2 Option B).prePersist/preUpdate).[REDACTED] if decryption fails).{% for user in users %}{{ user.firstname|decrypt }}{% endfor %}).How can I help you explore Laravel packages today?