Exemplo n.º 1
0
 /**
  * Make a new validator instance for this model.
  *
  * @return \Illuminate\Validation\Validator
  */
 protected function makeValidator()
 {
     $rules = $this->expandUniqueRules($this->rules);
     $validator = static::$validator->make($this->getAttributes(), $rules);
     event(new ModelValidator($this, $validator));
     return $validator;
 }
Exemplo n.º 2
0
 /**
  * Make a new validator instance for this model.
  *
  * @param array $attributes
  * @return \Illuminate\Validation\Validator
  */
 protected function makeValidator(array $attributes)
 {
     $rules = array_only($this->getRules(), array_keys($attributes));
     $validator = $this->validator->make($attributes, $rules, $this->getMessages());
     $this->events->fire(new ConfigureValidator($this, $validator));
     return $validator;
 }
Exemplo n.º 3
0
 public function validation($attributes, $rules = [])
 {
     if (empty($rules)) {
         $rules = $this->rules;
     }
     return $this->validator->make($attributes, $rules);
 }
Exemplo n.º 4
0
 /**
  * Create a new Validator instance.
  *
  * @param  array  $data
  * @param  array  $rules
  * @param  array  $messages
  * @param  array  $customAttributes
  * @return \Proengsoft\JsValidation\Validator
  */
 public function make(array $data, array $rules, array $messages = [], array $customAttributes = [])
 {
     $validator = $this->factory->make($data, $rules, $messages, $customAttributes);
     $jsValidator = $this->makeJsValidator($validator);
     $this->configureJsRemote($jsValidator);
     return $jsValidator;
 }
 /**
  * @param Ooglee\Domain\CommandBus\ICommand
  * @throws Ooglee\Domain\Validation\ValidationException
  */
 public function validate(ICommand $command)
 {
     $validator = $this->validator->make(['title' => $command->title, 'slug' => $command->slug, 'main_image' => $command->main_image, 'summary' => $command->summary, 'content' => $command->content], $this->rules);
     if (!$validator->passes()) {
         throw new ValidationException($validator->errors());
     }
 }
 /**
  * Validates the address lookup input.
  *
  * @param array $data
  * @throws ValidationException
  */
 public function validate(array $data = [])
 {
     $validation = $this->validator->make($data, $this->rules);
     if ($validation->fails()) {
         throw new ValidationException($validation->errors());
     }
 }
 /**
  * Validation method
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile
  * @return \Illuminate\Validation\Validator $validator
  */
 public function validate($csv_file_path)
 {
     // Line endings fix
     ini_set('auto_detect_line_endings', true);
     $csv_extendion = $csv_file_path->getClientOriginalExtension();
     // Open file into memory
     if ($opened_file = fopen($csv_file_path, 'r') === false) {
         throw new Exception('File cannot be opened for reading');
     }
     // Get first row of the file as the header
     $header = fgetcsv($opened_file, 0, ',');
     // Find email column
     $email_column = $this->getColumnNameByValue($header, 'email');
     // Find first_name column
     $first_name_column = $this->getColumnNameByValue($header, 'first_name');
     // Find last_name column
     $last_name_column = $this->getColumnNameByValue($header, 'last_name');
     // Get second row of the file as the first data row
     $data_row = fgetcsv($opened_file, 0, ',');
     // Combine header and first row data
     $first_row = array_combine($header, $data_row);
     // Find email in the email column
     $first_row_email = array_key_exists('email', $first_row) ? $first_row['email'] : '';
     // Find first name in first_name column
     $first_row_first_name = array_key_exists('first_name', $first_row) ? $first_row['first_name'] : '';
     // Find last name in last_name column
     $first_row_last_name = array_key_exists('last_name', $first_row) ? $first_row['last_name'] : '';
     // Close file and free up memory
     fclose($opened_file);
     // Build our validation array
     $validation_array = ['csv_extension' => $csv_extendion, 'email_column' => $email_column, 'first_name_column' => $first_name_column, 'last_name_column' => $last_name_column, 'email' => $first_row_email, 'first_name' => $first_row_first_name, 'last_name' => $first_row_last_name];
     // Return validator object
     return $this->validator->make($validation_array, $this->rules);
 }
