You are here

public function Count::__construct in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/validator/Constraints/Count.php \Symfony\Component\Validator\Constraints\Count::__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)

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

Overrides Constraint::__construct

File

vendor/symfony/validator/Constraints/Count.php, line 39

Class

Count
@Target({"PROPERTY", "METHOD", "ANNOTATION"})

Namespace

Symfony\Component\Validator\Constraints

Code

public function __construct($options = null) {
  if (null !== $options && !is_array($options)) {
    $options = array(
      'min' => $options,
      'max' => $options,
    );
  }
  parent::__construct($options);
  if (null === $this->min && null === $this->max) {
    throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array(
      'min',
      'max',
    ));
  }
}