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


PHP Validator::key方法代码示例

本文整理汇总了PHP中Respect\Validation\Validator::key方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::key方法的具体用法?PHP Validator::key怎么用?PHP Validator::key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Respect\Validation\Validator的用法示例。


在下文中一共展示了Validator::key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 public function validate($data)
 {
     $validator = V::key('name', V::string()->length(0, 100), true)->key('email', V::email()->length(0, 200), true)->key('password', V::string()->length(0, 100), true);
     try {
         $validator->assert($data);
         switch ($data['userable_type']) {
             case 'Designer':
                 $this->designerCreationValidator->validate($data);
                 $data['userable_type'] = DesignerModel::class;
                 break;
             case 'Administrator':
                 $this->adminCreationValidator->validate($data);
                 $data['userable_type'] = AdministratorModel::class;
                 break;
             case 'Buyer':
                 $this->buyerCreationValidator->validate($data);
                 $data['userable_type'] = BuyerModel::class;
                 break;
             default:
                 break;
         }
     } catch (AbstractNestedException $e) {
         $errors = $e->findMessages(['email', 'length', 'in']);
         throw new ValidationException('Could not create user.', $errors);
     }
     return true;
 }
开发者ID:HOFB,项目名称:HOFB,代码行数:27,代码来源:UserCreationValidator.php

示例2: testValidatorWithFilterGroups

 public function testValidatorWithFilterGroups()
 {
     $allOfFilter = new AllOfFilter([new ClosureFilter('name', v::intVal()), v::key('key', v::regex('/test.+/i'))]);
     static::assertTrue($allOfFilter->matches(['name' => '1234', 'key' => 'test47382']));
     static::assertFalse($allOfFilter->matches(['name' => 'test', 'key' => 'test47382']));
     static::assertFalse($allOfFilter->matches(['name' => '1234', 'key' => 'test']));
 }
开发者ID:graze,项目名称:array-filter,代码行数:7,代码来源:RespectValidationTest.php

示例3: validateField

 private function validateField($parameters, $fieldName)
 {
     if (v::key($fieldName)->validate($parameters)) {
         if (v::notEmpty()->validate($parameters[$fieldName])) {
             return true;
         }
     }
     return false;
 }
开发者ID:marcoescudeiro,项目名称:erede-acquiring-php,代码行数:9,代码来源:TransactionCreditFindValidator.php

示例4: validate

 public function validate($data)
 {
     $validator = V::key('about', V::string()->length(0, 100), false)->key('website', V::string()->length(0, 100), false)->key('twitter_username', V::string()->length(0, 100), false)->key('facebook_url', V::string()->length(0, 100), false)->key('pinterest_url', V::string()->length(0, 100), false)->key('instagram_username', V::string()->length(0, 100), false);
     try {
         $validator->assert($data);
     } catch (AbstractNestedException $e) {
         $errors = $e->findMessages(['about', 'website', 'twitter_username', 'facebook_url', 'pinterest_url', 'instagram_username']);
         throw new ValidationException('Could not update user.', $errors);
     }
     return true;
 }
开发者ID:HOFB,项目名称:HOFB,代码行数:11,代码来源:DesignerUpdateValidator.php

示例5: validate

 public function validate($data)
 {
     $validator = V::key('retailer_id', V::int()->length(0, 100), true);
     try {
         $validator->assert($data);
     } catch (AbstractNestedException $e) {
         $errors = $e->findMessages(['retailer_id']);
         throw new ValidationException('Could not create user.', $errors);
     }
     return true;
 }
开发者ID:HOFB,项目名称:HOFB,代码行数:11,代码来源:BuyerCreationValidator.php

示例6: validateRequired

 protected function validateRequired($parameters, $fieldNames)
 {
     foreach ($fieldNames as $fieldName) {
         if (!v::key($fieldName)->validate($parameters)) {
             $this->validationResponse->status = s::VALIDATION_ERROR;
             $this->validationResponse->errors[$fieldName] = "is required";
             return false;
         }
     }
     return true;
 }
开发者ID:marcoescudeiro,项目名称:erede-acquiring-php,代码行数:11,代码来源:TransactionCreditValidator.php

示例7: validateParameters

 private static function validateParameters($app, $post)
 {
     if (v::key('email', v::email())->validate($post)) {
         return $app->render(400, array('msg' => 'Invalid email. Check your parameters and try again.'));
     } else {
         if (!v::key('name', v::stringType())->validate($post) || !v::key('subject', v::stringType())->validate($post) || !v::key('message', v::stringType())->validate($post)) {
             return $app->render(400, array('msg' => 'Invalid subject or message. Check your parameters and try again.'));
         }
     }
     return true;
 }
开发者ID:rachellcarbone,项目名称:angular-seed,代码行数:11,代码来源:contactForm.controller.php

