PHP code example of imliamxo / shush

1. Go to this page and download the library: Download imliamxo/shush 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/ */

    

imliamxo / shush example snippets


use ImLiaMxo\Shush\Facades\Shush;

Shush::check('Hello world');           // false
Shush::check('What the fuck');         // true
Shush::check('What the f*ck');         // true
Shush::check('What the f.u.c.k');      // true
Shush::check('What the fuuuck');       // true
Shush::check('No kurwa mać');          // true (Polish, if enabled)

Shush::censor('What the fuck');        // "What the ****"
Shush::clean($text);                   // censors or throws, per config

$hits = Shush::detect('Shit and kurwa');
// [
//   ['word' => 'shit', 'tier' => 'moderate', 'language' => 'en', 'match' => 'Shit'],
//   ['word' => 'kurwa', 'tier' => 'severe', 'language' => 'pl', 'match' => 'kurwa'],
// ]

// Global
'strictness' => 'strict',

// Runtime
Shush::setStrictness('relaxed');

// Per-route
Route::post('/kids', ...)->middleware('shush:strict');
Route::post('/forum', ...)->middleware('shush:relaxed');



namespace App\Normalisers;

use ImLiaMxo\Shush\Normalisers\BaseNormaliser;

class GermanNormaliser extends BaseNormaliser
{
    public function getLanguage(): string
    {
        return 'de';
    }

    protected function getExtraSubstitutions(): array
    {
        return [
            'ä' => 'a', 'ö' => 'o', 'ü' => 'u', 'ß' => 'ss',
        ];
    }

    protected function stripDiacritics(string $text): string
    {
        return strtr($text, [
            'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'ß' => 'ss',
            'Ä' => 'ae', 'Ö' => 'oe', 'Ü' => 'ue',
        ]);
    }

    protected function getDiacriticAlternates(string $char): array
    {
        return match ($char) {
            'a' => ['ä'],
            'o' => ['ö'],
            'u' => ['ü'],
            default => [],
        };
    }
}

'normalisers' => [
    'de' => \App\Normalisers\GermanNormaliser::class,
],

Shush::registerNormaliser('de', \App\Normalisers\GermanNormaliser::class);

// Remove a built-in whitelist entry if needed
Shush::disallow(['cocktail']);

// Add to whitelist
Shush::allow(['mycustomword']);


return [
    'severe' => ['schlimmsteswort'],
    'moderate' => ['scheiße', 'arschloch', 'wichser'],
    'mild' => ['mist', 'verdammt', 'kacke'],
];

'languages' => ['en', 'pl', 'de'],

Shush::censor('What the fuck');     // "What the ****"
Shush::setMask('#')->censor('...');  // "What the ####"

// Full-word replacement (config: mask_behaviour = 'full')
// → "What the [REDACTED]"

try {
    Shush::clean($input);
} catch (ProfanityDetectedException $e) {
    $e->getDetectedWords(); // ['fuck']
}

// bootstrap/app.php (Laravel 11+)
->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'shush' => \ImLiaMxo\Shush\Middleware\ShushMiddleware::class,
    ]);
})

Route::post('/comment', ...)->middleware('shush');
Route::post('/kids', ...)->middleware('shush:strict');
Route::post('/forum', ...)->middleware('shush:relaxed');

use ImLiaMxo\Shush\Rules\NoProfanity;

$request->validate([
    'comment' => ['

Shush::setStrictness('strict');
Shush::setMode('block');
Shush::setMask('#');
Shush::setNormalise(false);

Shush::addWords(['customword']);                              // moderate, first language
Shush::addWords(['slur'], 'severe', 'en');                    // specific tier + language
Shush::allow(['damn']);                                        // whitelist
Shush::disallow(['cocktail']);                                  // un-whitelist

Shush::registerNormaliser('de', GermanNormaliser::class);       // custom normaliser

Shush::getWords();                    // all dictionaries
Shush::getWords('severe', 'en');      // English severe words
Shush::getActiveWords();              // words at current strictness
Shush::getWhitelist();                // full whitelist
Shush::getStrictness();               // 'relaxed' | 'normal' | 'strict'
Shush::getLanguages();                // ['en', 'pl']
bash
php artisan vendor:publish --tag=shush-config
php artisan vendor:publish --tag=shush-dictionaries   # optional

resources/shush/dictionaries/
├── en/
│   └── words.php
├── pl/
│   └── words.php
└── de/
    ├── insults.php
    └── slurs.php

src/
├── Shush.php                          # Core engine
├── ShushServiceProvider.php           # Laravel auto-discovery
├── Facades/Shush.php                  # Facade
├── Exceptions/
│   └── ProfanityDetectedException.php
├── Middleware/
│   └── ShushMiddleware.php            # Route middleware
├── Rules/
│   └── NoProfanity.php                # Validation rule
├── Normalisers/
│   ├── NormaliserInterface.php        # Contract
│   ├── BaseNormaliser.php             # Shared logic
│   ├── NormaliserFactory.php          # Registry / factory
│   ├── EnglishNormaliser.php          # English-specific
│   └── PolishNormaliser.php           # Polish-specific
└── Dictionaries/
    ├── en/
    │   └── words.php                  # ~350 entries, 3 tiers
    └── pl/
        └── words.php                  # ~450 entries, 3 tiers