Exemplo n.º 8
0
 /**
  * Validate what is passed into the age gate
  *
  * @param array $data
  * @return $this|Validation|\Illuminate\Http\RedirectResponse
  */
 public function validate(array $data)
 {
     $this->validation = $this->validator->make($data, $this->getValidationRules(), $this->getValidationMessages());
     if ($this->validation->fails()) {
         $failed = $this->validation->failed();
         $validExceptTooYoung = array_get($failed, 'dob.Before');
         $canTryAgain = config('laravel-avp.can_try_again');
         $toRedirect = config('laravel-avp.redirect_on_error');
         $redirectURL = config('laravel-avp.redirect_url');
         if (substr($data['dob'], 0, 4) > date('Y')) {
             return redirect()->action('AVPController@agegate')->withErrors($this->validation->messages())->withInput();
         } else {
             if ($validExceptTooYoung && $toRedirect) {
                 return redirect($redirectURL);
             } else {
                 if ($validExceptTooYoung && !$canTryAgain) {
                     $this->session->put('laravel-avp.previous_too_young', true);
                 } else {
                     $this->session->keep('url.intended');
                 }
             }
         }
         return redirect()->action('AVPController@agegate')->withErrors($this->validation->messages())->withInput();
     }
     return $this->setCookie($data['remember']);
 }
 /**
  * @param Ooglee\Domain\CommandBus\ICommand
  * @throws Ooglee\Domain\Validation\ValidationException
  */
 public function validate(ICommand $command)
 {
     $validator = $this->validator->make(['username' => $command->username, 'email' => $command->email, 'password' => $command->password], $this->rules);
     if (!$validator->passes()) {
         throw new ValidationException($validator->errors());
     }
 }
Exemplo n.º 10
0
 /**
  * @param \Hex\CommandBus\CommandInterface $command
  * @throws \Hex\Validation\ValidationException
  */
 public function validate(CommandInterface $command)
 {
     $validator = $this->validator->make(['subject' => $command->subject, 'name' => $command->name, 'email' => $command->email, 'category_id' => $command->category_id, 'staffer_id' => $command->staffer_id, 'message' => $command->message], $this->rules);
     if (!$validator->passes()) {
         throw new ValidationException($validator->errors());
     }
 }
Exemplo n.º 11
0
 public function handle($data)
 {
     $validation = $this->validator->make($data, static::$rules);
     if ($validation->fails()) {
         throw new ValidationException($validation->messages());
     }
     return true;
 }
Exemplo n.º 12
0
 /**
  * @param array $formData
  *
  * @return bool
  * @throws FormValidationException
  */
 public function validate(array $formData)
 {
     $this->validation = $this->validator->make($formData, $this->getValidatorRules());
     if ($this->validation->fails()) {
         throw new FormValidationException('Validation Failed!', $this->getValidationErrors());
     }
     return true;
 }
 /**
  * @param array $data
  * @param array $rules
  * @param array $messages
  * @return bool
  * @throws ValidationException
  */
 public function validate(array $data, array $rules, $messages = [])
 {
     $validation = $this->validator->make($data, $rules, $messages);
     if ($validation->fails()) {
         throw new ValidationException($validation->messages());
     }
     return true;
 }
 /**
  * Validate the form data
  *
  * @param array $formData
  * @param null $id
  * @throws \BB\Exceptions\FormValidationException
  * @return boolean
  */
 public function validate(array $formData, $id = null)
 {
     $this->validation = $this->validator->make($formData, $this->getValidationRules(['id' => $id]));
     if ($this->validation->fails()) {
         throw new FormValidationException('Validation failed', $this->getValidationErrors());
     }
     return true;
 }
Exemplo n.º 15
0
 public function test_jalali_after_or_before_replacer_is_applied_with_date_and_format()
 {
     $now = '1394-9-15';
     $faNow = StringCleaner::digitsToFarsi($now);
     $validator = $this->factory->make(['graduation_date' => 'garbage'], ['graduation_date' => "required|jalali_after:{$now},Y-m-d|jalali_before:{$now},Y-m-d"]);
     $this->assertTrue($validator->fails());
     $this->assertEquals(['graduation_date' => ["The graduation date must be a Jalali date after {$now}.", "The graduation date must be a Jalali date before {$now}."]], $validator->messages()->toArray());
 }
 public function store()
 {
     $validator = $this->validationFactory->make($this->request->except('_token', 'submit'), $this->rules['create']);
     if ($validator->fails()) {
         return $this->redirector->back()->withInput()->withErrors($validator);
     }
     $this->clients->create($this->request->get('name'), $this->request->get('redirect_uri'), (array) $this->request->get('grants'), (array) $this->request->get('scopes'));
     return $this->redirector->route('oauth.clients.index')->with('success', "Client added successfully.");
 }
Exemplo n.º 17
0
 /**
  * Do the validation
  *
  * @param  array $input The input rules
  * @param array  $rules
  * @throws ValidationException
  * @return bool
  */
 public function validate($input, $rules = [])
 {
     $rules = $rules ?: $this->getRules();
     $validator = $this->validator->make($input, $rules);
     if ($validator->fails()) {
         throw new ValidationException($validator->messages(), 'Validation failed.');
     }
     return true;
 }
Exemplo n.º 18
0
 /**
  * Validates and sets errors if fails.
  *
  * @param  array $data
  * @param  array $rules
  * @return boolean
  */
 public function validate(array $data, array $rules)
 {
     $validator = $this->validator->make($data, $rules, $this->messages);
     if ($validator->fails()) {
         $this->errors = $validator->messages();
         return false;
     }
     return true;
 }
