当前位置: 首页>>代码示例>>PHP>>正文


PHP Factory::extend方法代码示例

本文整理汇总了PHP中Illuminate\Validation\Factory::extend方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::extend方法的具体用法?PHP Factory::extend怎么用?PHP Factory::extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Validation\Factory的用法示例。


在下文中一共展示了Factory::extend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
     });
 }
开发者ID:halaei,项目名称:jalali,代码行数:26,代码来源:JalaliServiceProviderTest.php

示例2: 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);
     }
 }
开发者ID:arcanesoft,项目名称:auth,代码行数:14,代码来源:ValidatorServiceProvider.php

示例3: __construct

 /**
  * Create a new FormRequest instance.
  *
  * @param \Illuminate\Validation\Factory $factory
  * @return void
  */
 public function __construct(ValidatonFactory $factory)
 {
     $factory->extend('valid_token', function ($attribute, $value, $parameters, $validator) {
         $secret = Crypt::decrypt($this->user->google2fa_secret);
         return Google2FA::verifyKey($secret, $value);
     }, 'Not a valid token');
     $factory->extend('used_token', function ($attribute, $value, $parameters, $validator) {
         $key = $this->user->id . ':' . $value;
         return !Cache::has($key);
     }, 'Cannot resue token');
 }
开发者ID:cwt137,项目名称:google-laravel-2fa,代码行数:17,代码来源:ValidateSecretRequest.php

示例4: __construct

 public function __construct(Factory $factory)
 {
     //Custom Validator Rut
     $factory->extend('old_password', function ($attribute, $value, $parameters) {
         $id = $this->id;
         $usuario = Usuario::find($id);
         return Hash::check($value, $usuario->password);
     }, 'La Constraseña actual no corresponde');
     $factory->extend('rut_valid', function ($attribute, $value, $parameters) {
         return Rut::check($value);
     }, 'El campo Rut no tiene un formato válido');
 }
开发者ID:ProyectoSanClemente,项目名称:proyectoapi5.1,代码行数:12,代码来源:UpdateUsuarioRequest.php

示例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('channel', function ($attribute, $value, $parameters) {
         $first_character = substr($value, 0, 1);
         return ($first_character === '#' || $first_character === '@') && strlen($value) > 1;
     });
 }
开发者ID:BlueBayTravel,项目名称:deployer,代码行数:14,代码来源:StoreNotificationRequest.php

示例6: __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;
     });
 }
开发者ID:devLopez,项目名称:deployer-1,代码行数:41,代码来源:StoreProjectRequest.php

示例7: __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');
 }
开发者ID:ProyectoSanClemente,项目名称:proyectoapi5.1,代码行数:7,代码来源:CreateUsuarioRequest.php

示例8: boot

 /**
  * 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));
     });
 }
开发者ID:apolune,项目名称:account,代码行数:13,代码来源:ValidationServiceProvider.php

示例9: extending

 /**
  * add new rule to validation factory
  *
  * @return void
  */
 private function extending()
 {
     $this->factory->extend('has_parent', function ($attribute, $value) {
         if ($attribute == 'object' && $value->getDepth() > 1 && $value->getParent() === null) {
             return false;
         }
         return true;
     });
 }
开发者ID:mint-soft-com,项目名称:xpressengine,代码行数:14,代码来源:Validator.php

示例10: initializeValidator

 function initializeValidator()
 {
     $validator = new Validator($this->translator, new Container());
     $validator->extend('phone', function ($attribute, $value, $parameters, $validator) {
         preg_match('/\\d+/', $value, $matches);
         if (strlen($matches[0]) == 10) {
             return true;
         }
     });
     return $validator;
 }
开发者ID:laugharn,项目名称:clap,代码行数:11,代码来源:Clap.php

示例11: registerValidators

 /**
  * Register field's custom validators.
  *
  * @param Factory     $factory
  * @param FormBuilder $builder
  * @param FieldType   $fieldType
  */
 protected function registerValidators(Factory $factory, FormBuilder $builder, FieldType $fieldType)
 {
     foreach ($fieldType->getValidators() as $rule => $validator) {
         $handler = array_get($validator, 'handler');
         if (is_string($handler) && !str_contains($handler, '@')) {
             $handler .= '@handle';
         }
         $factory->extend($rule, function ($attribute, $value, $parameters, Validator $validator) use($handler, $builder) {
             return $this->container->call($handler, compact('attribute', 'value', 'parameters', 'builder', 'validator'));
         }, array_get($validator, 'message'));
     }
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:19,代码来源:FormExtender.php

示例12: 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);
     });
 }
开发者ID:opilo,项目名称:farsi,代码行数:24,代码来源:FarsiServiceProviderTest.php

示例13: __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('host', function ($attribute, $value, $parameters) {
         if (filter_var($value, FILTER_VALIDATE_IP)) {
             return true;
         }
         if (filter_var(gethostbyname($value), FILTER_VALIDATE_IP)) {
             return true;
         }
         return false;
     });
 }
开发者ID:arasmit2453,项目名称:deployer,代码行数:19,代码来源:StoreServerRequest.php

示例14: validate

 /**
  * @param array $input
  * @param array $rules
  * @return array
  */
 public function validate(array $input, array $rules)
 {
     $validatorFactory = new IlluminateValidationFactory(new SymfonyTranslator('en'));
     // enabling rule default, which will be used not to validate, but to set default value for optional parameter
     $validatorFactory->extend('default', function ($attribute, $value, $parameters) {
         return count($parameters) == 1 && !empty($parameters[0]);
     });
     // create replacers for custom messages
     //$validatorFactory->replacer('default', function ($message, $attribute, $rule, $parameters) {
     //    $replacement = !empty($parameters[0]) ? $replacement[0] : 'MISSING';
     //    return str_replace(':defaultValue', $replacement, $message);
     //});
     $validator = $validatorFactory->make($input, $rules, $this->validationMessages);
     $validationErrors = $validator->errors()->getMessages();
     reset($validationErrors);
     return $validationErrors;
 }
开发者ID:alexlvcom,项目名称:TaskRunner,代码行数:22,代码来源:ParamValidator.php

示例15: testMakeMethodCreatesValidValidator

 public function testMakeMethodCreatesValidValidator()
 {
     $translator = m::mock('Symfony\\Component\\Translation\\TranslatorInterface');
     $factory = new Factory($translator);
     $validator = $factory->make(array('foo' => 'bar'), array('baz' => 'boom'));
     $this->assertEquals($translator, $validator->getTranslator());
     $this->assertEquals(array('foo' => 'bar'), $validator->getData());
     $this->assertEquals(array('baz' => array('boom')), $validator->getRules());
     $presence = m::mock('Illuminate\\Validation\\PresenceVerifierInterface');
     $factory->extend('foo', function () {
     });
     $factory->setPresenceVerifier($presence);
     $validator = $factory->make(array(), array());
     $this->assertEquals(array('foo' => function () {
     }), $validator->getExtensions());
     $this->assertEquals($presence, $validator->getPresenceVerifier());
 }
开发者ID:j-ew-s,项目名称:BabyName,代码行数:17,代码来源:FactoryTest.php


注:本文中的Illuminate\Validation\Factory::extend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。