本文整理汇总了PHP中Respect\Validation\Validator::equals方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::equals方法的具体用法?PHP Validator::equals怎么用?PHP Validator::equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::equals方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
public function isValid($validation_data)
{
$errors = [];
foreach ($validation_data as $name => $value) {
if (isset($_REQUEST[$name])) {
$rules = explode("|", $value);
foreach ($rules as $rule) {
$exploded = explode(":", $rule);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::stringType()->length($min)->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " must be at least " . $min . " characters long";
}
break;
case 'email':
if (Valid::email()->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " must be a valid email ";
}
break;
case 'equalTo':
if (Valid::equals($_REQUEST[$name])->Validate($_REQUEST[$exploded[1]]) == false) {
$errors[] = "Values do not match";
}
break;
default:
//do nothing
}
}
} else {
$errors = "No value found";
}
}
return $errors;
}
示例2: isValid
public function isValid($validation_data)
{
$errors = [];
foreach ($validation_data as $name => $value) {
$rules = explode("|", $value);
foreach ($rules as $rule) {
$exploded = explode(":", $rule);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::stringType()->length($min, null)->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " must be at least " . $min . " characters long!";
}
break;
case 'email':
if (Valid::email()->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " must be a valid email address!";
}
break;
case 'equalTo':
if (Valid::equals($_REQUEST[$name])->Validate($_REQUEST[$exploded[1]]) == false) {
$errors[] = "Value does not match verification value!";
}
break;
default:
$errors[] = "No value found!";
}
}
}
return $errors;
}
示例3: isValid
public function isValid($validation_data)
{
$errors = [];
foreach ($validation_data as $name => $value) {
$exploded = explode(":", $value);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::stringType()->length($min, null)->Validate($_REQUEST[$name]) == false) {
$errors[] = $exploded[2] . " must be at least " . $min . " characters long ";
}
break;
case 'email':
if (Valid::email()->Validate($_REQUEST[$name]) == false) {
$errors[] = "Please enter a valid email";
}
break;
case 'equalTo':
if (Valid::equals($_REQUEST[$name])->Validate($_REQUEST[$exploded[1]]) == false) {
$errors[] = $exploded[2] . " value does not match " . $exploded[3] . " value";
}
break;
default:
//do nothing
$errors[] = "No values found";
}
}
return $errors;
}
示例4: isValid
public function isValid($validation_data)
{
$errors = "";
foreach ($validation_data as $name => $value) {
$rules = explode("|", $value);
foreach ($rules as $rule) {
$exploded = explode(":", $rule);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::alpha()->length($min)->Validate($_POST[$name]) == false) {
$errors[] = $name . " must be at least " . $exploded[1] . " characters long!";
}
break;
case 'email':
if (Valid::email()->validate($_POST[$name]) == false) {
$errors[] = $name . " must be a valid email address!";
}
break;
case 'equalTo':
if (Valid::equals($_POST[$name])->validate($_POST[$exploded[1]]) == false) {
$errors[] = $name . "'s don't match!";
}
break;
default:
$errors[] = "No value found!";
break;
}
}
}
return $errors;
}
示例5: post
public function post($request, $response, $service, $app)
{
Auth::restrictAccess('anonymous');
$app->users = new Users();
$app->passwordResets = new PasswordResets();
$email = $request->param('email');
$token = $request->param('token');
$passwordReset = self::validatePasswordResetRequest($email, $token);
$body = json_decode($request->body());
$newPassword = $body->newPassword;
$confirmPassword = $body->confirmPassword;
if (!v::length(6, 55)->validate($newPassword)) {
return 'password 1 dont comply';
}
if (!v::length(6, 55)->validate($confirmPassword)) {
return 'password 2 dont comply';
}
if (!v::equals($newPassword)->validate($confirmPassword)) {
return 'passwords dont match';
}
// user update password
$app->users->updatePassword($passwordReset['userId'], $newPassword);
// delete the passwordReset row after use
$app->passwordResets->destroy($passwordReset['id']);
}
示例6: create
/**
* Creates a new {@link LightInstruction}, verifying the action is valid and exactly two
* coordinates have been given.
*
* @param int $action {@link LightInstructionAction}
* @param Coordinate[] $coordinatePair two coordinates
* @return LightInstruction
* @throws \InvalidArgumentException
*/
public static function create($action, array $coordinatePair)
{
v::oneOf(v::equals(LightInstructionAction::TURN_ON), v::equals(LightInstructionAction::TURN_OFF), v::equals(LightInstructionAction::TOGGLE))->check($action);
v::length(2, 2)->check($coordinatePair);
v::each(v::instance('\\Hamdrew\\AdventOfCode\\Day6\\Coordinate'))->check($coordinatePair);
return new LightInstruction($action, $coordinatePair);
}
示例7: isValid
public function isValid($validation_data)
{
$errors = [];
foreach ($validation_data as $name => $value) {
$rules = explode("|", $value);
foreach ($rules as $rule) {
$exploded = explode(":", $rule);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::string()->length($min, null)->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " must be at least " . $min . " characters long.";
}
break;
case 'max':
$max = $exploded[1];
if (Valid::string()->length(null, $max)->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . " cannot be more than " . $max . " characters long.";
}
break;
case 'email':
if (Valid::email()->Validate($_REQUEST[$name]) == false) {
$errors[] = "Must be a valid email address.";
}
break;
case 'equalTo':
if (Valid::equals($_REQUEST[$name])->Validate($_REQUEST[$exploded[1]]) == false) {
$errors[] = "Values do not match.";
}
break;
// check to see if already exists in database
// check to see if already exists in database
case 'unique':
$model = "Acme\\models\\" . $exploded[1];
$table = new $model();
$results = $table::where($name, '=', $_REQUEST[$name])->get();
foreach ($results as $item) {
$errors[] = $_REQUEST[$name] . " already exists in this system.";
}
break;
default:
$errors[] = "No value found.";
}
}
}
return $errors;
}
示例8: isValid
public function isValid($validation_data)
{
$errors = [];
foreach ($validation_data as $name => $value) {
$rules = explode('|', $value);
foreach ($rules as $rule) {
$exploded = explode(':', $rule);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::stringType()->length($min)->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . ' must be at least ' . $min . ' characters long!';
}
break;
case 'email':
if (Valid::email()->Validate($_REQUEST[$name]) == false) {
$errors[] = $name . ' must be a valid email address!';
}
break;
case 'equalTo':
if (Valid::equals($_REQUEST[$name])->Validate($_REQUEST[$exploded[1]]) == false) {
$errors[] = 'Value does not match the verification value';
}
break;
case 'unique':
$model = "Acme\\models\\" . $exploded[1];
$table = new $model();
$results = $table->where($name, '=', $_REQUEST[$name])->get();
foreach ($results as $result) {
$errors[] = $_REQUEST[$name] . " already exists in this system!";
}
break;
default:
$errors = 'No value found';
break;
}
}
}
return $errors;
}
示例9: check
/**
* @param $validation_data
* @return array
*/
public function check($validation_data)
{
$errors = [];
foreach ($validation_data as $name => $value) {
$rules = explode("|", $value);
foreach ($rules as $rule) {
$exploded = explode(":", $rule);
switch ($exploded[0]) {
case 'min':
$min = $exploded[1];
if (Valid::stringType()->length($min)->Validate($this->request->input($name)) == false) {
$errors[] = $name . " must be at least " . $min . " characters long!";
}
break;
case 'email':
if (Valid::email()->Validate($this->request->input($name)) == false) {
$errors[] = $name . " must be a valid email!";
}
break;
case 'equalTo':
if (Valid::equals($this->request->input($name))->Validate($this->request->input($exploded[1])) == false) {
$errors[] = "Value does not match verification value!";
}
break;
case 'unique':
$model = "Acme\\models\\" . $exploded[1];
$table = new $model();
$results = $this->getRows($table, $name);
foreach ($results as $item) {
$errors[] = $this->request->input($name) . " already exists in this system!";
}
break;
default:
$errors[] = "No value found!";
}
}
}
return $errors;
}
示例10: equals
/**
* 检测是否为特定值
*
* @param string $value
* @param string $required 要比较的值
* @param bool $strict
* @return bool
*/
public static function equals($value, $required, $strict = false)
{
return Validator::equals($value, $strict)->validate($required);
}
示例11: validateForm
private function validateForm($params)
{
if (!v::notEmpty()->validate($params['first_name'])) {
return ['isValid' => false, 'message' => 'First name is required.'];
}
if (!v::notEmpty()->validate($params['last_name'])) {
return ['isValid' => false, 'message' => 'Last name is required.'];
}
if (!v::notEmpty()->validate($params['email'])) {
return ['isValid' => false, 'message' => 'Email is required.'];
}
if (!v::email()->validate($params['email'])) {
return ['isValid' => false, 'message' => 'Business Email should be a valid email.'];
}
if (!v::notEmpty()->validate($params['password'])) {
return ['isValid' => false, 'message' => 'Password is required.'];
}
if (!v::equals($params['confirm_password'])->validate($params['password'])) {
return ['isValid' => false, 'message' => 'Password mismatched.'];
}
return ['isValid' => true, 'message' => 'User saved.'];
}
示例12: function
<?php
require_once ROOT . 'models/model.php';
use Respect\Validation\Validator as v;
$validateSignup = function () use($app) {
$req = $app->request();
$data = $req->post();
$validator = v::key('domain', v::domain()->notEmpty())->key('username', v::string()->notEmpty()->length(1, 32))->key('email', v::email()->notEmpty())->key('nick', v::string()->notEmpty()->length(1, 32))->key('password', v::string()->notEmpty()->length(6, 20))->key('password_confirm', v::equals($data['password'])->notEmpty());
try {
$validator->assert($data);
} catch (\InvalidArgumentException $e) {
$errors = $e->findMessages(array('domain' => '网站域名不能为空', 'username' => '账户只能是英文字符和数字', 'email' => '邮箱格式不正确', 'nick' => '用户名称不能为空', 'password' => '密码不能少于6个字符', 'password_confirm' => '两次输入的密码不一致'));
$app->flash('errors', $errors);
$app->redirect(SITE_URL . '/signup');
}
};
/**
*-------------------------------------------
* User Signup
*-------------------------------------------
*/
$app->get('/signup', function () use($app) {
$app->render("signup.html");
})->name('signup');
$app->post('/signup', $validateSignup, function () use($app) {
// $this->halt('500', "Signup Not Supported Now");
$req = $app->request();
$data = $req->post();
$error = null;
$user = ORM::forTable('users')->where('email', $data['email'])->findOne();
if ($user) {
示例13: validateEqualTo
private function validateEqualTo($item, $value, $parameter)
{
if (Valid::equals($_POST[$item])->validate($_POST[$parameter]) == false) {
$this->errors[] = $this->formatName($item) . ' field does not match the ' . $this->formatName($parameter) . ' field.';
}
}
示例14: XenResponse
/**
* This parse the xml response and return the response obj
*
* @param mixed $response,
*
*
* @return XenResponse
*/
function xenrpc_parseresponse($response)
{
if (!Validator::arr()->validate($response) && !Validator::key('Status')->validate($request)) {
return new XenResponse($response);
} else {
if (Validator::key('Status', Validator::equals('Success'))->validate($response)) {
return new XenResponse($response);
} else {
if ($response['ErrorDescription'][0] == 'SESSION_INVALID') {
$response = $this->xenrpc_request($url, $this->xenrpc_method('session.login_with_password', array($this->_user, $this->_password, '1.3.1')));
if (Validator::arr()->validate($response) && Validator::key('Status', Validator::equals('Success'))->validate($response)) {
$this->_setSessionId($response['Value']);
} else {
return new XenResponse($response);
}
} else {
return new XenResponse($response);
}
}
}
return new XenResponse($response);
}