本文整理汇总了PHP中Reflection::invokeMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Reflection::invokeMethod方法的具体用法?PHP Reflection::invokeMethod怎么用?PHP Reflection::invokeMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reflection
的用法示例。
在下文中一共展示了Reflection::invokeMethod方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
public function validate()
{
$this->_errors = array();
$type = $this->_model->isNewRecord() ? 'create' : 'update';
if (empty($this->_registeredValidates[$type])) {
return true;
}
if ($this->_model->callback->call("before_validation_on_{$type}") === false) {
return false;
}
$validates = $this->_registeredValidates[$type];
foreach ($validates as $validate) {
if ($validate['type'] === 'validate') {
if (method_exists($this->_model, $validate[0])) {
$result = Reflection::invokeMethod($this->_model, $validate[0]);
}
continue;
}
$valid = true;
$attribute = $validate[0];
$value = $this->_model->{$attribute};
$valueLength = strlen($value);
if ($valueLength <= 0 && $validate['type'] !== 'validates_presence_of') {
continue;
}
switch ($validate['type']) {
case 'validates_presence_of':
$valid = $valueLength > 0;
break;
case 'validates_size_of':
$sizeType = $this->_getSizeType($validate);
if ($sizeType !== null) {
switch ($sizeType) {
case 'is':
$valid = $valueLength === $validate['is'];
break;
case 'in':
$valid = $valueLength >= $validate['in'][0] && $valueLength <= $validate['in'][1];
break;
case 'maximum':
$valid = $valueLength <= $validate['maximum'];
break;
case 'minimum':
$valid = $valueLength >= $validate['minimum'];
break;
}
}
break;
case 'validates_inclusion_of':
$valid = in_array($value, $validate['in']);
break;
case 'validates_exclusion_of':
$valid = in_array($value, $validate['in']) === false;
break;
case 'validates_format_of':
$valid = preg_match($validate['with'], $value) ? true : false;
break;
case 'validates_numericality_of':
$numericalityType = $this->_getNumericalityType($validate);
if ($numericalityType !== null) {
$value = floatval($value);
switch ($numericalityType) {
case 'only_integer':
$valid = preg_match('/^-?\\d+$/', $value) ? true : false;
break;
case 'even':
$valid = $value % 2 === 0;
break;
case 'odd':
$valid = $value % 2 === 1;
break;
case 'greater':
$valid = $value > $validate['greater'];
break;
case 'greater_or_equal':
$valid = $value >= $validate['greater_or_equal'];
break;
case 'equal':
$valid = $value === $validate['equal'];
break;
case 'less':
$valid = $value < $validate['less'];
break;
case 'less_or_equal':
$valid = $value <= $validate['less_or_equal'];
break;
}
}
break;
case 'validates_uniqueness_of':
$options = array('conditions' => array("`{$attribute}` = ? AND `id` != ?", $value, $this->_model->id));
$valid = $this->_model->exists($options) === false;
break;
}
if ($valid === true) {
continue;
}
$error = $this->_getErrorMessage($validate, $value);
if ($error === null) {
continue;
//.........这里部分代码省略.........