spatie/email-concealer
Replaces email domains in any string (e.g., dumps) to safely use production data locally without real addresses. Create a Concealer and call conceal(): info@spatie.be becomes info@example.com. Simple, fast, and handy for anonymizing text.
Concealer) with a fluent API (create() + conceal()). Minimal boilerplate for basic use.setReplacementDomain()), allowing adaptation to org-specific needs (e.g., user@example.org).spatie/array-to-xml if used internally).fakerphp/faker (for synthetic data) or custom regex if obfuscation needs evolve.hash('sha256', $email)).phpunit/phpunit@^9 and php:8.2 in CI early.example.com to stage-123.example.com per environment.// app/Http/Middleware/ConcealEmails.php
public function handle($request, Closure $next) {
$response = $next($request);
return $response->setContent(
Concealer::create()->conceal($response->content())
);
}
Concealer instance for reuse.// app/Console/Commands/AnonymizeDump.php
Concealer::create()->conceal(file_get_contents('dump.sql'));
@conceal helper for views.
// app/Providers/BladeServiceProvider.php
Blade::directive('conceal', fn($email) => "<?php echo \\Spatie\\EmailConcealer\\Concealer::create()->conceal($email); ?>");
user+tag@sub.domain.com, PGP addresses, or non-standard TLDs.composer.json:
"require": {
"spatie/email-concealer": "^1.0"
}
Concealer via traits or decorators if default behavior is insufficient.Concealer::setReplacementDomain(env('APP_ENV') === 'staging' ? 'stage.example.com' : 'fake.com').spatie/macroable (for fluent methods), which is also unmaintained.// User.php
public function getEmailAttribute($value) {
return Concealer::create()->conceal($value);
}
// app/Support/EmailConcealer.php
class Concealer {
public static function conceal(string $string): string {
return preg_replace('/([\w\.-]+)@([\w\.-]+)/', '$1@fake.com', $string);
}
}
spatie/macroable for vulnerabilities (though unlikely given its niche use).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| PHP version incompatibility | Integration breaks | Use a polyfill or fork. |
Regex edge cases (e.g., user@[IP]) |
Incomplete obfuscation | Pre-process with filter_var($email, FILTER_VALIDATE_EMAIL). |
| Dependency vulnerabilities | Security risk | Isolate in a container/Docker image. |
| Data corruption | Real emails leaked in production | Never use in prod; restrict to staging. |
How can I help you explore Laravel packages today?