本文整理汇总了PHP中Parameter::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Parameter::validate方法的具体用法?PHP Parameter::validate怎么用?PHP Parameter::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parameter
的用法示例。
在下文中一共展示了Parameter::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* 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)));
}
}
示例2: validate
/**
* 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)));
}
}
}
示例3: validate
/**
* 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();
}
}