示例8: __invoke

 /**
  * Handle domain logic for an action.
  *
  * @param  array $input
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     //Authorize user to be able to view shifts
     $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('entity'), 'view', 'shifts');
     //Validate input
     $inputValidator = v::key('startDateTime', v::stringType())->key('endDateTime', v::stringType());
     $inputValidator->assert($input);
     //Retrieve shifts between in time period
     $shifts = $this->shiftRepository->getShiftsBetween(Carbon::parse($input['startDateTime']), Carbon::parse($input['endDateTime']));
     $this->collection->setData($shifts)->setTransformer($this->shiftTransformer);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($this->collection)->toArray());
 }
开发者ID:sctape,项目名称:rest-scheduler-api,代码行数:18,代码来源:GetShifts.php

示例9: testKeysAsValidatorNames

   public function testKeysAsValidatorNames()
   {
       try {
           Validator::key('username', Validator::length(1, 32))->key('birthdate', Validator::date())->setName("User Subscription Form")->assert(array('username' => '', 'birthdate' => ''));
       } catch (NestedValidationExceptionInterface $e) {
           $this->assertEquals('\\-These rules must pass for User Subscription Form
 |-Key username must be valid
 | \\-"" must have a length between 1 and 32
 \\-Key birthdate must be valid
   \\-"" must be a valid date', $e->getFullMessage());
       }
   }
开发者ID:powerpbx,项目名称:framework,代码行数:12,代码来源:ValidatorTest.php

示例10: __invoke

 /**
  * Handle domain logic for an action.
  *
  * @param  array $input
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     //Check that user has permission to edit this resource
     $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('entity'), 'edit', 'shifts');
     //Validate input
     $inputValidator = v::key('id', v::intVal())->key('employee_id', v::intVal());
     $inputValidator->assert($input);
     //Execute command to update employee on shift
     $shift = $this->commandBus->handle(new AssignShiftCommand($input['id'], $input['employee_id']));
     $shiftItem = new Item($shift, new ShiftTransformer());
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($shiftItem)->toArray());
 }
开发者ID:sctape,项目名称:rest-scheduler-api,代码行数:18,代码来源:AssignShift.php

示例11: __invoke

 /**
  * Handle domain logic for an action.
  *
  * @param  array $input
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     //Check that user is authorized to view this resource
     $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity'), 'view', 'users');
     //Validate input
     $inputValidator = v::key('id', v::intVal());
     $inputValidator->assert($input);
     //Get user from repository and transform into resource
     $user = $this->userRepository->getOneByIdOrFail($input['id']);
     $this->item->setData($user)->setTransformer($this->userTransformer);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($this->item)->toArray());
 }
开发者ID:sctape,项目名称:rest-scheduler-api,代码行数:18,代码来源:GetUsers.php

示例12: __invoke

 /**
  * Handle domain logic for an action.
  *
  * @param  array $input
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     //Check that user is authorized to edit this resource
     $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity'), 'edit', 'shifts');
     //Validate input
     $inputValidator = v::key('break', v::floatVal())->key('start_time', v::stringType())->key('end_time', v::stringType())->key('id', v::intVal());
     $inputValidator->assert($input);
     //Update shift data
     $shift = $this->commandBus->handle(new UpdateShiftCommand($input['id'], $input['break'], $input['start_time'], $input['end_time']));
     $shiftItem = new Item($shift, new ShiftTransformer());
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($shiftItem)->toArray());
 }
开发者ID:sctape,项目名称:rest-scheduler-api,代码行数:18,代码来源:UpdateShift.php

示例13: dispatch

 /**
  * Handle notes validation, creation and update
  *
  * @param  \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
  * @param  \Psr\Http\Message\ResponseInterface      $response PSR7 response
  * @param  callable                                 $next     Next middleware
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function dispatch(Request $request, Response $response, $args)
 {
     $id = isset($args['id']) ? (int) $args['id'] : null;
     $input = $request->getParsedBody();
     $validator = v::key('body', v::stringType()->notEmpty()->length(5, null, true));
     $validator->assert($input);
     if ($id === null) {
         $note = $this->create($input);
     } else {
         $note = $this->update($input, $id);
     }
     return $response->write(json_encode([$note]));
 }
开发者ID:paulochavesbr,项目名称:notes-api,代码行数:22,代码来源:SaveAction.php

示例14: validateAddress

 public function validateAddress($address)
 {
     //@TODO: properly check all types.. strings need to be double checked for alnum, cause of typecasting.
     $rules = v::key('firstname', v::notEmpty()->setName('First name'))->key('lastname', v::notEmpty()->setName('Last name'))->key('address', v::alnum(".,-'")->notEmpty()->setName('Address'))->key('secondary_address', v::when(v::notEmpty(), v::alnum(".,-'"), v::alwaysValid())->setName('Address 2'))->key('city', v::alnum()->notEmpty()->setName('City'))->key('state', v::alnum()->notEmpty()->setName('State'))->key('zip', v::when(v::notEmpty(), v::postalCode('US'), v::alwaysValid())->notEmpty()->setName('Zipcode'));
     if ($rules->validate($address)) {
         return true;
     }
     try {
         $rules->check($address);
     } catch (ValidationExceptionInterface $exception) {
         //            $this->error = $exception->getMainMessage();
     }
     return false;
 }
开发者ID:alldigitalrewards,项目名称:marketplace,代码行数:14,代码来源:ValidationTrait.php

示例15: output

 public function output($request, $response, $args)
 {
     $query = $request->getQueryParams();
     $validator = v::key('a', v::stringType()->length(1, 32))->key('b', v::alnum());
     list($ok, $message) = $this->validate($validator, $query);
     if (!$ok) {
         return $this->view->error('INPUT_ERROR', $message);
     }
     $ret = array();
     for ($i = 0; $i < 4; $i++) {
         $ret[] = array('data' => $i);
     }
     return $this->view->render($ret);
 }
开发者ID:bradelement,项目名称:flash-skeleton,代码行数:14,代码来源:TestController.php


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