本文整理汇总了PHP中Respect\Validation\Validator::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::create方法的具体用法?PHP Validator::create怎么用?PHP Validator::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
/**
* @RPC\Route("/api/auth/login")
* @RPC\Method("POST")
*/
public function login()
{
$credentials = json_decode($this->request->getContent(), true);
try {
v::create()->key('email', v::notEmpty())->key('password', v::notEmpty())->assert($credentials);
} catch (ValidationException $e) {
$errors = $e->findMessages(['email', 'password']);
throw new \pmill\Doctrine\Rest\Exception\ValidationException($errors);
}
$password = $credentials['password'];
unset($credentials['password']);
/** @var User $user */
$user = $this->authenticationService->authenticateWithCredentials(User::class, $credentials, $password);
$token = $this->authenticationService->generateTokenFromObject($user);
return ['token' => $token];
}
示例2: testStaticCreateShouldReturnNewValidator
public function testStaticCreateShouldReturnNewValidator()
{
$this->assertInstanceOf(Validator::class, Validator::create());
}
示例3: testStaticCreateShouldReturnNewValidator
public function testStaticCreateShouldReturnNewValidator()
{
$this->assertInstanceOf('Respect\\Validation\\Validator', Validator::create());
}
示例4: validator
protected function validator()
{
return Validator::create();
}
示例5: updateUser
/**
* @param $data array
*
*/
public function updateUser(array $data)
{
$stringValidator = v::stringType()->length(1, 128);
$idValidator = v::numeric();
$userValidator = v::create();
$userValidator->key('id', $idValidator);
$userValidator->key('username', $stringValidator);
$userValidator->key('fullname', $stringValidator);
$userValidator->key('password', $stringValidator, false);
//optional
try {
$userValidator->assert($data);
} catch (NestedValidationException $exception) {
$this->writeFail($exception->getFullMessage());
return;
}
//see if username is changing if so, check it is available
$currentUserData = UserModel::getUser($data['id']);
if ($data['username'] !== $currentUserData['username'] && UserModel::isUsernameAvailable($data['username'])) {
$this->writeFail(["Username is not available"]);
return;
}
//then check the current user is either admin or editing his own
if ($this->isUserAuthenticated() && ($this->currentUser->isAdmin() || $this->currentUser->id === $data["id"])) {
UserModel::updateUser($data);
} else {
$this->writeUnauthorized();
}
}
示例6: updateTrip
private function updateTrip($data)
{
// Create validators
$stringValidator = v::create();
$stringValidator->stringType();
$idValidator = v::numeric();
$dateValidator = v::date('Y-m-d');
$tripValidator = v::create();
$tripValidator->key('user_id', $idValidator);
$tripValidator->key('destination', $stringValidator);
$tripValidator->key('start_date', $dateValidator);
$tripValidator->key('end_date', $dateValidator);
$tripValidator->key('comment', $stringValidator);
// run validation
try {
$tripValidator->assert($data);
} catch (NestedValidationException $exception) {
$this->writeFail($exception->getFullMessage());
return;
}
//then check the current user is either admin or editing his own
if ($this->isUserAuthenticated() && ($this->currentUser->isAdmin() || $this->currentUser->id === $data["user_id"])) {
TripModel::updateTrip($data);
} else {
$this->writeUnauthorized();
}
}