Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Unique.php

class Unique

Validates that all the elements of the given collection are unique.

@author Yevgeniy Zholkevskiy <zhenya.zholkevskiy@gmail.com>

Hierarchy

  • class \Symfony\Component\Validator\Constraint
    • class \Symfony\Component\Validator\Constraints\Unique extends \Symfony\Component\Validator\Constraint

Expanded class hierarchy of Unique

File

vendor/symfony/validator/Constraints/Unique.php, line 22

Namespace

Symfony\Component\Validator\Constraints
View source
class Unique extends Constraint {
    public const IS_NOT_UNIQUE = '7911c98d-b845-4da0-94b7-a8dac36bc55a';
    public array|string $fields = [];
    public ?string $errorPath = null;
    protected const ERROR_NAMES = [
        self::IS_NOT_UNIQUE => 'IS_NOT_UNIQUE',
    ];
    public string $message = 'This collection should contain only unique elements.';
    
    /** @var callable|null */
    public $normalizer;
    
    /**
     * @param array<string,mixed>|null $options
     * @param string[]|null            $groups
     * @param string[]|string|null     $fields  Defines the key or keys in the collection that should be checked for uniqueness (defaults to null, which ensure uniqueness for all keys)
     */
    public function __construct(?array $options = null, ?string $message = null, ?callable $normalizer = null, ?array $groups = null, mixed $payload = null, array|string|null $fields = null, ?string $errorPath = null) {
        parent::__construct($options, $groups, $payload);
        $this->message = $message ?? $this->message;
        $this->normalizer = $normalizer ?? $this->normalizer;
        $this->fields = $fields ?? $this->fields;
        $this->errorPath = $errorPath ?? $this->errorPath;
        if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
            throw new InvalidArgumentException(\sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Constraint::$groups public property The groups that the constraint belongs to.
Constraint::$payload public property Domain-specific data attached to a constraint.
Constraint::addImplicitGroupName public function Adds the given group if this constraint is in the Default group. 2
Constraint::CLASS_CONSTRAINT public constant Marks a constraint that can be put onto classes.
Constraint::DEFAULT_GROUP public constant The name of the group given to all constraints with no explicit group.
Constraint::getDefaultOption public function Returns the name of the default option. 28
Constraint::getErrorName public static function Returns the name of the given error code.
Constraint::getRequiredOptions public function Returns the name of the required options. 22
Constraint::getTargets public function Returns whether the constraint can be put onto classes, properties or
both.
8
Constraint::normalizeOptions protected function
Constraint::PROPERTY_CONSTRAINT public constant Marks a constraint that can be put onto properties.
Constraint::validatedBy public function Returns the name of the class that validates this constraint. 9
Constraint::__get public function Returns the value of a lazily initialized option. 2
Constraint::__isset public function 1
Constraint::__set public function Sets the value of a lazily initialized option. 1
Constraint::__sleep public function Optimizes the serialized value to minimize storage space.
Unique::$errorPath public property
Unique::$fields public property
Unique::$message public property
Unique::$normalizer public property @var callable|null
Unique::ERROR_NAMES protected constant Maps error codes to the names of their constants. Overrides Constraint::ERROR_NAMES
Unique::IS_NOT_UNIQUE public constant
Unique::__construct public function Overrides Constraint::__construct
RSS feed
Powered by Drupal