function Constraint::normalizeOptions
Return value
array<string, mixed>
2 calls to Constraint::normalizeOptions()
- Compound::__construct in vendor/
symfony/ validator/ Constraints/ Compound.php - The groups of the composite and its nested constraints are made consistent using the following strategy:
- Constraint::__construct in vendor/
symfony/ validator/ Constraint.php - Initializes the constraint with options.
File
-
vendor/
symfony/ validator/ Constraint.php, line 127
Class
- Constraint
- Contains the properties of a constraint definition.
Namespace
Symfony\Component\ValidatorCode
protected function normalizeOptions(mixed $options) : array {
$normalizedOptions = [];
$defaultOption = $this->getDefaultOption();
$invalidOptions = [];
$missingOptions = array_flip($this->getRequiredOptions());
$knownOptions = get_class_vars(static::class);
if (\is_array($options) && isset($options['value']) && !property_exists($this, 'value')) {
if (null === $defaultOption) {
throw new ConstraintDefinitionException(\sprintf('No default option is configured for constraint "%s".', static::class));
}
$options[$defaultOption] = $options['value'];
unset($options['value']);
}
if (\is_array($options)) {
reset($options);
}
if ($options && \is_array($options) && \is_string(key($options))) {
foreach ($options as $option => $value) {
if (\array_key_exists($option, $knownOptions)) {
$normalizedOptions[$option] = $value;
unset($missingOptions[$option]);
}
else {
$invalidOptions[] = $option;
}
}
}
elseif (null !== $options && !(\is_array($options) && 0 === \count($options))) {
if (null === $defaultOption) {
throw new ConstraintDefinitionException(\sprintf('No default option is configured for constraint "%s".', static::class));
}
if (\array_key_exists($defaultOption, $knownOptions)) {
$normalizedOptions[$defaultOption] = $options;
unset($missingOptions[$defaultOption]);
}
else {
$invalidOptions[] = $defaultOption;
}
}
if (\count($invalidOptions) > 0) {
throw new InvalidOptionsException(\sprintf('The options "%s" do not exist in constraint "%s".', implode('", "', $invalidOptions), static::class), $invalidOptions);
}
if (\count($missingOptions) > 0) {
throw new MissingOptionsException(\sprintf('The options "%s" must be set for constraint "%s".', implode('", "', array_keys($missingOptions)), static::class), array_keys($missingOptions));
}
return $normalizedOptions;
}