本文整理汇总了PHP中Cake\Validation\Validator::provider方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::provider方法的具体用法?PHP Validator::provider怎么用?PHP Validator::provider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Validation\Validator
的用法示例。
在下文中一共展示了Validator::provider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildValidator
public function buildValidator(Event $event, Validator $validator, $name)
{
if ($this->_config['fields']) {
$validator->provider('fileupload', 'WoodyAttachments\\Model\\Validation\\FileUploadValidator');
foreach ($this->_config['fields'] as $field => $fieldOptions) {
$options = array_merge($this->_config['defaultFieldOptions'], $fieldOptions);
if (isset($options['numberOfFiles'])) {
//$field .= '.';
}
if ($options['required']) {
$validator->notEmpty($field, __d('WoodyAttachments', 'This filed is required'), $options['required']);
} else {
$validator->allowEmpty($field, true);
}
$validator->add($field, ['mime' => ['rule' => ['mimeType', $options['allowedFileTypes']], 'message' => __d('WoodyAttachments', 'One of the files is not allowed file type.'), 'provider' => 'fileupload', 'on' => function ($context) use($options, $field) {
return !empty($options['allowedFileTypes']) && !empty($context['data'][$field][0]['tmp_name']) || !empty($options['allowedFileTypes']) && !empty($context['data'][$field]['tmp_name']);
}], 'size' => ['rule' => ['fileSize', '<', $options['fileSize']], 'message' => __d('WoodyAttachments', 'One of the files is too large.'), 'provider' => 'fileupload', 'on' => function ($context) use($options, $field) {
return !is_null($options['fileSize']) && !empty($context['data'][$field][0]['tmp_name']) || !is_null($options['fileSize']) && !empty($context['data'][$field]['tmp_name']);
}], 'error' => ['rule' => ['uploadErrorCheck'], 'message' => __d('WoodyAttachments', 'Upload error.'), 'provider' => 'fileupload', 'on' => function ($context) use($options, $field) {
return !empty($context['data'][$field][0]['tmp_name']) || !empty($context['data'][$field]['tmp_name']);
}]]);
unset($options);
}
return $validator;
}
throw new \BadFunctionCallException(__d('WoodyAttachments', 'You must specify fields field in WoodyAttachmentsUploadBehavior!'));
}
示例2: validationImage
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationImage(Validator $validator)
{
$validator->requirePresence('upload', 'create')->notEmpty('upload');
$validator->add('upload', 'extnesion_check', ['rule' => ['extension'], 'message' => 'Image must be jpg, png or gif.'])->add('upload', 'file_size', ['rule' => ['fileSize', '<', '500Kb'], 'message' => 'Image is not correct dimensions.'])->add('upload', 'mimeType', ['rule' => ['mimeType', ['image/gif', 'image/png', 'image/jpg', 'image/jpeg']], 'message' => 'Image must be jpg, png or gif.']);
$validator->provider('proffer', 'Proffer\\Model\\Validation\\ProfferRules')->add('upload', 'proffer', ['rule' => ['dimensions', ['min' => ['w' => 1, 'h' => 1], 'max' => ['w' => 1920, 'h' => 1920]]], 'message' => 'Image is not correct dimensions.', 'provider' => 'proffer']);
return $validator;
}
示例3: validate
/**
* Validates the internal properties using a validator object and returns any
* validation errors found.
*
* @param \Cake\Validation\Validator $validator The validator to use when validating the entity.
* @return array
*/
public function validate(Validator $validator)
{
$data = $this->_properties;
$new = $this->isNew();
$validator->provider('entity', $this);
$this->errors($validator->errors($data, $new === null ? true : $new));
return $this->_errors;
}
示例4: testMinLength
/**
* test minLength validation.
*
* @return void
*/
public function testMinLength()
{
$validator = new Validator();
$validator->provider('purifier', 'App\\Model\\Validation\\PurifierValidator')->add('biography', 'minLength', ['rule' => ['purifierMinLength', 10], 'provider' => 'purifier', 'message' => 'You fail']);
$expected = ['biography' => ['minLength' => 'You fail']];
$this->assertEquals($expected, $validator->errors(['biography' => 'LessThan9']));
$this->assertEmpty($validator->errors(['biography' => 'more than 10 characteres']));
}
示例5: testMaxDimensionSuccess
/**
* test maxDimension with success validation.
*
* @return void
*/
public function testMaxDimensionSuccess()
{
$file = ['name' => 'avatar.png', 'tmp_name' => TEST_WWW_ROOT . 'img/avatar.png', 'error' => UPLOAD_ERR_OK, 'type' => 'image/png', 'size' => 201];
$expected = ['avatar_file' => ['maxDimension' => 'You fail']];
$this->assertEquals($expected, $this->validator->errors(['avatar_file' => $file]));
$validator = new Validator();
$validator->provider('upload', 'App\\Model\\Validation\\UploadValidator')->add('avatar_file', 'maxDimension', ['rule' => ['maxDimension', 160, 160], 'provider' => 'upload', 'message' => 'You fail']);
$this->assertEmpty($validator->errors(['avatar_file' => $file]));
}
示例6: validationAccount
/**
* Account validation rules.
*
* @param \Cake\Validation\Validator $validator The Validator instance.
*
* @return \Cake\Validation\Validator
*/
public function validationAccount(Validator $validator)
{
return $validator->provider('upload', 'App\\Model\\Validation\\UploadValidator')->provider('purifier', 'App\\Model\\Validation\\PurifierValidator')->allowEmpty('first_name')->add('first_name', 'maxLength', ['rule' => ['maxLength', 100], 'message' => __("Your First Name can not contain more than {0} characters.", 100)])->allowEmpty('last_name')->add('last_name', 'maxLength', ['rule' => ['maxLength', 100], 'message' => __("Your Last Name can not contain more than {0} characters.", 100)])->allowEmpty('avatar_file')->add('avatar_file', ['mimeType' => ['rule' => ['mimeType', ['image/jpeg', 'image/png']], 'message' => __("The mimeType is not allowed."), 'on' => function ($context) {
return !empty($context['data']['avatar_file']['name']);
}], 'fileExtension' => ['rule' => ['extension', ['jpg', 'jpeg', 'png']], 'message' => __("The extensions allowed are {0}.", '.jpg, .jpeg and .png'), 'on' => function ($context) {
return !empty($context['data']['avatar_file']['name']);
}], 'fileSize' => ['rule' => ['fileSize', '<', '500KB'], 'message' => __("The file exceeded the max allowed size of {0}", '500KB'), 'on' => function ($context) {
return !empty($context['data']['avatar_file']['name']);
}], 'maxDimension' => ['rule' => ['maxDimension', 230, 230], 'provider' => 'upload', 'message' => __("The file exceeded the max allowed dimension. Max height : {0} Max width : {1}", 230, 230)]])->allowEmpty('facebook')->add('facebook', 'maxLength', ['rule' => ['maxLength', 200], 'message' => __("Your Facebook can not contain more than {0} characters.", 200)])->allowEmpty('twitter')->add('twitter', 'maxLength', ['rule' => ['maxLength', 200], 'message' => __("Your Twitter can not contain more than {0} characters.", 200)])->allowEmpty('biography')->add('biography', ['purifierMaxLength' => ['rule' => ['purifierMaxLength', 3000], 'provider' => 'purifier', 'message' => __('Your biography can not contain more than {0} characters.', 3000)]])->allowEmpty('signature')->add('signature', ['purifierMaxLength' => ['rule' => ['purifierMaxLength', 300], 'provider' => 'purifier', 'message' => __('Your biography can not contain more than {0} characters.', 300)]]);
}
示例7: validationCreate
/**
* Create validation rules.
*
* @param \Cake\Validation\Validator $validator Instance of the validator.
*
* @return \Cake\Validation\Validator
*/
public function validationCreate(Validator $validator)
{
$validator->provider('upload', 'App\\Model\\Validation\\UploadValidator')->notEmpty('name', __("You must select a name."))->add('name', 'minLength', ['rule' => ['minLength', 5], 'message' => __("Please, {0} characters minimum for the name.", 5)])->allowEmpty('picture_file')->add('picture_file', ['mimeType' => ['rule' => ['mimeType', ['image/jpeg', 'image/png']], 'message' => __("The mimeType is not allowed."), 'on' => function ($context) {
return !empty($context['data']['picture_file']['name']);
}], 'fileExtension' => ['rule' => ['extension', ['jpg', 'jpeg', 'png']], 'message' => __("The extension allowed are {0}.", '.jpg, .jpeg and .png'), 'on' => function ($context) {
return !empty($context['data']['picture_file']['name']);
}], 'fileSize' => ['rule' => ['fileSize', '<', '500KB'], 'message' => __("The file exceeded the max allowed size of {0}", '500KB'), 'on' => function ($context) {
return !empty($context['data']['picture_file']['name']);
}], 'maxDimension' => ['rule' => ['maxDimension', 130, 130], 'provider' => 'upload', 'message' => __("The file exceeded the max allowed dimension. Max height : {0} Max width : {1}", 130, 130)]])->notEmpty('type', __("You must select a type."))->add('type', 'inList', ['rule' => ['inList', ['comments', 'registration']], 'message' => __("This type is not allowed. Allowed types : {0}", implode(", ", ['comments', 'registration']))])->notEmpty('rule', __("You must select a rule."))->add('rule', 'numeric', ['rule' => 'numeric']);
return $validator;
}
示例8: testLocalizedProviderIntegration
/**
* Test the usage of the plugin inside a Validator
*
* @return void
*/
public function testLocalizedProviderIntegration()
{
$validator = new Validator();
$validator->provider('fr', 'Cake\\Localized\\Validation\\FrValidation');
$validator->add('phoneField', 'myCustomRuleNameForPhone', ['rule' => 'phone', 'provider' => 'fr', 'message' => 'Numéro invalide']);
$validator->add('postalField', 'myCustomRuleNameForPostal', ['rule' => 'postal', 'provider' => 'fr']);
$this->assertCount(2, $validator);
$this->assertEmpty($validator->errors(['phoneField' => '05 24 22 72 27', 'postalField' => '93000']));
$errors = $validator->errors(['phoneField' => '924.227.227', 'postalField' => '0000']);
$expected = ['phoneField' => ['myCustomRuleNameForPhone' => 'Numéro invalide'], 'postalField' => ['myCustomRuleNameForPostal' => 'The provided value is invalid']];
$this->assertEquals($expected, $errors);
}
示例9: validationDefault
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator)
{
$validator->provider('proffer', 'Proffer\\Model\\Validation\\ProfferRules');
$validator->add('id', 'valid', ['rule' => 'numeric'])->allowEmpty('id', 'create');
$validator->add('email', 'valid', ['rule' => 'email'])->requirePresence('email', 'create')->notEmpty('email')->add('email', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
$validator->requirePresence('username', 'create')->notEmpty('username')->add('username', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
$validator->requirePresence('password', 'create')->notEmpty('password');
$validator->requirePresence('first_name', 'create')->notEmpty('first_name');
$validator->requirePresence('last_name', 'create')->notEmpty('last_name');
$validator->add('avatar', 'proffer', ['rule' => ['dimensions', ['min' => ['w' => 32, 'h' => 32], 'max' => ['w' => 1024, 'h' => 1024]]], 'message' => 'Avatar image is not in correct dimensions.', 'provider' => 'proffer'])->allowEmpty('avatar');
return $validator;
}
示例10: validationDefault
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator)
{
$validator->add('id', 'valid', ['rule' => 'numeric'])->allowEmpty('id', 'create');
$validator->add('is_primary', 'valid', ['rule' => 'boolean'])->requirePresence('is_primary', 'create')->notEmpty('is_primary');
$validator->requirePresence('filename', 'create')->notEmpty('filename');
$validator->provider('upload', \Josegonzalez\Upload\Validation\DefaultValidation::class);
$fileUploaded = function ($context) {
return !empty($context['data']['filename']) && $context['data']['filename']['error'] == UPLOAD_ERR_OK;
};
$fileUploaded = true;
$validator->add('filename', 'isValidExtension', ['rule' => ['extension', ['jpg', 'jpeg', 'gif', 'png']], 'message' => 'Sorry, your images need to have a filetype of .jpg, .png, or .gif', 'on' => $fileUploaded, 'last' => true])->add('filename', 'fileUnderPhpSizeLimit', ['rule' => 'isUnderPhpSizeLimit', 'message' => 'Sorry, this image exceeds the maximum filesize', 'provider' => 'upload', 'on' => $fileUploaded, 'last' => true])->add('filename', 'fileCompletedUpload', ['rule' => 'isCompletedUpload', 'message' => 'This file could not be uploaded completely', 'provider' => 'upload', 'on' => $fileUploaded, 'last' => true])->add('filename', 'fileFileUpload', ['rule' => 'isFileUpload', 'message' => 'No file was uploaded', 'provider' => 'upload', 'last' => true])->add('filename', 'fileSuccessfulWrite', ['rule' => 'isSuccessfulWrite', 'message' => 'There was an error saving the uploaded file', 'provider' => 'upload', 'on' => $fileUploaded, 'last' => true])->add('filename', 'fileAboveMinHeight', ['rule' => ['isAboveMinHeight', 200], 'message' => 'This image should at least be 200px high', 'provider' => 'upload', 'on' => $fileUploaded])->add('filename', 'fileAboveMinWidth', ['rule' => ['isAboveMinWidth', 200], 'message' => 'This image should at least be 200px wide', 'provider' => 'upload', 'on' => $fileUploaded]);
return $validator;
}
示例11: validationDefault
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator)
{
$validator->add('id', 'valid', ['rule' => 'numeric'])->allowEmpty('id', 'create');
// $validator
// ->add('user_id', 'valid', ['rule' => 'numeric'])
// ->allowEmpty('user_id');
$validator->requirePresence('gender_id', 'create')->notEmpty('gender_id');
$validator->requirePresence('first_name', 'create')->notEmpty('first_name');
$validator->requirePresence('last_name', 'create')->notEmpty('last_name');
$validator->add('birth', 'valid', ['rule' => ['date', 'dmy']])->requirePresence('birth', 'create')->notEmpty('birth');
$validator->requirePresence('phone1', 'create')->notEmpty('phone1');
$validator->allowEmpty('phone2');
$validator->provider('br', BrValidation::class);
$validator->add('uid', 'idVerification', ['rule' => 'personId', 'provider' => 'br'])->allowEmpty('uid');
return $validator;
}
示例12: validationDefault
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator)
{
$validator->provider('extra', new \App\Model\Validation\ExtraValidator());
$validator->add('id', 'valid', ['rule' => 'numeric'])->allowEmpty('id', 'create');
$validator->add('codigo_banco', 'valid', ['rule' => 'numeric'])->allowEmpty('codigo_banco');
$validator->allowEmpty('nome');
$validator->allowEmpty('agencia');
$validator->allowEmpty('conta_corrente');
$validator->add('sequencial_arquivo', 'valid', ['rule' => 'numeric'])->allowEmpty('sequencial_arquivo');
$validator->allowEmpty('caminho_arquivo');
$validator->allowEmpty('sacador_avalista');
$validator->add('cnpj_sacador', 'valid', ['provider' => 'extra', 'rule' => 'moeda', 'message' => __('CNPJ Informado esta invalido')])->allowEmpty('cnpj_sacador');
$validator->allowEmpty('contrato');
$validator->allowEmpty('carteira');
$validator->allowEmpty('convenio');
return $validator;
}
示例13: testValidateUniqueScope
/**
* Tests the validateUnique method with scope
*
* @return void
*/
public function testValidateUniqueScope()
{
$table = TableRegistry::get('Users');
$validator = new Validator();
$validator->add('username', 'unique', ['rule' => ['validateUnique', ['derp' => 'erp', 'scope' => 'id']], 'provider' => 'table']);
$validator->provider('table', $table);
$data = ['username' => 'larry', 'id' => 3];
$this->assertNotEmpty($validator->errors($data));
$data = ['username' => 'larry', 'id' => 1];
$this->assertEmpty($validator->errors($data));
$data = ['username' => 'jose'];
$this->assertEmpty($validator->errors($data));
}
示例14: addNestedMany
/**
* Adds a nested validator.
*
* Nesting validators allows you to define validators for array
* types. For example, nested validators are ideal when you want to validate many
* similar sub-documents or complex array types.
*
* This method assumes that the sub-document has a 1:N relationship with the parent.
*
* The providers of the parent validator will be synced into the nested validator, when
* errors are checked. This ensures that any validation rule providers connected
* in the parent will have the same values in the nested validator when rules are evaluated.
*
* @param string $field The root field for the nested validator.
* @param \Cake\Validation\Validator $validator The nested validator.
* @return $this
*/
public function addNestedMany($field, Validator $validator)
{
$field = $this->field($field);
$field->add(static::NESTED, ['rule' => function ($value, $context) use($validator) {
if (!is_array($value)) {
return false;
}
foreach ($this->providers() as $provider) {
$validator->provider($provider, $this->provider($provider));
}
$errors = [];
foreach ($value as $i => $row) {
if (!is_array($row)) {
return false;
}
$check = $validator->errors($row, $context['newRecord']);
if (!empty($check)) {
$errors[$i] = $check;
}
}
return empty($errors) ? true : $errors;
}]);
return $this;
}
示例15: validationCreate
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationCreate(Validator $validator)
{
$validator->provider('purifier', 'App\\Model\\Validation\\PurifierValidator')->notEmpty('message', __d('conversations', 'You must specify a message for your response.'))->add('message', ['purifierMinLength' => ['rule' => ['purifierMinLength', 5], 'provider' => 'purifier', 'message' => __d('conversations', 'Your message must contain at least {0} characters.', 5)]]);
return $validator;
}