本文整理汇总了PHP中Illuminate\Validation\Factory::replacer方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::replacer方法的具体用法?PHP Factory::replacer怎么用?PHP Factory::replacer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Validation\Factory
的用法示例。
在下文中一共展示了Factory::replacer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
$this->translator = new Translator(new \Illuminate\Translation\FileLoader(new \Illuminate\Filesystem\Filesystem(), __DIR__ . '/../sample-lang'), 'en');
$this->translator->setLocale('en');
$this->factory = new Factory($this->translator);
$validator = new JalaliValidator();
$this->factory->extend('jalali', function ($attribute, $value, $parameter) use($validator) {
return $validator->validateJalali($attribute, $value, $parameter);
});
$this->factory->extend('jalali_after', function ($attribute, $value, $parameter) use($validator) {
return $validator->validateAfter($attribute, $value, $parameter);
});
$this->factory->extend('jalali_before', function ($attribute, $value, $parameter) use($validator) {
return $validator->validateBefore($attribute, $value, $parameter);
});
$this->factory->replacer('jalali', function ($message, $attribute, $rule, $parameter) use($validator) {
return $validator->replaceJalali($message, $attribute, $rule, $parameter);
});
$this->factory->replacer('jalali_after', function ($message, $attribute, $rule, $parameter) use($validator) {
return $validator->replaceAfterOrBefore($message, $attribute, $rule, $parameter);
});
$this->factory->replacer('jalali_before', function ($message, $attribute, $rule, $parameter) use($validator) {
return $validator->replaceAfterOrBefore($message, $attribute, $rule, $parameter);
});
}
示例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: 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);
}
}
示例4: registerJDateTimeRules
/**
* @param JalaliValidator $validator
*/
private function registerJDateTimeRules(JalaliValidator $validator)
{
$this->factory->extend('jdatetime', function ($attribute, $value, $parameter) use($validator) {
return $validator->validateJDateTime($attribute, $value, $parameter);
});
$this->factory->extend('jdatetime_after', function ($attribute, $value, $parameter) use($validator) {
return $validator->validateJDateTimeAfter($attribute, $value, $parameter);
});
$this->factory->extend('jdatetime_before', function ($attribute, $value, $parameter) use($validator) {
return $validator->validateJDateTimeBefore($attribute, $value, $parameter);
});
$this->factory->replacer('jdatetime', function ($message, $attribute, $rule, $parameter) use($validator) {
return $validator->replaceJalali($message, $attribute, $rule, $parameter);
});
$this->factory->replacer('jdatetime_after', function ($message, $attribute, $rule, $parameter) use($validator) {
return $validator->replaceAfterOrBefore($message, $attribute, $rule, $parameter);
});
$this->factory->replacer('jdatetime_before', function ($message, $attribute, $rule, $parameter) use($validator) {
return $validator->replaceAfterOrBefore($message, $attribute, $rule, $parameter);
});
}
示例5: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerPresenceVerifier();
$this->app->singleton('validator', function ($app) {
$validator = new Factory($app['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']);
}
// Add validation extensions
$extensions = config('esensi/core::validation.extensions', []);
foreach ($extensions as $extension => $class) {
$validator->extend($extension, $class . '@validate' . ucfirst(studly_case($extension)));
$validator->replacer($extension, $class . '@replace' . ucfirst(studly_case($extension)));
}
return $validator;
});
}
示例6: replacer
/**
* Register a custom implicit validator message replacer.
*
* @param string $rule
* @param \Closure|string $replacer
* @return void
* @static
*/
public static function replacer($rule, $replacer)
{
\Illuminate\Validation\Factory::replacer($rule, $replacer);
}
示例7: replacer
/**
* Register a custom implicit validator message replacer.
*
* @param string $rule
* @param \Closure|string $replacer
* @return void
*/
public function replacer($rule, $replacer)
{
$this->factory->replacer($rule, $replacer);
}