本文整理汇总了PHP中DateTime::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::validate方法的具体用法?PHP DateTime::validate怎么用?PHP DateTime::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime
的用法示例。
在下文中一共展示了DateTime::validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validate
*
* @param string $key
* @param string $value
* @param string $label
* @param array $fields
* @return boolean
*/
public function validate($key, $value, $label, &$fields)
{
unset($fields[$key]);
$fields['>=' . $key] = null;
$fields['<=' . $key] = null;
if (!is_array($value)) {
$this->addError($key, $this->getMessageInvalid(), ['#LABEL#' => $label]);
return false;
}
if ($this->first_field === null) {
$this->first_field = $this->min();
}
if ($this->second_field === null) {
$this->second_field = $this->max();
}
$min_value = array_key_exists($this->min_key, $value) ? $value[$this->min_key] : null;
if (!$this->first_field->validate($this->min_key, $min_value, $label, $fields)) {
$this->addError($key, $this->getMessageInvalidMin(), ['#LABEL#' => $label, '#VALUE#' => $min_value]);
return false;
}
$max_value = array_key_exists($this->max_key, $value) ? $value[$this->max_key] : null;
if (!$this->second_field->validate($this->max_key, $max_value, $label, $fields)) {
$this->addError($key, $this->getMessageInvalidMax(), ['#LABEL#' => $label, '#VALUE#' => $max_value]);
return false;
}
if ($this->string()->length($max_value) > 0) {
$max_time = $this->date()->makeTimeStamp($max_value, $this->format_input);
$fields['<=' . $key] = $this->date()->convertTimeStamp($max_time);
}
if ($this->string()->length($min_value) > 0) {
$min_time = $this->date()->makeTimeStamp($min_value, $this->format_input);
$fields['>=' . $key] = $this->date()->convertTimeStamp($min_time);
}
if (isset($max_time) && isset($min_time)) {
if ($max_time < $min_time) {
$this->addError($key, $this->getMessageMinMoreMax(), ['#LABEL#' => $label, '#MIN#' => $min_value, '#MAX#' => $max_value]);
return false;
}
}
return true;
}