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'])); }
/** * init valid rule */ protected function initRule() { $this->validRule['id'] = v::numeric(); $this->validRule['name'] = v::stringType()->length(1, 10); $this->validRule['email'] = v::email(); $this->validRule['sex'] = v::intVal()->between(0, 1); }
protected function validateLevel() { $value = v::intVal()->notEmpty()->validate($this->getLevel()); if (!$value) { msg::showMsg('O campo Nível de Acesso deve ser deve ser preenchido corretamente.' . '<script>focusOn("level");</script>', 'danger'); } return $this; }
static function deleteUser($app, $userId) { if (!v::intVal()->validate($userId)) { return $app->render(400, array('msg' => 'Could not find user. Check your parameters and try again.')); } if (UserData::deleteUser($userId)) { return $app->render(200, array('msg' => 'User has been deleted.')); } else { return $app->render(400, array('msg' => 'Could not delete user.')); } }
/** * 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()); }
static function deleteRole($app, $roleId) { if (!v::intVal()->validate($roleId)) { return $app->render(400, array('msg' => 'Could not delete role. Check your parameters and try again.')); } else { if (RoleData::deleteRole($roleId)) { return $app->render(200, array('msg' => 'Role has been deleted.')); } else { return $app->render(400, array('msg' => 'Could not delete role.')); } } }
/** * 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()); }
/** * 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()); }
static function deleteGroup($app, $groupId) { if (!v::intVal()->validate($groupId)) { return $app->render(400, array('msg' => 'Could not delete group. Check your parameters and try again.')); } else { if (GroupData::deleteGroup($groupId)) { return $app->render(200, array('msg' => 'Group has been deleted.')); } else { return $app->render(400, array('msg' => 'Could not delete group.')); } } }
/** * init valid rule */ protected function initRule() { $this->validRule['uid'] = v::numeric(); $this->validRule['eduid'] = v::numeric(); $this->validRule['schoolName'] = v::stringType()->length(1, 32); $this->validRule['majorName'] = v::stringType()->length(1, 32); $this->validRule['majorCat'] = v::stringType()->length(1, 32); $this->validRule['area'] = v::stringType()->length(1, 32); $this->validRule['schoolCountry'] = v::stringType()->length(1, 32); $this->validRule['startDate'] = v::date('Y-m'); $this->validRule['endDate'] = v::date('Y-m'); $this->validRule['degreeStatus'] = v::intVal()->between(1, 3); }
/** * Handle domain logic for an action. * * @param array $input * @return PayloadInterface */ public function __invoke(array $input) { //Ensure that the use has permission to create shifts $user = $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity'); $this->authorizeUser($user, 'create', 'shifts'); //If no manager_id is specified in request, default to user creating shift if (!array_key_exists('manager_id', $input)) { $input['manager_id'] = $user->getId(); } //Validate input $inputValidator = v::key('break', v::floatVal())->key('start_time', v::date())->key('end_time', v::date()->min($input['start_time']))->key('manager_id', v::intVal()); $inputValidator->assert($input); //Execute command to create shift $shift = $this->commandBus->handle(new CreateShift($input['manager_id'], $input['employee_id'], $input['break'], $input['start_time'], $input['end_time'])); $this->item->setData($shift)->setTransformer($this->shiftTransformer); return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($this->item)->toArray()); }
/** * @param array $input * @return PayloadInterface * @throws UserNotAuthorized */ public function __invoke(array $input) { //Don't allow employees to view other employee's shifts //todo: figure out if managers can access all employees' shifts if ($input['id'] != $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('id')) { throw new UserNotAuthorized(); } //Validate input $inputValidator = v::key('id', v::intVal()); $inputValidator->assert($input); //Get shifts and transform $employee = $this->userRepository->getOneByIdOrFail($input['id']); $shifts = $this->shiftRepository->getByEmployee($employee); $this->collection->setData($shifts)->setTransformer($this->shiftTransformer); $include = array_key_exists('include', $input) ? $input['include'] : ''; return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes($include)->createData($this->collection)->toArray()); }
static function deleteVariable($app, $variableId) { if (!v::intVal()->validate($variableId)) { return $app->render(400, array('msg' => 'Could not find system config variable.')); } $savedConfig = ConfigData::getVariableById($variableId); if ($savedConfig && ($savedConfig->locked || $savedConfig->indestructible)) { return $app->render(400, array('msg' => 'This config variable is locked or indestructible and cannot deleted without special permissions.')); } if (ConfigData::deleteVariable($variableId)) { return $app->render(200, array('msg' => 'System config variable has been deleted.')); } else { return $app->render(400, array('msg' => 'Could not delete system config variable. Check your parameters and try again.')); } }
use DI\ContainerBuilder; use Respect\Validation\Validator; require __DIR__ . '/bootstrap.php'; $builder = new ContainerBuilder(); $container = $builder->buildDevContainer(); $argc = $_SERVER['argc']; $argv = $_SERVER['argv']; $minDay = 1; $maxDay = 25; if ($argc > 2) { error_log('Usage: php SolutionRunner.php [day]'); exit(1); } if ($argc == 2) { $day = intval($argv[1]); if (!Validator::intVal()->between($minDay, $maxDay)->validate($day)) { error_log("Day must be between {$minDay} and {$maxDay}"); exit(1); } $minDay = $day; $maxDay = $day; } for ($i = $minDay; $i <= $maxDay; $i++) { echo "Running solution for Day {$i}...\n"; /** @var Solution $class */ $class = "\\Hamdrew\\AdventOfCode\\Day{$i}\\SolutionDay{$i}"; if (!class_exists($class)) { echo "WARNING: Solution for day {$i} not found\n"; return; } $part1 = $container->get($class)->part1();
public function providerForInvalidNot() { return [[new IntVal(), 123], [new AllOf(new OneOf(new Numeric(), new IntVal())), 13.37], [new OneOf(new Numeric(), new IntVal()), 13.37], [Validator::oneOf(Validator::numeric(), Validator::intVal()), 13.37]]; }
static function deleteField($app, $fieldId) { if (!v::intVal()->validate($fieldId)) { return $app->render(400, array('msg' => 'Could not delete field. Check your parameters and try again.')); } else { if (FieldData::deleteField($fieldId)) { return $app->render(200, array('msg' => 'Field has been deleted.')); } else { return $app->render(400, array('msg' => 'Could not delete field.')); } } }
static function declineTeamInvite($app) { $post = $app->request->post(); if (!v::key('inviteToken', v::stringType())->validate($post) || !v::key('userId', v::intVal())->validate($post) || !v::key('teamId', v::intVal())->validate($post)) { return $app->render(400, array('msg' => 'Invalid token. Check your parameters and try again.')); } $sent = EmailData::updateDeclineInvite(array(':token' => $post['inviteToken'], ':team_id' => $post['teamId'], ':user_id' => $post['userId'])); if ($sent) { return $app->render(200, array('msg' => "Team invitation has been declined.")); } else { return $app->render(400, array('msg' => 'Could not update team invite.')); } }
public function providerForInvalidNot() { return array(array(new IntVal(), 123), array(new AllOf(new OneOf(new Numeric(), new IntVal())), 13.37), array(new OneOf(new Numeric(), new IntVal()), 13.37), array(Validator::oneOf(Validator::numeric(), Validator::intVal()), 13.37)); }
/** * @param string $orderId * @param int $limit between 1 and 100 * @param string $startDate acceptable format yyyy-MM-dd'T'HH:mm:ss'Z' * @param string $endDate acceptable format yyyy-MM-dd'T'HH:mm:ss'Z' * @return \Httpful\Response * @throws \Httpful\Exception\ConnectionErrorException */ public function searchByOrderId($orderId, $limit = null, $startDate = null, $endDate = null) { $uri = '/transactions?order=' . $orderId; if (Validator::intVal()->max(100, true)->notEmpty()->validate($limit)) { $uri .= '&limit=' . $limit; } if (Validator::date("Y-m-d'T'HH:mm:ss'Z'")->notEmpty()->validate($startDate)) { $uri .= '&start-date=' . urlencode($startDate); } if (Validator::date("Y-m-d'T'HH:mm:ss'Z'")->notEmpty()->validate($endDate)) { $uri .= '&end-date=' . urlencode($limit); } return $this->makeRequest(self::$METHOD_GET, $uri); }
/** * Deleta o usuario * $request e $response usam interface psr7 * $args contém os argumentos informados na rota * * @param Slim\Http\Request $request * @param Slim\Http\Response $response * @param array $args * @return void|Slim\Http\Response */ public function delete($request, $response, $args) { $id = $args['id']; $validations = [v::intVal()->validate($id)]; if ($this->validate($validations) === false) { return $response->withStatus(400); } else { $usuario = Models\Usuario::with('relationDependentes')->find($id); if ($usuario) { $dependentes = $usuario->relationDependentes->all(); if ($dependentes) { $status = 403; echo $this->error('delete#usuarios{id}', $request->getUri()->getPath(), $status, 'FK_CONSTRAINT_ABORT'); return $response->withStatus($status); } else { $usuario->delete(); } } else { $status = 404; echo $this->error('delete#usuarios{id}', $request->getUri()->getPath(), $status); return $response->withStatus($status); } } }
public function __construct(Client $client) { $this->client = $client; $sortColumns = array_keys(Bookmark::select()->toAssoc()); $this->supportedSettings = array('ff.limit' => array('desc' => 'Limit amount of results (> 0 or 0 for no limit)', 'validation' => array(v::intVal()->min(0, true)), 'default' => '0'), 'ff.sort' => array('desc' => 'Sort order of results (' . implode($sortColumns, ', ') . ')', 'validation' => array(v::in($sortColumns)->notEmpty()), 'default' => 'hit_count'), 'ff.interactive' => array('desc' => 'Ask for missing input interactively (0 never, 1 always)', 'validation' => array(v::in(array('0', '1'))), 'default' => '1'), 'ff.color' => array('desc' => 'Enable color output on supported systems (0/1)', 'validation' => array(v::in(array('0', '1'))), 'default' => '1')); }
public function providerForSetName() { return [[new IntVal()], [new AllOf(new NumericVal(), new IntVal())], [new Not(new Not(new IntVal()))], [Validator::intVal()->setName('Bar')], [Validator::noneOf(Validator::numericVal(), Validator::intVal())]]; }
public static function number($details, $value) { if (strlen($value) == 0) { return TRUE; } else { if ($value === '0') { // Zero as a string is valid return TRUE; } } return RespectValidator::intVal()->validate($value); }