承接 jonpurvis/squeaky 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jonpurvis/squeaky

Composer 安装命令:

composer require jonpurvis/squeaky

包简介

A Laravel Validation Rule to Help Catch Profanity.

README 文档

README

Squeaky

A Laravel Validation Rule that helps catch profanity in your application.

Tests GitHub last commit Packagist PHP Version GitHub issues GitHub Packagist Downloads

Introduction

Squeaky (short for Squeaky Clean) is a Laravel validation rule that you can add your Laravel application, to ensure any user submitted input such as a name or biography, is free of profanity and therefore, clean. Just add new Clean() to your rules and you're good to go!

Squeaky is powered by Pest Profanity Plugin, which is a PestPHP Plugin that does the same thing, but for code. By utilising the profanity in that package, Squeaky is powerful from the get-go and provides support for numerous locales, not just English.

Installation

To install Squeaky, you can run the following command in your project's root:

composer require jonpurvis/squeaky

After installation, you can publish the configuration file to customize the package behavior:

php artisan vendor:publish --provider="JonPurvis\Squeaky\SqueakyServiceProvider"

This will create a config/squeaky.php file in your application where you can configure custom blocked and allowed words.

Examples

Let's take a look at how Squeaky works. As it's a Laravel Validation rule, there's not really that much to it. You would use it in the same way you would use a custom validation rule you've added yourself.

Let's take the following scenario where we have a form that allows a user to enter their name, email and bio:

use App\Models\User;
use Illuminate\Validation\Rule;
use JonPurvis\Squeaky\Rules\Clean;

return [
    'name' => ['required', 'string', 'max:255', new Clean],
    'email' => [
        'required',
        'string',
        'lowercase',
        'email',
        'max:255',
        Rule::unique(User::class)->ignore($this->user()->id),
    ],
    'bio' => ['required', 'string', 'max:255', new Clean],
];

You'll notice that both name and bio are using the Clean rule. This rule will take the value and ensure that it doesn't exist in the profanity config files that the package has. By default, it will use your app locale, so if your locale is set to en, it will scan profanity in the en profanity config.

If profanity is found, an error will appear in the validation errors array and will be shown to your user (if your application does this).

Some applications allow for more than one language, so you're able to pass in additional locales to the rule to cater for them. Below is an example showing how to cater for both en and it:

use JonPurvis\Squeaky\Rules\Clean;

'name' => ['required', 'string', 'max:255', new Clean(['en', 'it'])],

Alternatively, instead of passing an array of strings to the rule, you can pass in an array of JonPurvis\Squeaky\Enums\Locale enums to specify the locales:

use JonPurvis\Squeaky\Enums\Locale;
use JonPurvis\Squeaky\Rules\Clean;

'name' => ['required', 'string', 'max:255', new Clean([Locale::English, Locale::Italian])],

This will then check the locale config for any locale you've passed in (providing the config exists!). If profanity is found in any of them, an error will appear in the validation errors.

The really cool thing about this, is the error will be returned in the language that failed. So if the failure was found in the it profanity list, the package assumes the user is Italian and returns the error message in Italian to let them know that their value is not clean.

Configuration

Squeaky provides a publishable configuration file that allows you to customize the package behavior for your specific application needs.

Custom Words

You can specify custom words that should be treated as profanity or explicitly allowed:

// config/squeaky.php
return [
    'blocked_words' => [
        'company_secret',
        'internal_term',
        'restricted_word',
    ],
    
    'allowed_words' => [
        'analytics',
        'scunthorpe',
        'penistone',
    ],
    
    'case_sensitive' => false,
];
  • blocked_words: Words that will be treated as profanity regardless of the locale-specific profanity lists. These override everything else.
  • allowed_words: Words that will be explicitly allowed even if they appear in the locale-specific profanity lists.
  • case_sensitive: Determines whether word matching should be case-sensitive. Defaults to false for case-insensitive matching.

Priority Order

The validation follows this priority order:

  1. Custom blocked words (highest priority - always blocked)
  2. Custom allowed words (override locale profanity)
  3. Locale-specific profanity lists (lowest priority)

Languages

Squeaky currently supports the following languages:

  • Arabic
  • Danish
  • English
  • German
  • Spanish
  • Italian
  • Japanese
  • Dutch
  • Brazilian Portuguese
  • Russian

Contributing

Contributions to the package are more than welcome! Depending on the type of change, there's a few extra steps that will need carrying out:

Existing Locale Changes

These changes should be done in Pest Profanity Plugin and a new release should be tagged. Dependabot will then open a PR on this repo. Once that's been merged, it should be good to go because the config will already be getting loaded.

New Locale Support

The new locale config will need adding to Pest Profanity Plugin first and a new release should be tagged. Dependabot will then open a PR on this repo. Additionally, the new config will need loading in within the boot method of the service provider of this package.

A new case will also need adding to the JonPurvis/Squeaky/Enums/Locale enum to support the new locale.

Functionality Changes

For changes to how this rule works, these should be done in this package. No change needed to Pest Profanity Plugin.

jonpurvis/squeaky 适用场景与选型建议

jonpurvis/squeaky 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.66k 次下载、GitHub Stars 达 72, 最近一次更新时间为 2025 年 02 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「php」 「plugin」 「laravel」 「profanity」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jonpurvis/squeaky 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jonpurvis/squeaky 我们能提供哪些服务?
定制开发 / 二次开发

基于 jonpurvis/squeaky 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 72
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 72
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-27