本文整理汇总了PHP中Illuminate\Validation\Factory类的典型用法代码示例。如果您正苦于以下问题:PHP Factory类的具体用法?PHP Factory怎么用?PHP Factory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setValidator
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);
}
示例2: extendValidator
/**
* 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' !");
}
示例3: register
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();
});
}
示例4: __construct
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');
}
示例5: __construct
/**
* 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;
});
}
示例6: register
/**
* 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;
});
}
示例7: __construct
/**
* 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;
});
}
示例8: validate
/**
* @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());
}
}
示例9: setLines
/**
* 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);
}
}
示例10: makeValidator
/**
* 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;
}
示例11: validate
/**
* @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());
}
}
示例12: validate
/**
* 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());
}
}
示例13: extendValidator
/**
* 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);
}
}
示例14: validation
public function validation($attributes, $rules = [])
{
if (empty($rules)) {
$rules = $this->rules;
}
return $this->validator->make($attributes, $rules);
}
示例15: makeValidator
/**
* 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;
}