Exemplo n.º 19
0
 public function postValidate()
 {
     $validator = $this->validator->make($this->input->all(), array('recaptcha_response_field' => 'required|recaptcha'));
     if ($validator->fails()) {
         return $this->response->json(array('result' => 'failed'));
     }
     $this->session->put('captcha.passed.time', $this->mockably->microtime());
     return $this->response->json(array('result' => 'success'));
 }
Exemplo n.º 20
0
 /**
  * Returns true if validation passes otherwise ValidationException
  * @param $data
  * @throws ValidationException
  * @internal param $data
  * @return bool
  */
 public function isValid($data)
 {
     $data = $this->normalizeValidationData($data);
     $validation = $this->validator->make($data, static::$rules);
     if ($validation->fails()) {
         throw new ValidationException($validation->messages());
     }
     return true;
 }
Exemplo n.º 21
0
 /**
  * Test if validation passes
  *
  * @author ZZK
  * @link   http://verecom.com
  *
  * @return bool
  */
 public function passes()
 {
     $validator = $this->validator->make($this->data, $this->rules, $this->messages);
     if ($validator->fails()) {
         $this->errors = $validator->messages();
         return false;
     }
     return true;
 }
Exemplo n.º 22
0
 /**
  * Validate the given data.
  *
  * @param array $data
  * @return bool
  * @throws ValidationException
  */
 public function validate(array $data = null)
 {
     $data = $data ?: $this->getInput();
     $this->validation = $this->validator->make($data, $this->rules(), $this->messages());
     if ($this->validation->fails()) {
         $this->failed();
     }
     return true;
 }
Exemplo n.º 23
0
 /**
  * Validates the data.
  * 
  * @param  string $type type of validation create/update.
  * @throws ValidationException
  * @return boolean
  */
 public function validate($type)
 {
     $v = $this->validator->make($this->fields, $this->rules[$type]);
     if ($v->fails()) {
         throw new ValidationException($v->errors());
     } else {
         return true;
     }
 }
 /**
  * Store the scope
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store()
 {
     $validator = $this->validationFactory->make($this->request->except('_token', 'submit'), $this->rules['create']);
     if ($validator->fails()) {
         return $this->redirector->back()->withInput()->withErrors($validator);
     }
     $this->scopes->create($this->request->get('id'), $this->request->get('description'));
     return $this->redirector->route('oauth.scopes.index')->with('success', "Scope added successfully.");
 }
Exemplo n.º 25
0
 /**
  * Validation passes or fails
  *
  * @return Boolean
  */
 public function passes()
 {
     $validator = $this->validator->make($this->data, $this->rules, $this->message);
     $validator->getPresenceVerifier()->setConnection($this->connection);
     if ($validator->fails()) {
         $this->errors = $validator->messages();
         return false;
     }
     return true;
 }
 /**
  * Pass the data and the rules to the validator
  *
  * @param string $action
  * @return bool
  */
 public function passes($action = null)
 {
     $rules = $this->getRules($action);
     $validator = $this->validator->make($this->data, $rules);
     if ($validator->fails()) {
         $this->errors = $validator->messages();
         return false;
     }
     return true;
 }
Exemplo n.º 27
0
 /**
  * @param array $formData
  *
  * @throws FormValidationException
  */
 public function validate(array $formData)
 {
     // Instantiate validator instance by factory
     $this->validation = $this->validator->make($formData, $this->rules());
     // Validate
     if ($this->validation->fails()) {
         throw new FormValidationException('Validation Failed', $this->getValidationErrors());
     }
     return true;
 }
Exemplo n.º 28
0
 /**
  * Validate the model's attributes.
  *
  * @param  array  $rules
  * @return bool
  */
 public function validate(array $rules = array())
 {
     $rules = $this->processRules($rules ?: static::$rules);
     $this->validator = $this->validatorFactory->make($this->attributes, $rules);
     if ($this->validator->fails()) {
         $this->errors = $this->validator->errors();
         return false;
     }
     $this->errors = null;
     return true;
 }
 /**
  * passes
  *
  * @return bool
  * @author  Vincent Sposato <*****@*****.**>
  * @version v1.0
  */
 public function passes()
 {
     // Load the custom validation rules
     $this->loadCustomValidation();
     $validator = $this->validator->make($this->data, $this->rules, $this->messages);
     if ($validator->fails()) {
         $this->errors = $validator->messages();
         return false;
     }
     return true;
 }
Exemplo n.º 30
0
 /**
  * @param UserRegisterCommand $command
  *
  * @return bool
  */
 public function validate(UserRegisterCommand $command)
 {
     /**
      * @var Validator $validator
      */
     $validator = $this->validator->make($command->toArray(), $this->rules);
     if ($validator->fails()) {
         throw new ValidationFailedException($validator->errors());
     }
     return true;
 }