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

Breadcrumb

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

function Constraint::__construct

Same name in this branch
  1. 11.1.x vendor/composer/semver/src/Constraint/Constraint.php \Composer\Semver\Constraint\Constraint::__construct()
  2. 11.1.x core/lib/Drupal/Core/Validation/Attribute/Constraint.php \Drupal\Core\Validation\Attribute\Constraint::__construct()
  3. 11.1.x core/lib/Drupal/Component/Version/Constraint.php \Drupal\Component\Version\Constraint::__construct()

Initializes the constraint with options.

You should pass an associative array. The keys should be the names of existing properties in this class. The values should be the value for these properties.

Alternatively you can override the method getDefaultOption() to return the name of an existing property. If no associative array is passed, this property is set instead.

You can force that certain options are set by overriding getRequiredOptions() to return the names of these options. If any option is not set here, an exception is thrown.

Parameters

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

string[] $groups An array of validation groups:

mixed $payload Domain-specific data attached to a constraint:

Throws

InvalidOptionsException When you pass the names of non-existing options

MissingOptionsException When you don't pass any of the options returned by getRequiredOptions()

ConstraintDefinitionException When you don't pass an associative array, but getDefaultOption() returns null

116 calls to Constraint::__construct()
AbstractComparison::__construct in vendor/symfony/validator/Constraints/AbstractComparison.php
Initializes the constraint with options.
AbstractComparison::__construct in vendor/symfony/validator/Constraints/AbstractComparison.php
Initializes the constraint with options.
Bic::__construct in vendor/symfony/validator/Constraints/Bic.php
Bic::__construct in vendor/symfony/validator/Constraints/Bic.php
Blank::__construct in vendor/symfony/validator/Constraints/Blank.php

... See full list

58 methods override Constraint::__construct()
AbstractComparison::__construct in vendor/symfony/validator/Constraints/AbstractComparison.php
Initializes the constraint with options.
Bic::__construct in vendor/symfony/validator/Constraints/Bic.php
Blank::__construct in vendor/symfony/validator/Constraints/Blank.php
Callback::__construct in vendor/symfony/validator/Constraints/Callback.php
CardScheme::__construct in vendor/symfony/validator/Constraints/CardScheme.php

... See full list

File

vendor/symfony/validator/Constraint.php, line 109

Class

Constraint
Contains the properties of a constraint definition.

Namespace

Symfony\Component\Validator

Code

public function __construct(mixed $options = null, ?array $groups = null, mixed $payload = null) {
    unset($this->groups);
    // enable lazy initialization
    $options = $this->normalizeOptions($options);
    if (null !== $groups) {
        $options['groups'] = $groups;
    }
    $options['payload'] = $payload ?? $options['payload'] ?? null;
    foreach ($options as $name => $value) {
        $this->{$name} = $value;
    }
}

API Navigation

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