芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/airport-back/vendor/yiisoft/yii2/validators/FilterValidator.php
* @since 2.0 */ class FilterValidator extends Validator { /** * @var callable the filter. This can be a global function name, anonymous function, etc. * The function signature must be as follows, * * ```php * function foo($value) { * // compute $newValue here * return $newValue; * } * ``` */ public $filter; /** * @var bool whether the filter should be skipped if an array input is given. * If true and an array input is given, the filter will not be applied. */ public $skipOnArray = false; /** * @var bool this property is overwritten to be false so that this validator will * be applied when the value being validated is empty. */ public $skipOnEmpty = false; /** * {@inheritdoc} */ public function init() { parent::init(); if ($this->filter === null) { throw new InvalidConfigException('The "filter" property must be set.'); } } /** * {@inheritdoc} */ public function validateAttribute($model, $attribute) { $value = $model->$attribute; if (!$this->skipOnArray || !is_array($value)) { $model->$attribute = call_user_func($this->filter, $value); } } /** * {@inheritdoc} */ public function clientValidateAttribute($model, $attribute, $view) { if ($this->filter !== 'trim') { return null; } ValidationAsset::register($view); $options = $this->getClientOptions($model, $attribute); return 'value = yii.validation.trim($form, attribute, ' . Json::htmlEncode($options) . ', value);'; } /** * {@inheritdoc} */ public function getClientOptions($model, $attribute) { $options = []; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } return $options; } }