Skip to content

Banned Phrases

Validates that a given string does not contain blacklisted phrases.

Can be applied to properties or methods.

Basic Usage

namespace App\Entity;

use Omines\AntiSpamBundle\Validator\Constraints as Antispam;

class Message
{
    #[Antispam\BannedPhrases(['viagra', 'cialis'])
    protected string $content;
}
# config/validator/validation.yaml
App\Entity\Message:
    properties:
        content:
            - BannedPhrases:
                - viagra
                - cialis
// src/Entity/Participant.php
namespace App\Entity;

use Omines\AntiSpamBundle\Validator\Constraints as Antispam;
use Symfony\Component\Validator\Mapping\ClassMetadata;

class Message
{
// ...

    public static function loadValidatorMetadata(ClassMetadata $metadata): void
    {
        $metadata->addPropertyConstraint('content', new Antispam\BannedPhrases(['viagra', 'cialis']));
    }
}

Options

groups

type: array|string default: null

It defines the validation group or groups of this constraint. Read more about validation groups.

passive

type: bool default: null, defaulting to bundle configuration

When in passive mode the constraint will not generate a validation error, but still dispatch its regular events.

With default bundle configuration passive mode is disabled.

payload

type: mixed default: null

This option can be used to attach arbitrary domain-specific data to a constraint. The configured payload is not used by the Validator component, but its processing is completely up to you.

For example, you may want to use several error levels to present failed constraints differently in the front-end depending on the severity of the error.

stealth

type: bool default: null, defaulting to bundle configuration

With stealth mode disabled the validator will generate a verbose error, similar to Symfony built-in constraints, explaining for precisely which reasons what rule was validated.

If stealth mode is enabled instead the validator only shows a generic error message, stating that form submission failed and the user should contact the website administrator for further assistance.

With default bundle configuration stealth mode is disabled by default when used standalone, and enabled by default when applied as part of an anti-spam profile.