Documentation

UniqueEntity extends Constraint
in package

Constraint for the Unique Entity validator.

Tags
Annotation
Target

({"CLASS", "ANNOTATION"})

author

Benjamin Eberlei kontakt@beberlei.de

Table of Contents

Constants

CLASS_CONSTRAINT  = 'class'
Marks a constraint that can be put onto classes.
DEFAULT_GROUP  = 'Default'
The name of the group given to all constraints with no explicit group.
NOT_UNIQUE_ERROR  = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f'
PROPERTY_CONSTRAINT  = 'property'
Marks a constraint that can be put onto properties.

Properties

$em  : mixed
$entityClass  : mixed
$errorPath  : mixed
$fields  : mixed
$groups  : array<string|int, string>
The groups that the constraint belongs to.
$ignoreNull  : mixed
$message  : mixed
$payload  : mixed
Domain-specific data attached to a constraint.
$repositoryMethod  : mixed
$service  : mixed
$errorNames  : mixed
Maps error codes to the names of their constants.

Methods

__construct()  : mixed
Initializes the constraint with options.
__get()  : mixed
Returns the value of a lazily initialized option.
__isset()  : bool
__set()  : mixed
Sets the value of a lazily initialized option.
addImplicitGroupName()  : mixed
Adds the given group if this constraint is in the Default group.
getDefaultOption()  : string|null
Returns the name of the default option.
getErrorName()  : string
Returns the name of the given error code.
getRequiredOptions()  : array<string|int, string>
Returns the name of the required options.
getTargets()  : string|array<string|int, string>
Returns whether the constraint can be put onto classes, properties or both.
validatedBy()  : string
The validator must be defined as a service with this name.
normalizeOptions()  : array<string|int, mixed>

Constants

CLASS_CONSTRAINT

Marks a constraint that can be put onto classes.

public mixed CLASS_CONSTRAINT = 'class'

DEFAULT_GROUP

The name of the group given to all constraints with no explicit group.

public mixed DEFAULT_GROUP = 'Default'

NOT_UNIQUE_ERROR

public mixed NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f'

PROPERTY_CONSTRAINT

Marks a constraint that can be put onto properties.

public mixed PROPERTY_CONSTRAINT = 'property'

Properties

$groups

The groups that the constraint belongs to.

public array<string|int, string> $groups

$message

public mixed $message = 'This value is already used.'

$payload

Domain-specific data attached to a constraint.

public mixed $payload

$repositoryMethod

public mixed $repositoryMethod = 'findBy'

$service

public mixed $service = 'doctrine.orm.validator.unique'

$errorNames

Maps error codes to the names of their constants.

protected static mixed $errorNames = [self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR']

Methods

__construct()

Initializes the constraint with options.

public __construct(array<string|int, mixed>|string $fields[, string $message = null ][, string $service = null ][, string $em = null ][, string $entityClass = null ][, string $repositoryMethod = null ][, string $errorPath = null ][, bool $ignoreNull = null ][, array<string|int, mixed> $groups = null ][, mixed $payload = null ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$fields : array<string|int, mixed>|string

the combination of fields that must contain unique values or a set of options

$message : string = null
$service : string = null
$em : string = null
$entityClass : string = null
$repositoryMethod : string = null
$errorPath : string = null
$ignoreNull : bool = null
$groups : array<string|int, mixed> = null

An array of validation groups

$payload : mixed = null

Domain-specific data attached to a constraint

$options : array<string|int, mixed> = []

The options (as associative array) or the value for the default option (any other type)

__get()

Returns the value of a lazily initialized option.

public __get(string $option) : mixed

Corresponding properties are added to the object on first access. Hence this method will be called at most once per constraint instance and option name.

Parameters
$option : string
Tags
throws
InvalidOptionsException

If an invalid option name is given

__isset()

public __isset(string $option) : bool
Parameters
$option : string
Return values
bool

__set()

Sets the value of a lazily initialized option.

public __set(string $option, mixed $value) : mixed

Corresponding properties are added to the object on first access. Hence this method will be called at most once per constraint instance and option name.

Parameters
$option : string
$value : mixed
Tags
throws
InvalidOptionsException

If an invalid option name is given

addImplicitGroupName()

Adds the given group if this constraint is in the Default group.

public addImplicitGroupName(string $group) : mixed
Parameters
$group : string

getDefaultOption()

Returns the name of the default option.

public getDefaultOption() : string|null

Override this method to define a default option.

Return values
string|null

getErrorName()

Returns the name of the given error code.

public static getErrorName(string $errorCode) : string
Parameters
$errorCode : string
Tags
throws
InvalidArgumentException

If the error code does not exist

Return values
string

getRequiredOptions()

Returns the name of the required options.

public getRequiredOptions() : array<string|int, string>

Override this method if you want to define required options.

Return values
array<string|int, string>

getTargets()

Returns whether the constraint can be put onto classes, properties or both.

public getTargets() : string|array<string|int, string>
Return values
string|array<string|int, string>

One or more constant values

validatedBy()

The validator must be defined as a service with this name.

public validatedBy() : string
Return values
string

normalizeOptions()

protected normalizeOptions(mixed $options) : array<string|int, mixed>
Parameters
$options : mixed
Return values
array<string|int, mixed>

        
On this page

Search results