tourze / sensitive-text-detect-bundle
敏感文本识别服务
Installs: 38
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/event-dispatcher: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/security-core: ^6.4
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-05-09 08:17:33 UTC
README
A Symfony bundle for detecting sensitive text in content.
Features
- Simple integration with Symfony applications
- Replaceable detector implementation through the service container
- Support for context-aware detection with user object support
- Built on Symfony's dependency injection and configuration system
Installation
Install via Composer:
composer require tourze/sensitive-text-detect-bundle
Quick Start
Register the Bundle in your Symfony application
// config/bundles.php return [ // ... Tourze\SensitiveTextDetectBundle\SensitiveTextDetectBundle::class => ['all' => true], ];
Inject and use the service
<?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use Tourze\SensitiveTextDetectBundle\Service\SensitiveTextDetector; class TextCheckController extends AbstractController { public function __construct( private readonly SensitiveTextDetector $sensitiveTextDetector, ) { } #[Route('/check-text', name: 'app_check_text')] public function checkText(): Response { $text = 'Sample text to check'; $isSensitive = $this->sensitiveTextDetector->isSensitiveText($text); return $this->json([ 'is_sensitive' => $isSensitive, ]); } }
Customizing the Detector
By default, the bundle uses DefaultTextSensitiveTextDetector
implementation, which always returns false
. You can customize the detection logic by implementing the SensitiveTextDetector
interface and registering your implementation in the container:
<?php namespace App\Service; use Symfony\Component\DependencyInjection\Attribute\AsAlias; use Symfony\Component\Security\Core\User\UserInterface; use Tourze\SensitiveTextDetectBundle\Service\SensitiveTextDetector; #[AsAlias(SensitiveTextDetector::class)] class CustomSensitiveTextDetector implements SensitiveTextDetector { public function isSensitiveText(string $text, ?UserInterface $user = null): bool { // Implement your custom sensitive text detection logic return str_contains($text, 'sensitive-word'); } }
Testing
Run tests:
./vendor/bin/phpunit packages/sensitive-text-detect-bundle/tests
License
This package is released under the MIT License. See the LICENSE file for details.