Skip to content

Commit

Permalink
rename validatePresence to requirePresence.
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Nov 13, 2014
1 parent ae59fb5 commit 85beeb2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ORM/Table.php
Expand Up @@ -1020,7 +1020,7 @@ public function updateAll($fields, $conditions) {
* return $validator
* ->add('email', 'valid-email', ['rule' => 'email'])
* ->add('password', 'valid', ['rule' => 'notEmpty'])
* ->validatePresence('username');
* ->requirePresence('username');
* }
* }}}
*
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Bake/default/classes/table.ctp
Expand Up @@ -115,7 +115,7 @@ foreach ($validation as $field => $rules):
);
else:
$validationMethods[] = sprintf(
"->validatePresence('%s', 'create')",
"->requirePresence('%s', 'create')",
$field
);
$validationMethods[] = sprintf(
Expand Down
6 changes: 3 additions & 3 deletions src/Validation/README.md
Expand Up @@ -13,14 +13,14 @@ use Cake\Validation\Validator;

$validator = new Validator();
$validator
->validatePresence('email')
->requirePresence('email')
->add('email', 'validFormat', [
'rule' => 'email',
'message' => 'E-mail must be valid'
])
->validatePresence('name')
->requirePresence('name')
->notEmpty('name', 'We need your name.')
->validatePresence('comment')
->requirePresence('comment')
->notEmpty('comment', 'You need to give a comment.');

$errors = $validator->errors($_POST);
Expand Down
18 changes: 17 additions & 1 deletion src/Validation/Validator.php
Expand Up @@ -323,14 +323,30 @@ public function remove($field, $rule = null) {
* is required.
* @return Validator this instance
*/
public function validatePresence($field, $mode = true, $message = null) {
public function requirePresence($field, $mode = true, $message = null) {
$this->field($field)->isPresenceRequired($mode);
if ($message) {
$this->_presenceMessages[$field] = $message;
}
return $this;
}

/**
* Sets whether a field is required to be present in data array.
*
* Alias for requirePresence().
*
* @param string $field the name of the field
* @param bool|string $mode Valid values are true, false, 'create', 'update'
* @param string $message The validation message to show if the field presence
* is required.
* @return Validator this instance
* @deprecated 3.0.0 Will be removed in 3.0.0.
*/
public function validatePresence($field, $mode = true, $message = null) {
return $this->requirePresence($field, $mode, $message);
}

/**
* Allows a field to be empty.
*
Expand Down

0 comments on commit 85beeb2

Please sign in to comment.