You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add non-English severity maps and result caching
Add severity maps (mild/moderate/extreme) for Spanish, French, and German
so withSeverity() filtering works correctly for all languages instead of
defaulting everything to High.
Implement result caching in PendingCheck — check() results are cached by
a hash of all parameters (text, driver, language, severity, allow/block
lists, mask strategy). CallbackMask bypasses cache since closures can't
serialize. Add Result::fromArray() for deserialization, extend
Dictionary::clearCache() to also clear result cache, and add
cache.results config toggle.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@@ -160,6 +165,31 @@ The phonetic driver uses `metaphone()` + Levenshtein distance to catch words tha
160
165
161
166
Configure sensitivity in `config/blasp.php` under `drivers.phonetic`. A curated false-positive list prevents common words like "fork", "duck", and "beach" from being flagged.
162
167
168
+
### Pipeline Driver
169
+
170
+
The pipeline driver chains multiple drivers together so a single `check()` call runs all of them. It uses **union merge** semantics — text is flagged if **any** driver finds a match.
171
+
172
+
```php
173
+
// Config-based: set 'default' => 'pipeline' or use driver('pipeline')
174
+
Blasp::driver('pipeline')->check('phuck this sh1t');
175
+
176
+
// Ad-hoc: pick drivers on the fly (no config needed)
177
+
Blasp::pipeline('regex', 'phonetic')->check('phuck this sh1t');
When multiple drivers detect the same word at the same position, duplicates are removed — only the longest match is kept. Masks are applied from the merged result, and the score is recalculated across all matches.
182
+
183
+
Configure the default sub-drivers in `config/blasp.php`:
184
+
185
+
```php
186
+
'drivers' => [
187
+
'pipeline' => [
188
+
'drivers' => ['regex', 'phonetic'], // Drivers to chain
189
+
],
190
+
],
191
+
```
192
+
163
193
## Eloquent Integration
164
194
165
195
The `Blaspable` trait automatically checks model attributes during save:
@@ -335,7 +365,7 @@ Full `config/blasp.php` reference:
'language' => env('BLASP_LANGUAGE', 'english'), // Default language
340
370
'mask' => '*', // Default mask character
341
371
'severity' => 'mild', // Minimum severity
@@ -345,6 +375,7 @@ return [
345
375
'enabled' => true,
346
376
'driver' => env('BLASP_CACHE_DRIVER'),
347
377
'ttl' => 86400,
378
+
'results' => true, // Cache check() results by content hash
348
379
],
349
380
350
381
'middleware' => [
@@ -359,6 +390,9 @@ return [
359
390
],
360
391
361
392
'drivers' => [
393
+
'pipeline' => [
394
+
'drivers' => ['regex', 'phonetic'], // Sub-drivers to chain
395
+
],
362
396
'phonetic' => [
363
397
'phonemes' => 4, // metaphone code length (2-8)
364
398
'min_word_length' => 3, // skip short words
@@ -402,6 +436,41 @@ Blasp::extend('my-driver', fn($app) => new MyDriver());
402
436
Blasp::driver('my-driver')->check($text);
403
437
```
404
438
439
+
## Caching
440
+
441
+
Blasp caches `check()` results by default. When the same text is checked with the same configuration (language, driver, severity, allow/block lists), the cached result is returned instantly.
442
+
443
+
```php
444
+
// First call — runs full analysis, caches result
445
+
$result = Blasp::check('some text');
446
+
447
+
// Second call — returns cached result
448
+
$result = Blasp::check('some text');
449
+
```
450
+
451
+
Configure caching in `config/blasp.php`:
452
+
453
+
```php
454
+
'cache' => [
455
+
'enabled' => true, // Master switch for all caching
0 commit comments