/** * Método protegido que faz a validação das requisições. * * @method getData() * * @param Request * @param array * @param bool * * @return bool */ protected static function getData($request, &$data = [], $upper = true) { if (!empty($request)) { foreach ($request as $key => $value) { if (empty($key)) { continue; } if (self::$require) { if (in_array($key, self::$require)) { if (Validator::blank($value)) { self::$error[] = $key; } } } $data[str_replace('|', '.', $key)] = $upper ? strtoupper(addslashes(trim($value))) : addslashes(trim($value)); } if ($request['request_data']) { parse_str_to_array($request['request_data'], $data_rd); foreach ($data_rd as $key => $value) { if (empty($key)) { continue; } $data_rd[$key] = $upper ? strtoupper(addslashes(trim($value))) : addslashes(trim($value)); } $data = array_merge($data, $data_rd); unset($data['request_data']); } } else { // nenhuma requisição passada sem nenhum retorno de dados. return false; } // todo request foi verificado e teve retorno de dados. return true; }
public function validate($params) { $this->removeRepeats($params); $params['num_names'] = count($params['actor_name']); $params['num_surnames'] = count($params['actor_surname']); $rules = ['id' => ['required', 'positive_integer'], 'title' => ['required', 'trim'], 'year' => ['required', 'trim', ['number_between' => [1896, date('Y')]]], 'format' => ['required', 'trim', ['one_of' => ['DVD', 'VHS', 'Blu-Ray']]], 'actor_name' => ['list_of' => ['required', 'trim', ['min_length' => 1]]], 'actor_surname' => ['list_of' => ['required', 'trim', ['min_length' => 1]]], 'num_names' => ['equal_to_field' => 'num_surnames']]; return \Service\Validator::validate($params, $rules); }
public function validate($params) { $type = $params['type']; if ($type !== null && $params['value'] === '') { //search type exists, but value is empty throw new \Service\X(['Message' => 'Value type cannot be empty', 'Fields' => 'value', 'Type' => 'Request Error']); } $rules = ['type' => ['one_of' => [null, 'actor', 'title']], 'value' => ['min_length' => 0]]; return \Service\Validator::validate($params, $rules); }
public function validate($params) { $rules = ['id' => ['required', 'positive_integer']]; return \Service\Validator::validate($params, $rules); }
public function validate($params) { $rules = []; return \Service\Validator::validate($params, $rules); }
public function validate($params) { $this->removeRepeats($params); $rules = ['title' => ['required', 'trim'], 'year' => ['required', 'trim', ['number_between' => [1896, date('Y')]]], 'format' => ['required', 'trim', ['one_of' => ['DVD', 'VHS', 'Blu-Ray']]], 'actor_name' => ['list_of' => ['required', 'trim', ['min_length' => 1]]], 'actor_surname' => ['list_of' => ['required', 'trim', ['min_length' => 1]]]]; return \Service\Validator::validate($params, $rules); }