PHP code example of tourze / sensitive-text-detect-bundle
1. Go to this page and download the library: Download tourze/sensitive-text-detect-bundle 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/ */
tourze / sensitive-text-detect-bundle example snippets
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,
]);
}
}
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');
}
}
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;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.