Example #1
2
 protected function setValidator()
 {
     $filesystem = new FileLoader(new Filesystem(), CONFIG_DIR . DIRECTORY_SEPARATOR . 'langs');
     $translator = new Translator($filesystem, Main::$app->web->get('locale', false) ?: 'en');
     $this->validator = new ValidatorFactory($translator);
     $verifier = new DatabasePresenceVerifier($this->capsule->getDatabaseManager());
     $this->validator->setPresenceVerifier($verifier);
 }
 /**
  * @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());
     }
 }
 /**
  * Extend the Validator.
  *
  * @param Factory $factory
  */
 protected function extendValidator(Factory $factory)
 {
     $factory->replacer('required_if_has', function ($message, $attribute, $rule, $parameters) {
         return $this->setFieldsAndValues($message, $attribute, $rule, $parameters);
     });
     $factory->replacer('required_if_not', function ($message, $attribute, $rule, $parameters) {
         return $this->setFieldsAndValues($message, $attribute, $rule, $parameters);
     });
     /////////////////////
     // Required if NOT //
     /////////////////////
     $factory->extendImplicit('required_if_not', function ($attribute, $value, $parameters = []) {
         $input = $this->input();
         $field = $parameters[0];
         $fieldValue = $parameters[1];
         // If the field is not set, default to true
         if (!array_key_exists($field, $input)) {
             return true;
         }
         return $input[$field] !== $fieldValue ? array_key_exists($attribute, $input) : true;
     }, "La question ':attribute' est requise lorsque la question ':field' n'est pas ':value' !");
     //////////////////////////////////
     // If checkbox contains a value //
     //////////////////////////////////
     $factory->extendImplicit('required_if_has', function ($attribute, $value, $parameters = []) {
         $input = $this->input();
         $field = $parameters[0];
         $fieldValue = $parameters[1];
         // If the field is not set, default to true
         if (!array_key_exists($field, $input)) {
             return true;
         }
         return array_key_exists($fieldValue, $input[$field]) ? array_key_exists($attribute, $input) : true;
     }, "La question ':attribute' est requise lorsque la question ':field' contient ':value' !");
 }
Example #4
0
 /**
  * Set the language lines used by the translator.
  *
  * @param  array $lines
  * @return void
  */
 public function setLines(array $lines)
 {
     $translator = $this->factory->getTranslator();
     if ($translator instanceof Translator) {
         $translator->setLines($lines);
     }
 }
Example #5
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;
 }
 public function register(Application $app)
 {
     $core = $app;
     $app['illuminate'] = new Container();
     $app['illuminate']['config'] = array('cache.driver' => 'memcached', 'cache.memcached' => array(array('host' => 'localhost', 'port' => '11211')));
     $app['illuminate']->bindShared('validator', function ($app) use($core) {
         $validator = new Factory($core['translator'], $app);
         // The validation presence verifier is responsible for determining the existence
         // of values in a given data collection, typically a relational database or
         // other persistent data stores. And it is used to check for uniqueness.
         if (isset($app['validation.presence'])) {
             $validator->setPresenceVerifier($app['validation.presence']);
         }
         return $validator;
     });
     $app['illuminate']->bindShared('cache', function ($app) {
         return new CacheManager($app);
     });
     $app['illuminate']->bindShared('cache.store', function ($app) {
         return $app['cache']->driver();
     });
     $app['illuminate']->bindShared('memcached.connector', function () {
         return new MemcachedConnector();
     });
 }
 /**
  * @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());
     }
 }
 /**
  * Extend validator.
  *
  * @param  string         $name
  * @param  string         $class
  * @param  \Closure|null  $replacer
  */
 private function extendValidator($name, $class, Closure $replacer = null)
 {
     $this->validator->extend($name, $class . '@validate' . studly_case($name));
     if (!is_null($replacer)) {
         $this->validator->replacer($name, $replacer);
     }
 }
