class When
Same name in this branch
- 11.1.x vendor/symfony/dependency-injection/Attribute/When.php \Symfony\Component\DependencyInjection\Attribute\When
Conditionally apply validation constraints based on an expression using the ExpressionLanguage syntax.
Hierarchy
- class \Symfony\Component\Validator\Constraint
Expanded class hierarchy of When
See also
https://symfony.com/doc/current/components/expression_language.html
1 string reference to 'When'
- XmlFileLoader::parseNode in vendor/
symfony/ routing/ Loader/ XmlFileLoader.php - Parses a node from a loaded XML file.
File
-
vendor/
symfony/ validator/ Constraints/ When.php, line 24
Namespace
Symfony\Component\Validator\ConstraintsView source
class When extends Composite {
public string|Expression $expression;
public array|Constraint $constraints = [];
public array $values = [];
/**
* @param string|Expression|array<string,mixed> $expression The condition to evaluate, written with the ExpressionLanguage syntax
* @param Constraint[]|Constraint|null $constraints One or multiple constraints that are applied if the expression returns true
* @param array<string,mixed>|null $values The values of the custom variables used in the expression (defaults to [])
* @param string[]|null $groups
* @param array<string,mixed> $options
*/
public function __construct(string|Expression|array $expression, array|Constraint|null $constraints = null, ?array $values = null, ?array $groups = null, $payload = null, array $options = []) {
if (!class_exists(ExpressionLanguage::class)) {
throw new LogicException(\sprintf('The "symfony/expression-language" component is required to use the "%s" constraint. Try running "composer require symfony/expression-language".', __CLASS__));
}
if (\is_array($expression)) {
$options = array_merge($expression, $options);
}
else {
$options['expression'] = $expression;
$options['constraints'] = $constraints;
}
if (isset($options['constraints']) && !\is_array($options['constraints'])) {
$options['constraints'] = [
$options['constraints'],
];
}
if (null !== $groups) {
$options['groups'] = $groups;
}
if (null !== $payload) {
$options['payload'] = $payload;
}
parent::__construct($options);
$this->values = $values ?? $this->values;
}
public function getRequiredOptions() : array {
return [
'expression',
'constraints',
];
}
public function getTargets() : string|array {
return [
self::CLASS_CONSTRAINT,
self::PROPERTY_CONSTRAINT,
];
}
protected function getCompositeOption() : string {
return 'constraints';
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Composite::addImplicitGroupName | public | function | Implicit group names are forwarded to nested constraints. | Overrides Constraint::addImplicitGroupName | |
Composite::getNestedConstraints | public | function | @internal Used by metadata | ||
Composite::initializeNestedConstraints | protected | function | Initializes the nested constraints. | 1 | |
Constraint::$groups | public | property | The groups that the constraint belongs to. | ||
Constraint::$payload | public | property | Domain-specific data attached to a constraint. | ||
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::ERROR_NAMES | protected | constant | Maps error codes to the names of their constants. | 59 | |
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::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. | ||
When::$constraints | public | property | |||
When::$expression | public | property | |||
When::$values | public | property | |||
When::getCompositeOption | protected | function | Returns the name of the property that contains the nested constraints. | Overrides Composite::getCompositeOption | |
When::getRequiredOptions | public | function | Returns the name of the required options. | Overrides Constraint::getRequiredOptions | |
When::getTargets | public | function | Returns whether the constraint can be put onto classes, properties or both. |
Overrides Constraint::getTargets | |
When::__construct | public | function | Overrides Composite::__construct |