本文整理汇总了PHP中Phalcon\Validation::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::validate方法的具体用法?PHP Validation::validate怎么用?PHP Validation::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Validation
的用法示例。
在下文中一共展示了Validation::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInValid
public function testInValid()
{
$array = ['ids' => ['foo@foo.ru', 'bar@bar.ru', 1234]];
$this->validation->add('ids', $this->testable);
$messages = $this->validation->validate($array);
$this->assertEquals(1, count($messages));
}
示例2: validation
public function validation()
{
$validator = new Validation();
$validator->add('creeA', new PresenceOfValidator(array('message' => "La date de création est nécessaire")));
$validator->add('courrierElectronique', new EmailValidator(array('field' => '', 'message' => 'Le courrier électronique est invalide')));
$validator->add('statut', new ExclusionInValidator(array('domain' => array('X', 'Z'), 'message' => 'L\'état ne doit être "X" ou "Z"')));
$validator->add('statut', new InclusionInValidator(array('domain' => array('P', 'I', 'w'), 'message' => 'L\'état doit être "P", "I" ou "w"')));
$validator->add('courrierElectronique', new UniquenessValidator(array('message' => 'Le courrier électronique doit être unique', 'model' => $this)));
$validator->validate('statut', new RegexValidator(array('pattern' => '/[A-Z]/', 'message' => "L'état ne correspond pas à l'expression régulière")));
$validator->validate('courrierElectronique', new StringLengthValidator(array('min' => '7', 'max' => '50', 'messageMinimum' => "Le courrier électronique est trop court", 'messageMaximum' => "Le courrier électronique est trop long")));
return $this->validate($validator);
}
示例3: testCustomMessage
public function testCustomMessage()
{
$this->specify('Test Email validator works with a custom message.', function () {
$validation = new Validation();
$validation->add('email', new Email(['message' => 'The email is not valid']));
$messages = $validation->validate([]);
$expectedMessages = Validation\Message\Group::__set_state(['_messages' => [0 => Validation\Message::__set_state(['_type' => 'Email', '_message' => 'The email is not valid', '_field' => 'email', '_code' => '0'])]]);
$this->assertEquals($expectedMessages, $messages);
$messages = $validation->validate(['email' => 'x=1']);
expect($expectedMessages)->equals($messages);
$messages = $validation->validate(['email' => 'x.x@hotmail.com']);
expect($messages)->count(0);
});
}
示例4: testCustomMessage
public function testCustomMessage()
{
$this->specify('Test URL validator works with a custom message.', function () {
$validation = new Validation();
$validation->add('url', new Validation\Validator\Url(['message' => 'The url is not valid']));
$messages = $validation->validate([]);
$expectedMessages = Validation\Message\Group::__set_state(['_messages' => [0 => Validation\Message::__set_state(['_type' => 'Url', '_message' => 'The url is not valid', '_field' => 'url', '_code' => '0'])]]);
expect($expectedMessages)->equals($messages);
$messages = $validation->validate(['url' => 'x=1']);
expect($expectedMessages)->equals($messages);
$messages = $validation->validate(['url' => 'http://phalconphp.com']);
expect($messages)->count(0);
});
}
示例5: testCustomMessage
public function testCustomMessage()
{
$this->specify('Test Between validator works with a custom message.', function () {
$validation = new Validation();
$validation->add('price', new Between(['minimum' => 1, 'maximum' => 3, 'message' => 'The price must be between 1 and 3']));
$messages = $validation->validate(['price' => 5]);
$expectedMessages = Validation\Message\Group::__set_state(['_messages' => [0 => Validation\Message::__set_state(['_type' => 'Between', '_message' => 'The price must be between 1 and 3', '_field' => 'price', '_code' => '0'])]]);
$this->assertEquals($expectedMessages, $messages);
$messages = $validation->validate([]);
expect($expectedMessages)->equals($messages);
$messages = $validation->validate(['price' => 2]);
expect($messages)->count(0);
});
}
示例6: validate
public function validate(array $data)
{
$messages = parent::validate($data);
if ($messages->count() > 0) {
throw new ValidationException($messages);
}
}
示例7: createAction
public function createAction()
{
$response = new Response();
$response->setHeader('Content-Type', 'application/json');
if ($this->request->isPost()) {
$validation = new Validation();
$validation->add('profilesId', new PresenceOf(array('message' => '请选择一个角色类型')));
$messages = $validation->validate($_POST);
$datas = array();
if (count($messages)) {
foreach ($messages as $message) {
$datas[] = $message->getMessage();
}
$response->setJsonContent(array('status' => 'error', 'messages' => $datas));
} else {
$user = new Users();
$user->assign(array('name' => $this->request->getPost('name', 'striptags'), 'email' => $this->request->getPost('email', 'email'), 'profilesId' => $this->request->getPost('profilesId', 'int')));
if (!$user->save()) {
foreach ($user->getMessages() as $message) {
$datas[] = $message->getMessage();
}
$response->setJsonContent(array('status' => 'error', 'messages' => $datas));
} else {
$response->setJsonContent(array('status' => 'success', 'messages' => '用户添加成功'));
}
}
}
return $response;
}
示例8: signup
public function signup($data)
{
foreach ($data as $k => $v) {
$this->{$k} = $v;
}
$this->confirm = 1;
$validation = new Validation();
$validation->add('email', new Validation\Validator\Email(array('message' => 'Указан не действительный E-mail')));
$validation->add('email', new \App\Library\Validators\Uniqueness(array("model" => 'App\\Models\\Users', "message" => "Такой E-mail уже используется.")));
$validation->add('fname', new Validation\Validator\PresenceOf(array('message' => 'Поле "Имя" должно быть заполнено')));
$validation->add('fname', new Validation\Validator\StringLength(array("max" => 40, 'messageMaximum' => 'Длина текста в поле "' . $this->getLabel('fname') . '" должна быть не более 40 символов')));
$validation->add('lname', new Validation\Validator\StringLength(array("max" => 40, 'messageMaximum' => 'Длина текста в поле "' . $this->getLabel('lname') . '" должна быть не более 40 символов')));
$validation->add('thname', new Validation\Validator\StringLength(array("max" => 40, 'messageMaximum' => 'Длина текста в поле "' . $this->getLabel('thname') . '" должна быть не более 40 символов')));
$validation->add('password', new Validation\Validator\PresenceOf(array('message' => 'Пароль должен быть указан')));
$validation->add('password', new Validation\Validator\Confirmation(array('with' => 'password_confirm', 'message' => '"Пароль" и "Повтор пароля" должны совпадать')));
$messages = $validation->validate($data);
if (count($messages)) {
return $validation->getMessages();
} else {
if ($this->create() === true) {
return true;
} else {
return $this->getMessages();
}
}
}
示例9: indexAction
/**
* User login
*/
public function indexAction()
{
//User has login yet
if ($this->_user) {
$this->session->remove('auth');
unset($_SESSION);
}
$this->_addSocialLogin();
//Regular login
if ($this->request->isPost()) {
$validation = new Validation();
$validation->add('email', new Email());
$messages = $validation->validate($this->request->getPost());
if (count($messages)) {
foreach ($messages as $message) {
$this->flashSession->error($message);
}
$this->response->redirect('/user/login/');
return;
}
$email = strtolower($this->request->getPost('email', 'email'));
$password = $this->request->getPost('password', 'string');
if (Users::login($email, $password)) {
$user = Users::getCurrentUser();
$this->flashSession->success('Hi, ' . $user['full_name']);
$this->response->redirect('/');
} else {
$this->flashSession->error('User or password not match!');
$this->response->redirect('/user/login/');
}
}
}
示例10: indexAction
/**
* Login Action
*/
public function indexAction()
{
//User has login yet
if ($this->_user) {
$this->session->remove('auth');
unset($_SESSION);
}
//Regular login
if ($this->request->isPost()) {
$validation = new Validation();
$validation->add('email', new Email());
$messages = $validation->validate($this->request->getPost());
if (count($messages)) {
foreach ($messages as $message) {
$this->flashSession->error($message);
}
return $this->response->redirect('/admin/user/login/');
}
$email = strtolower($this->request->getPost('email', 'email'));
$password = $this->request->getPost('password', 'string');
if (Users::login($email, $password)) {
$this->response->redirect('/admin/');
} else {
$this->flashSession->error('m_user_message_login__user_or_password_do_not_match');
return $this->response->redirect('/admin/user/login/');
}
}
return null;
}
示例11: testMultipleField
/**
* Tests alnum validator with multiple field
*
* @author Wojciech Ślawski <jurigag@gmail.com>
* @since 2016-06-05
*/
public function testMultipleField()
{
$this->specify('Test alnum validator with multiple field.', function () {
$validation = new Validation();
$validationMessages = ['name' => 'Name must be alnum', 'type' => 'Type must be alnum'];
$validation->add(['name', 'type'], new Alnum(['message' => $validationMessages]));
$messages = $validation->validate(['name' => 'SomeValue123', 'type' => 'SomeValue123']);
expect($messages->count())->equals(0);
$messages = $validation->validate(['name' => 'SomeValue123!@#', 'type' => 'SomeValue123']);
expect($messages->count())->equals(1);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['name']);
$messages = $validation->validate(['name' => 'SomeValue123!@#', 'type' => 'SomeValue123!@#']);
expect($messages->count())->equals(2);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['name']);
expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['type']);
});
}
示例12: testMultipleField
/**
* Tests numericality validator with multiple field
*
* @author Wojciech Ślawski <jurigag@gmail.com>
* @since 2016-06-05
*/
public function testMultipleField()
{
$this->specify('Test numericality validator with multiple field', function () {
$validation = new Validation();
$validationMessages = ['amount' => 'Amount must be digit.', 'price' => 'Price must be digit.'];
$validation->add(['amount', 'price'], new Numericality(['message' => $validationMessages]));
$messages = $validation->validate(['amount' => 123, 'price' => 123]);
expect($messages->count())->equals(0);
$messages = $validation->validate(['amount' => '123abc', 'price' => 123]);
expect($messages->count())->equals(1);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['amount']);
$messages = $validation->validate(['amount' => '123abc', 'price' => '123abc']);
expect($messages->count())->equals(2);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['amount']);
expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['price']);
});
}
示例13: testMultipleField
/**
* Tests between validator with multiple field
*
* @author Wojciech Ślawski <jurigag@gmail.com>
* @since 2016-06-05
*/
public function testMultipleField()
{
$this->specify('Test between validator with multiple field.', function () {
$validation = new Validation();
$validationMessages = ['amount' => 'Amount must be between 0 and 999.', 'price' => 'Price must be between 0 and 999.'];
$validation->add(['amount', 'price'], new Between(['minimum' => ['amount' => 0, 'price' => 0], 'maximum' => ['amount' => 999, 'price' => 999], 'message' => $validationMessages]));
$messages = $validation->validate(['amount' => 100]);
expect($messages->count())->equals(0);
$messages = $validation->validate(['amount' => 1000, 'price' => 100]);
expect($messages->count())->equals(1);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['amount']);
$messages = $validation->validate(['amount' => 1000, 'price' => 1000]);
expect($messages->count())->equals(2);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['amount']);
expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['price']);
});
}
示例14: testMultipleField
/**
* Tests url validator with multiple field
*
* @author Wojciech Ślawski <jurigag@gmail.com>
* @since 2016-06-05
*/
public function testMultipleField()
{
$this->specify('Test url validator with multiple field.', function () {
$validation = new Validation();
$validationMessages = ['url' => 'Url must be correct url.', 'anotherUrl' => 'AnotherUrl must be correct url.'];
$validation->add(['url', 'anotherUrl'], new Validation\Validator\Url(['message' => $validationMessages]));
$messages = $validation->validate(['url' => 'http://google.com', 'anotherUrl' => 'http://google.com']);
expect($messages->count())->equals(0);
$messages = $validation->validate(['url' => '://google.', 'anotherUrl' => 'http://google.com']);
expect($messages->count())->equals(1);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['url']);
$messages = $validation->validate(['url' => '://google.', 'anotherUrl' => '://google.']);
expect($messages->count())->equals(2);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['url']);
expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['anotherUrl']);
});
}
示例15: testMultipleField
/**
* Tests email validator with multiple field
*
* @author Wojciech Ślawski <jurigag@gmail.com>
* @since 2016-06-05
*/
public function testMultipleField()
{
$this->specify('Test email validator with multiple field.', function () {
$validation = new Validation();
$validationMessages = ['email' => 'Email must be correct email.', 'anotherEmail' => 'AnotherEmail must be correct email.'];
$validation->add(['email', 'anotherEmail'], new Email(['message' => $validationMessages]));
$messages = $validation->validate(['email' => 'test@somemail.com', 'anotherEmail' => 'test@somemail.com']);
expect($messages->count())->equals(0);
$messages = $validation->validate(['email' => 'rootlocalhost', 'anotherEmail' => 'test@somemail.com']);
expect($messages->count())->equals(1);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['email']);
$messages = $validation->validate(['email' => 'rootlocalhost', 'anotherEmail' => 'rootlocalhost']);
expect($messages->count())->equals(2);
expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['email']);
expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['anotherEmail']);
});
}