本文整理汇总了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;
}
示例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']));
}
示例3: validateField
private function validateField($parameters, $fieldName)
{
if (v::key($fieldName)->validate($parameters)) {
if (v::notEmpty()->validate($parameters[$fieldName])) {
return true;
}
}
return false;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
}
示例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());
}
示例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());
}
示例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());
}
示例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]));
}
示例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;
}
示例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);
}