/** * If the parameter is required, checks that it has been set. * Checks the value complies with minimal and maximal length. * Checks the value validates the rule sets with setValidateType(). * * @return void * @throws UserError When the value doesn't comply with the requirements. */ public function validate() { parent::validate(); // When the parameter is required, checks that it has been set. $value = $this->getValue(); $length = strlen($value); if ($length < $this->getMinimalLength()) { Tools::ThrowUserError(wfMessage('wfmk-validation-error', $this->getName(), $value, wfMessage('wfmk-min-length', $this->getMinimalLength()))); } elseif ($this->getMaximalLength() != 0 && $length > $this->getMaximalLength()) { Tools::ThrowUserError(wfMessage('wfmk-validation-error', $this->getName(), $value, wfMessage('wfmk-max-length', $this->getMaximalLength()))); } elseif (!Tools::Validate($value, $this->validate_type)) { Tools::ThrowUserError(wfMessage('wfmk-validation-error', $this->getName(), $value, wfMessage('wfmk-string-validate-type', $this->validate_type))); } }
/** * If the parameter is required, checks that it has been set. * * Check that the value complies with the minimum and maximum values. * * @return void *When @throws UserError <ul> * <li>When the parameter is required and not set.</li> * <li>When value doesn't complies with the minimum and the maximum.</li> * </ul> */ public function validate() { parent::validate(); // If the parameter is required, checks that it has been set. $value = $this->getValue(); $min = $this->getMin(); if (!is_null($min)) { if ($value < $min) { Tools::ThrowUserError(wfMessage('wfmk-validation-error', $this->getName(), $value, wfMessage('wfmk-min-value', $min))); } } $max = $this->getMax(); if (!is_null($max)) { if ($value > $max) { Tools::ThrowUserError(wfMessage('wfmk-validation-error', $this->getName(), $value, wfMessage('wfmk-max-value', $max))); } } }
/** * If the xor-parameter is required, checks that a sub-parameter * has been set. * * If a sub-parameter has been set, calls its validate() method. * * @return void * @throws UserError */ public function validate() { parent::validate(); // If the parameter is required, checks that it has been set. $parameter = $this->getParameter(); if (!is_null($parameter)) { $parameter->validate(); } }