本文整理匯總了PHP中yii\validators\Validator::createValidator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::createValidator方法的具體用法?PHP Validator::createValidator怎麽用?PHP Validator::createValidator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\validators\Validator
的用法示例。
在下文中一共展示了Validator::createValidator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validateEndpoint
public function validateEndpoint()
{
$url = $this->baseUrl . $this->endpoint;
$validator = Validator::createValidator('url', $this, []);
if ($validator->validate($url, $error)) {
// Crop fragment
if (($pos = strpos($this->endpoint, '#')) !== false) {
$this->endpoint = substr($this->endpoint, 0, $pos);
}
// Crop query
if (($pos = strpos($this->endpoint, '?')) !== false) {
$this->endpoint = substr($this->endpoint, 0, $pos);
}
// Parse params
$query = parse_url($url, PHP_URL_QUERY);
if (trim($query) !== '') {
foreach (explode('&', $query) as $couple) {
list($key, $value) = explode('=', $couple, 2) + [1 => ''];
$this->queryKeys[] = urldecode($key);
$this->queryValues[] = urldecode($value);
$this->queryActives[] = true;
}
}
} else {
$this->addError('endpoint', $error);
}
}
示例2: attach
public function attach($owner)
{
parent::attach($owner);
if (in_array($owner->scenario, $this->scenarios)) {
$fileValidator = Validator::createValidator('file', $this->owner, $this->provider->attributeName, ['types' => $this->provider->fileTypes]);
$owner->validators[] = $fileValidator;
}
}
示例3: attach
/**
* @param ActiveRecord $owner
*/
public function attach($owner)
{
parent::attach($owner);
// Применяем конфигурационные опции
foreach ($this->imageConfig as $key => $value) {
$var = '_' . $key;
$this->{$var} = $value;
}
// Вычисляем корень сайта
if (empty($this->_rootPathAlias)) {
$savePathParts = explode('/', $this->_savePathAlias);
// Удаляем последнюю часть
unset($savePathParts[count($savePathParts - 1)]);
// Объединяем все части обратно
$this->_rootPathAlias = implode('/', $savePathParts);
}
// Добавляем валидатор require
if ($this->_imageRequire) {
$owner->validators->append(Validator::createValidator(RequiredValidator::className(), $owner, $this->_imageAttribute));
}
// Подключаем валидатор изображения
$validatorParams = array_merge(['extensions' => $this->_fileTypes, 'maxSize' => $this->_maxFileSize, 'skipOnEmpty' => true, 'tooBig' => 'Изображение слишком велико, максимальный размер: ' . floor($this->_maxFileSize / 1024 / 1024) . ' Мб'], $this->_imageValidatorParams);
$validator = Validator::createValidator(ImageValidator::className(), $owner, $this->_imageAttribute, $validatorParams);
$owner->validators->append($validator);
}
示例4: checkFile
/**
* 各類型上傳文件驗證
* @param $attribute
* @param $params
*/
public function checkFile($attribute, $params)
{
// 按照類型 驗證上傳
switch ($this->type) {
case Media::TYPE_IMAGE:
$rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 1048576];
// 1MB
break;
case Media::TYPE_THUMB:
$rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 524288];
// 64KB
break;
case Media::TYPE_VOICE:
$rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'amr, mp3', 'maxSize' => 2097152];
// 2MB
break;
case Media::TYPE_VIDEO:
$rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'mp4', 'maxSize' => 10485760];
// 10MB
break;
default:
return;
}
$validator = Validator::createValidator($rule[1], $this, (array) $rule[0], array_slice($rule, 2));
$validator->validateAttributes($this);
}
示例5: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
$validators = $owner->validators;
$validator = Validator::createValidator('safe', $owner, array_keys($this->attributes));
$validators->append($validator);
}
示例6: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
if (!is_array($this->attributes) || empty($this->attributes)) {
throw new InvalidParamException('Invalid or empty attributes array.');
} else {
foreach ($this->attributes as $attribute => $config) {
if (!isset($config['path']) || empty($config['path'])) {
throw new InvalidParamException('Path must be set for all attributes.');
}
if (!isset($config['tempPath']) || empty($config['tempPath'])) {
throw new InvalidParamException('Temporary path must be set for all attributes.');
}
if (!isset($config['url']) || empty($config['url'])) {
$config['url'] = $this->publish($config['path']);
}
$this->attributes[$attribute]['path'] = FileHelper::normalizePath(Yii::getAlias($config['path'])) . DIRECTORY_SEPARATOR;
$this->attributes[$attribute]['tempPath'] = FileHelper::normalizePath(Yii::getAlias($config['tempPath'])) . DIRECTORY_SEPARATOR;
$this->attributes[$attribute]['url'] = rtrim($config['url'], '/') . '/';
$validator = Validator::createValidator('string', $this->owner, $attribute);
$this->owner->validators[] = $validator;
unset($validator);
}
}
}
示例7: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
$validators = $owner->validators;
foreach ($this->rules as $rule) {
if ($rule instanceof Validator) {
$validators->append($rule);
$this->validators[] = $rule;
// keep a reference in behavior
} elseif (is_array($rule) && isset($rule[0], $rule[1])) {
// attributes, validator type
$validator = Validator::createValidator($rule[1], $owner, (array) $rule[0], array_slice($rule, 2));
$validators->append($validator);
$this->validators[] = $validator;
// keep a reference in behavior
} else {
throw new InvalidConfigException('Invalid validation rule: a rule must specify both attribute names and validator type.');
}
}
$owner->on(ActiveRecord::EVENT_BEFORE_INSERT, function () {
$this->saveRelatedDir($this->txt, $this->id_field, $this->name_field, $this->classDir);
});
$owner->on(ActiveRecord::EVENT_BEFORE_UPDATE, function () {
$this->saveRelatedDir($this->txt, $this->id_field, $this->name_field, $this->classDir);
});
}
示例8: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
$validators = $this->owner->getValidators();
$validator = Validator::createValidator('safe', $this->owner, 'template_id');
$validators->append($validator);
}
示例9: attach
public function attach($owner)
{
parent::attach($owner);
$validators = $owner->validators;
$validator = Validator::createValidator('safe', $owner, ['singleImageArray']);
$validators->append($validator);
}
示例10: attach
public function attach($owner)
{
parent::attach($owner);
$validators = $owner->validators;
$validatorInt = Validator::createValidator('integer', $owner, ['create_user_id', 'update_user_id']);
$validatorSafe = Validator::createValidator('safe', $owner, ['created', 'updated']);
$validators->append($validatorInt);
$validators->append($validatorSafe);
}
示例11: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->message === null) {
$this->message = Yii::t('validator', '{attribute} must be an array', ['attribute' => $attribute]);
}
if ($this->validator !== null) {
$this->_validator = Validator::createValidator($this->validator[1], null, null, array_slice($this->validator, 2));
}
}
示例12: attach
/**
* Add safe validators for virtual attributes if there are not rules for them
*
* @param \yii\base\Component $owner
*/
public function attach($owner)
{
parent::attach($owner);
foreach ($this->mlGetAttributes() as $attribute) {
$validators = $this->owner->getActiveValidators($attribute);
if (empty($validators)) {
$this->owner->getValidators()->append(Validator::createValidator('string', $this->owner, $attribute));
}
}
}
示例13: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
if ($this->ownerType !== false && $this->ownerType === null) {
$this->ownerType = $owner::className();
}
$validators = $this->owner->getValidators();
$validator = Validator::createValidator('im\\base\\validators\\RelationValidator', $this->owner, ['meta']);
$validators->append($validator);
}
示例14: beforeValidate
/**
* Добавляем дополнительные валидаторы
* в зависимости от типа записи
*/
public function beforeValidate()
{
switch ($this->type) {
case 7:
// Дата
$this->validators[] = Validator::createValidator('string', $this, 'value');
break;
}
return true;
}
示例15: init
/**
* Initializes this behavior by setting its properties and registering
* these properties as additional validators in the [[owner]].
*/
public function init()
{
$this->owner->validators[] = Validator::createValidator('required', $this->owner, 'menu_id', ['message' => Yii::t('cms', 'Please select a menu')]);
$this->owner->validators[] = Validator::createValidator('string', $this->owner, ['type', 'brand'], ['max' => 255]);
if (!empty($this->owner->content)) {
$properties = Json::decode($this->owner->content);
$this->menu_id = $properties['menu_id'];
$this->type = $properties['type'];
$this->brand = $properties['brand'];
}
}