tourze/sensitive-text-detect-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tourze/sensitive-text-detect-bundle

最新稳定版本:1.1.0

Composer 安装命令:

composer require tourze/sensitive-text-detect-bundle

包简介

敏感文本识别服务,提供文本内容的敏感性检测功能

README 文档

README

English | 中文

Latest Version Build Status Total Downloads License Coverage Status

A Symfony bundle for detecting sensitive text in content. This bundle provides a flexible interface for implementing content filtering and sensitive text detection with user context support.

Features

  • Simple Integration: Easy to integrate with any Symfony application
  • Flexible Interface: Replaceable detector implementation through the service container
  • Context-Aware: Support for user-specific detection with UserInterface integration
  • Framework Native: Built on Symfony's dependency injection and configuration system
  • Extensible: Default implementation that can be easily replaced with custom logic

Requirements

  • PHP 8.1+
  • Symfony 6.4+

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');
    }
}

API Reference

SensitiveTextDetector Interface

interface SensitiveTextDetector
{
    /**
     * Check if text contains sensitive content
     *
     * @param string $text The text to check
     * @param UserInterface|null $user Optional user context
     * @return bool True if text is sensitive, false otherwise
     */
    public function isSensitiveText(string $text, ?UserInterface $user = null): bool;
}

Default Implementation

The bundle includes a DefaultTextSensitiveTextDetector that always returns false. This is intended as a placeholder that you should replace with your own implementation.

Testing

Run tests:

./vendor/bin/phpunit packages/sensitive-text-detect-bundle/tests

Contributing

Contributions are welcome! Please ensure:

  1. All tests pass
  2. Code follows PSR-12 standards
  3. New features include tests
  4. Documentation is updated

License

This package is released under the MIT License. See the LICENSE file for details.

统计信息

  • 总下载量: 192
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固