/** * Validates the parameter value. * Also sets the value to the default when it's not set or invalid, assuming there is a default. * * @since 0.5 * * @param $definitions array of ParamDefinition * @param $params array of Param * @param ValidatorOptions $options * * @throws MWException */ protected function doValidation(array $definitions, array $params, ValidatorOptions $options) { if ($this->setCount == 0) { if ($this->definition->isRequired()) { // This should not occur, so throw an exception. throw new MWException('Attempted to validate a required parameter without first setting a value.'); } else { $this->setToDefault(); } } else { $validationResult = $this->definition->validate($this, $definitions, $params, $options); if (is_array($validationResult)) { /** * @var ValidationError $error */ foreach ($validationResult as $error) { $error->addTags($this->getName()); $this->errors[] = $error; } } $this->validateCriteria($definitions, $params); $this->setToDefaultIfNeeded(); } }