1. Go to this page and download the library: Download blaspsoft/blasp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
blaspsoft / blasp example snippets
use Blaspsoft\Blasp\Facades\Blasp;
$result = Blasp::check('This is a fucking sentence');
$result->isOffensive(); // true
$result->clean(); // "This is a ******* sentence"
$result->original(); // "This is a fucking sentence"
$result->score(); // 30
$result->count(); // 1
$result->uniqueWords(); // ['fucking']
$result->severity(); // Severity::High
// Config-based: set 'default' => 'pipeline' or use driver('pipeline')
Blasp::driver('pipeline')->check('phuck this sh1t');
// Ad-hoc: pick drivers on the fly (no config needed)
Blasp::pipeline('regex', 'phonetic')->check('phuck this sh1t');
Blasp::pipeline('regex', 'pattern', 'phonetic')->check($text);
use Blaspsoft\Blasp\Events\ModelProfanityDetected;
Event::listen(ModelProfanityDetected::class, function ($event) {
$event->model; // The model instance
$event->attribute; // Which attribute had profanity
$event->result; // Result instance
});
// Using the short alias (recommended)
Route::post('/comment', CommentController::class)
->middleware('blasp');
// With parameters: action, severity
Route::post('/comment', CommentController::class)
->middleware('blasp:sanitize,mild');
// Or using the class directly
use Blaspsoft\Blasp\Middleware\CheckProfanity;
Route::post('/comment', CommentController::class)
->middleware(CheckProfanity::class);
return [
'default' => env('BLASP_DRIVER', 'regex'), // 'regex' | 'pattern' | 'phonetic' | 'pipeline'
'language' => env('BLASP_LANGUAGE', 'english'), // Default language
'mask' => '*', // Default mask character
'severity' => 'mild', // Minimum severity
'events' => false, // Fire ProfanityDetected events
'cache' => [
'enabled' => true,
'driver' => env('BLASP_CACHE_DRIVER'),
'ttl' => 86400,
'results' => true, // Cache check() results by content hash
],
'middleware' => [
'action' => 'reject',
'fields' => ['*'],
'except' => ['password', 'email', '_token'],
'severity' => 'mild',
],
'model' => [
'mode' => env('BLASP_MODEL_MODE', 'sanitize'), // 'sanitize' | 'reject'
],
'drivers' => [
'pipeline' => [
'drivers' => ['regex', 'phonetic'], // Sub-drivers to chain
],
'phonetic' => [
'phonemes' => 4, // metaphone code length (2-8)
'min_word_length' => 3, // skip short words
'max_distance_ratio' => 0.6, // levenshtein threshold (0.3-0.8)
'supported_languages' => ['english'], // metaphone is English-oriented
'false_positives' => ['fork', '...'], // never flag these words
],
],
'allow' => [], // Global allow-list
'block' => [], // Global block-list
'separators' => [...], // Characters treated as separators
'substitutions' => [...], // Character leet-speak mappings
'false_positives' => [...], // Words that should never be flagged
];
use Blaspsoft\Blasp\Core\Contracts\DriverInterface;
use Blaspsoft\Blasp\Core\Result;
use Blaspsoft\Blasp\Core\Dictionary;
use Blaspsoft\Blasp\Core\Contracts\MaskStrategyInterface;
class MyDriver implements DriverInterface
{
public function detect(string $text, Dictionary $dictionary, MaskStrategyInterface $mask, array $options = []): Result
{
// Your detection logic
}
}
// Register in a service provider
Blasp::extend('my-driver', fn($app) => new MyDriver());
// Use it
Blasp::driver('my-driver')->check($text);
// First call — runs full analysis, caches result
$result = Blasp::check('some text');
// Second call — returns cached result
$result = Blasp::check('some text');