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

Breadcrumb

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

function When::__construct

Same name in this branch
  1. 11.1.x vendor/symfony/dependency-injection/Attribute/When.php \Symfony\Component\DependencyInjection\Attribute\When::__construct()

Parameters

string|Expression|array<string,mixed> $expression The condition to evaluate, written with the ExpressionLanguage syntax:

Constraint[]|Constraint|null $constraints One or multiple constraints that are applied if the expression returns true:

array<string,mixed>|null $values The values of the custom variables used in the expression (defaults to []):

string[]|null $groups:

array<string,mixed> $options:

Overrides Composite::__construct

File

vendor/symfony/validator/Constraints/When.php, line 38

Class

When
Conditionally apply validation constraints based on an expression using the ExpressionLanguage syntax.

Namespace

Symfony\Component\Validator\Constraints

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal