本文整理汇总了PHP中SimpleValidator\Validator::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::validate方法的具体用法?PHP Validator::validate怎么用?PHP Validator::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleValidator\Validator
的用法示例。
在下文中一共展示了Validator::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInvalidValidation
public function testInvalidValidation()
{
$rules = array('test1' => array('rule1(:test2,3,:test3)' => function ($input, $test2, $value, $test3) {
if ($input == "test data 1" && $value == 3 && $test2 == "test data 1" && $test3 == "test data 1") {
return true;
}
return false;
}));
$naming = array('test2' => 'Test 2');
$validation = \SimpleValidator\Validator::validate($this->test_data, $rules, $naming);
$this->assertFalse($validation->isSuccess());
$validation->customErrors(array('rule1' => "Foo :params(0) bar :params(1) baz :params(2)"));
$errors = $validation->getErrors();
$this->assertEquals("Foo Test 2 bar 3 baz test3", $errors[0]);
}
示例2: validate
public function validate($data)
{
$obj = $this;
$rules = array(':book_type' => array('required', 'integer', 'type_exists' => function ($input) use($obj) {
return $obj->checkExist('type_id', ':type_id', 'types', $input);
}), ':book_city' => array('required', 'integer', 'city_exists' => function ($input) use($obj) {
return $obj->checkExist('city_id', ':city_id', 'cities', $input);
}), ':book_size' => array('required', 'integer', 'size_exists' => function ($input) use($obj) {
return $obj->checkExist('size_id', ':size_id', 'sizes', $input);
}), ':book_address' => array('required'), ':book_coordinate_lat' => array('required'));
$names = [':book_address' => 'Adresas'];
$validate = \SimpleValidator\Validator::validate($data, $rules, $names);
if ($validate->isSuccess() == true) {
$response = ['success' => 'true'];
return $response;
} else {
$validate->customErrors(['required' => '\':attribute\' Laukas yra privalomas', ':book_coordinate_lat.required' => 'Prašome patikslinti vietą', 'integer' => 'Reikšmė turi būti skaičius', 'type_exists' => 'Blogai pasirinktas tipas', 'city_exists' => 'Blogai pasirinktas miestas', 'size_exists' => 'Blogai pasirinktas dydis']);
$response = ['success' => 'false', 'errors' => $validate->getErrors()];
return $response;
}
}
示例3: function
<?php
/**
* @author Gaaaab
*/
use App\Http\Model\Contact;
use Tamtamchik\SimpleFlash\Flash;
$app->get('/contact', function () use($app) {
$app->render('site/contacts/contact.php');
})->name('contact.index');
$app->post('/contact', function () use($app) {
// Mail
$mail = new \Mailgun\Mailgun(MAILGUN_KEY);
// Validation
$rules = ['name' => ['required', 'alpha', 'min_length(3)', 'max_length(60)'], 'email' => ['email', 'required'], 'content' => ['required']];
$input = ['name' => $app->request->post('name'), 'email' => $app->request->post('email'), 'content' => $app->request->post('content')];
$validation_result = \SimpleValidator\Validator::validate($_POST, $rules);
if ($validation_result->isSuccess()) {
$contact = new Contact();
$contact->name = $app->request->post('name');
$contact->email = $app->request->post('email');
$contact->content = $app->request->post('content');
// Saving it to database? not necessary but WTH not =3
$contact->save();
$mail->sendMessage(MAILGUN_DOMAIN, array('from' => MAIL_FROM, 'to' => MAIL_TO, 'subject' => 'SHARE SOMETHING SUPPORT: CONTACT RESPONSE', 'text' => 'Contact request from: ' . $app->request->post('name') . '\\n' . 'Email: ' . $app->request->post('email') . '\\n' . 'Content: ' . ' ' . $app->request->post('content')));
$app->redirectTo('site.index');
} else {
require_once __DIR__ . '/../errors.php';
}
})->name('contact.post');