settingsTypeRegistry->has($definition->type)) { throw new InvalidSettingDefinitionException('Invalid settings type "' . $definition->type . '" in setting "' . $definition->key . '"', 1732181103); } $type = $this->settingsTypeRegistry->get($definition->type); // Only validate options if type supports them if ($type instanceof SettingsTypeOptionAwareInterface) { $this->validateSettingsTypeOptions($definition, $type); } // Validate default value if (!$type->validate($definition->default, $definition)) { throw new InvalidSettingDefinitionException('Invalid default value in setting "' . $definition->key . '"', 1732181102); } } private function validateSettingsTypeOptions( SettingDefinition $definition, SettingsTypeInterface&SettingsTypeOptionAwareInterface $type ): void { $supportedOptions = $type->getSupportedOptions(); $options = $definition->options; foreach ($supportedOptions as $optionName => $optionDefinition) { if (!array_key_exists($optionName, $options)) { if ($optionDefinition->required) { throw new InvalidSettingDefinitionException( 'Required option "' . $optionName . '" missing for type "' . $definition->type . '" in setting "' . $definition->key . '"', 1732181110 ); } continue; } $value = $definition->options[$optionName]; $isValid = match ($optionDefinition->type) { 'string' => is_string($value), 'int' => is_int($value), 'number' => is_int($value) || is_float($value), 'bool' => is_bool($value), 'array' => is_array($value), default => throw new InvalidSettingDefinitionException('Unsupported settings type option: ' . $optionDefinition->type, 1734513842), }; if (!$isValid) { throw new InvalidSettingDefinitionException( 'Invalid value for option "' . $optionName . '" in setting "' . $definition->key . '": expected ' . $optionDefinition->type . ', got ' . gettype($value), 1732181109 ); } unset($options[$optionName]); } if ($options !== []) { throw new InvalidSettingDefinitionException( 'Unsupported options [' . implode(', ', array_keys($options)) . '] for type "' . $definition->type . '" in setting "' . $definition->key . '". Supported options: [' . implode(', ', array_keys($supportedOptions)) . ']', 1732181108 ); } if (!$type->validateOptions($definition)) { throw new InvalidSettingDefinitionException( 'Setting definition options for type "' . $definition->type . '" in setting "' . $definition->key . '" could not be validated.', 1752821671 ); } } }