当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::create方法代码示例

本文整理汇总了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];
 }
开发者ID:pmill,项目名称:doctrine-rest-api,代码行数:20,代码来源:AuthenticationController.php

示例2: testStaticCreateShouldReturnNewValidator

 public function testStaticCreateShouldReturnNewValidator()
 {
     $this->assertInstanceOf(Validator::class, Validator::create());
 }
开发者ID:respect,项目名称:validation,代码行数:4,代码来源:ValidatorTest.php

示例3: testStaticCreateShouldReturnNewValidator

 public function testStaticCreateShouldReturnNewValidator()
 {
     $this->assertInstanceOf('Respect\\Validation\\Validator', Validator::create());
 }
开发者ID:00F100,项目名称:Validation,代码行数:4,代码来源:ValidatorTest.php

示例4: validator

 protected function validator()
 {
     return Validator::create();
 }
开发者ID:barryosull,项目名称:valueobjects,代码行数:4,代码来源:AbstractValueObject.php

示例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();
     }
 }
开发者ID:JohnUiterwyk,项目名称:journey-planner,代码行数:33,代码来源:UsersController.php

示例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();
     }
 }
开发者ID:JohnUiterwyk,项目名称:journey-planner,代码行数:27,代码来源:TripsController.php


注:本文中的Respect\Validation\Validator::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。