本文整理匯總了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();
}
}