Example #10
0
 public function validation($attributes, $rules = [])
 {
     if (empty($rules)) {
         $rules = $this->rules;
     }
     return $this->validator->make($attributes, $rules);
 }
 public function __construct(Factory $factory)
 {
     //Custom Validator Rut
     $factory->extend('rut_valid', function ($attribute, $value, $parameters) {
         return Rut::check($value);
     }, 'El campo Rut no tiene un formato válido');
 }
 /**
  * Overwrite the parent constructor to define a new validator.
  *
  * @param  Factory $factory
  * @return void
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function __construct(Factory $factory)
 {
     $factory->extend('repository', function ($attribute, $value, $parameters) {
         if (preg_match('/^(ssh|git|https?):\\/\\//', $value)) {
             // Plain old git repo
             return true;
         }
         if (preg_match('/^(.*)@(.*):(.*)\\/(.*)\\.git/', $value)) {
             // Gitlab
             return true;
         }
         /*
         TODO: improve these regexs, using the following stolen from PHPCI (sorry Dan!)
         
         'ssh': /git\@github\.com\:([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)\.git/,
         'git': /git\:\/\/github.com\/([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)\.git/,
         'http': /https\:\/\/github\.com\/([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)(\.git)?/
         */
         if (preg_match('/^[a-zA-Z0-9_\\-]+\\/[a-zA-Z0-9_\\-\\.]+$/', $value)) {
             // Github
             return true;
         }
         /*
         'ssh': /git\@bitbucket\.org\:([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)\.git/,
         'http': /https\:\/\/[a-zA-Z0-9_\-]+\@bitbucket.org\/([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)\.git/,
         'anon': /https\:\/\/bitbucket.org\/([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)(\.git)?/
         */
         if (preg_match('/^[a-zA-Z0-9_\\-]+\\/[a-zA-Z0-9_\\-\\.]+$/', $value)) {
             // Bitbucket
             return true;
         }
         return false;
     });
 }
Example #13
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->mergeConfigFrom(__DIR__ . '/../config/captcha.php', 'mews.captcha');
     /**
      * @param $app
      * @return Captcha
      */
     $this->app->bind('captcha', function ($app) {
         return new Captcha($app['Illuminate\\Filesystem\\Filesystem'], $app['Illuminate\\Config\\Repository'], $app['Intervention\\Image\\ImageManager'], $app['Illuminate\\Session\\Store'], $app['Illuminate\\Hashing\\BcryptHasher'], $app['Illuminate\\Support\\Str']);
     });
     /**
      * @param Captcha $captcha
      * @param $config
      * @return \Intervention\Image\ImageManager
      */
     $this->app['router']->get('captcha/{config?}', 'Chekun\\Captcha\\CaptchaController@draw');
     $this->app['validator'] = $this->app->share(function ($app) {
         $validator = new Factory($app['translator']);
         $validator->setPresenceVerifier($this->app['validation.presence']);
         $validator->resolver(function ($translator, $data, $rules, $messages) {
             return new CaptchaValidator($translator, $data, $rules, $messages);
         });
         return $validator;
     });
 }
 /**
  * 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;
 }
 /**
  * Overwrite the parent constructor to define a new validator.
  *
  * @param  Factory $factory
  * @return void
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function __construct(Factory $factory)
 {
     $factory->extend('channel', function ($attribute, $value, $parameters) {
         $first_character = substr($value, 0, 1);
         return ($first_character === '#' || $first_character === '@') && strlen($value) > 1;
     });
 }
 /**
  * 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);
 }
 /**
  * @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());
     }
 }
Example #18
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']);
 }
Example #19
0
 public function handle($data)
 {
     $validation = $this->validator->make($data, static::$rules);
     if ($validation->fails()) {
         throw new ValidationException($validation->messages());
     }
     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;
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot(Validator $validator)
 {
     $rules = new Rules();
     collect(get_class_methods($rules))->each(function ($method) use($validator) {
         $name = snake_case(preg_replace('/^validate/i', null, $method));
         $validator->extend($name, sprintf('%s@%s', Rules::class, $method));
     });
 }
 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());
 }
 /**
  * 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;
 }
 /**
  * Get the validator instance for the request.
  *
  * @param $factory \Illuminate\Validation\Factory
  * @return \Illuminate\Validation\Validator
  */
 public function validator(\Illuminate\Validation\Factory $factory)
 {
     // add 'user_list' attribute if doesn't exist
     if (!$this->request->has('user_list')) {
         $this->merge(['user_list' => []]);
     }
     return $factory->make($this->all(), $this->rules());
 }
 /**
  * @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;
 }
Example #26
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;
 }
 /**
  * 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;
 }
 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.");
 }
 /**
  * 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;
 }
 /**
  * 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.");
 }