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


PHP Validation::createValidatorBuilder方法代码示例

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


在下文中一共展示了Validation::createValidatorBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct()
 {
     $this->validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
     $this->getSetNormalizer = new GetSetMethodNormalizer();
     $this->builder = new Builder();
     $this->annotationReader = new AnnotationReader();
 }
开发者ID:suramon,项目名称:entity-serializer,代码行数:7,代码来源:EntityNormalizer.php

示例2: validate

 public function validate()
 {
     $this->helper = (include FrontController::getRootPath() . "/src/cli_config.php");
     $validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
     $violations = $validator->validate($this);
     return $violations;
 }
开发者ID:epoplive,项目名称:pillow,代码行数:7,代码来源:AnnotationValidatorTrait.php

示例3: createUser

 public function createUser()
 {
     $user = new Test\User();
     $post = $this->app->request()->getBody();
     $data = json_decode($post);
     var_dump($data);
     $user->name = $data->name;
     $user->email = $data->email;
     var_dump($user);
     /*
             $validator = Validation::createValidator();
     $constraint = new Assert\Collection(array(
                 'email' => new Assert\Email(),
                 'name' => new Assert\Length(array('min' => 10)),
             ));
     $violations = $validator->validateValue($data, $constraint);
     */
     $builder = Validation::createValidatorBuilder();
     $builder->addYamlMapping(__DIR__ . '/rules.yml');
     $validator = $builder->getValidator();
     $violations = $validator->validate($user);
     if (0 === count($violations)) {
         echo 'valid';
     } else {
         foreach ($violations as $violation) {
             echo $violation->getMessage();
         }
     }
 }
开发者ID:swos-,项目名称:slim-api,代码行数:29,代码来源:UsersController.php

示例4: __construct

 public function __construct(Request $request, $type = "form", $data = array(), $options = array())
 {
     $this->request = $request;
     $validator = Validation::createValidatorBuilder();
     if (!isset($options["attr"]["name"])) {
         $options["attr"]["thelia_name"] = $this->getName();
     }
     $builder = Forms::createFormFactoryBuilder()->addExtension(new HttpFoundationExtension());
     if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
         $builder->addExtension(new CsrfExtension(new SessionCsrfProvider($request->getSession(), isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__)))));
     }
     $translator = Translator::getInstance();
     $validator->setTranslationDomain('validators')->setTranslator($translator);
     $this->formBuilder = $builder->addExtension(new ValidatorExtension($validator->getValidator()))->getFormFactory()->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
     $this->buildForm();
     // If not already set, define the success_url field
     // This field is not included in the standard form hidden fields
     // This field is not included in the hidden fields generated by form_hidden_fields Smarty function
     if (!$this->formBuilder->has('success_url')) {
         $this->formBuilder->add("success_url", "hidden");
     }
     // The "error_message" field defines the error message displayed if
     // the form could not be validated. If it is empty, a standard error message is displayed instead.
     // This field is not included in the hidden fields generated by form_hidden_fields Smarty function
     if (!$this->formBuilder->has('error_message')) {
         $this->formBuilder->add("error_message", "hidden");
     }
     $this->form = $this->formBuilder->getForm();
 }
开发者ID:alex63530,项目名称:thelia,代码行数:29,代码来源:BaseForm.php

示例5: testConstraintsValidatorCanBeModified

 public function testConstraintsValidatorCanBeModified()
 {
     $validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
     Configuration::setConstraintsValidator($validator);
     $returnedValidator = Configuration::getConstraintsValidator();
     $this->assertEquals($validator, $returnedValidator);
 }
开发者ID:antarestupin,项目名称:Accessible,代码行数:7,代码来源:ConfigurationTest.php

示例6: register

 public function register(Container $app)
 {
     $app['validator'] = function ($app) {
         return $app['validator.builder']->getValidator();
     };
     $app['validator.builder'] = function ($app) {
         $builder = Validation::createValidatorBuilder();
         $builder->setConstraintValidatorFactory($app['validator.validator_factory']);
         $builder->setTranslationDomain('validators');
         $builder->addObjectInitializers($app['validator.object_initializers']);
         $builder->setMetadataFactory($app['validator.mapping.class_metadata_factory']);
         if (isset($app['translator'])) {
             $builder->setTranslator($app['translator']);
         }
         return $builder;
     };
     $app['validator.mapping.class_metadata_factory'] = function ($app) {
         return new LazyLoadingMetadataFactory(new StaticMethodLoader());
     };
     $app['validator.validator_factory'] = function () use($app) {
         return new ConstraintValidatorFactory($app, $app['validator.validator_service_ids']);
     };
     $app['validator.object_initializers'] = function ($app) {
         return array();
     };
     $app['validator.validator_service_ids'] = array();
 }
开发者ID:cordje,项目名称:Silex,代码行数:27,代码来源:ValidatorServiceProvider.php

示例7: getMetaValidator

 public function getMetaValidator($allowedLocales = array(), $intlExtension = false, $strict = false)
 {
     $factory = new ConstraintValidatorFactory($this->getLocaleValidator($intlExtension), $this->getLocaleAllowedValidator($intlExtension, $allowedLocales, $strict));
     $validator = Validation::createValidatorBuilder();
     $validator->setConstraintValidatorFactory($factory);
     return new MetaValidator($validator->getValidator());
 }
开发者ID:Sententiaregum,项目名称:LocaleBundle,代码行数:7,代码来源:BaseMetaValidator.php

示例8: testCreate

 public function testCreate()
 {
     $teamA = new Team();
     $teamA->setPlayerA(new Player(1, 'John Doe'));
     $teamA->setPlayerB(new Player(2, 'James Doe'));
     $teamB = new Team();
     $teamB->setPlayerA(new Player(3, 'John Smith'));
     $teamB->setPlayerB(new Player(4, 'James Smith'));
     $setScore = new SetScore();
     $setScore->setScoresByString('21-18');
     $match = new Match();
     $match->setTeamA($teamA);
     $match->setTeamB($teamB);
     $match->addSetScore($setScore);
     $match->addSetScoreByString('21-16');
     $match->setGameTimeLengthInSeconds(5);
     $validator = Validation::createValidatorBuilder()->addMethodMapping('loadValidatorMetadata')->getValidator();
     $this->assertEmpty($validator->validate($match));
     $this->assertTrue($match->getTeamA() instanceof Team);
     $this->assertTrue($match->getTeamB() instanceof Team);
     $this->assertSame(2, count($match->getSetScores()));
     $this->assertTrue($match->getSetscores()[0] instanceof SetSCore);
     $this->assertTrue($match->getSetscore(1) instanceof SetSCore);
     $this->assertSame(null, $match->getSetScore(3));
     $this->assertSame(5, $match->getGameTimeLengthInSeconds());
     $this->assertSame('[(1) John Doe, (2) James Doe] def [(3) John Smith, (4) James Smith]', $match->__toString());
 }
开发者ID:pdt256,项目名称:vbscraper,代码行数:27,代码来源:MatchTest.php

示例9: register

 public function register(Application $app)
 {
     $app['validator'] = $app->share(function ($app) {
         return $app['validator.builder']->getValidator();
     });
     $app['validator.builder'] = $app->share(function ($app) {
         $builder = Validation::createValidatorBuilder();
         $builder->setConstraintValidatorFactory($app['validator.validator_factory']);
         $builder->setTranslationDomain('validators');
         $builder->addObjectInitializers($app['validator.object_initializers']);
         $builder->setMetadataFactory($app['validator.mapping.class_metadata_factory']);
         if (isset($app['translator'])) {
             $builder->setTranslator($app['translator']);
         }
         return $builder;
     });
     $app['validator.mapping.class_metadata_factory'] = $app->share(function ($app) {
         if (class_exists('Symfony\\Component\\Validator\\Mapping\\Factory\\LazyLoadingMetadataFactory')) {
             return new LazyLoadingMetadataFactory(new StaticMethodLoader());
         }
         return new ClassMetadataFactory(new StaticMethodLoader());
     });
     $app['validator.validator_factory'] = $app->share(function () use($app) {
         return new ConstraintValidatorFactory($app, $app['validator.validator_service_ids']);
     });
     $app['validator.object_initializers'] = $app->share(function ($app) {
         return array();
     });
     $app['validator.validator_service_ids'] = array();
 }
开发者ID:jujhars13,项目名称:gearman-ui.docker,代码行数:30,代码来源:ValidatorServiceProvider.php

示例10: __construct

 public function __construct()
 {
     $builder = Validation::createValidatorBuilder();
     $builder->setConstraintValidatorFactory(new ConstraintValidatorFactory());
     $builder->setMetadataFactory(new LazyLoadingMetadataFactory(new StaticMethodLoader()));
     parent::__construct($builder->getValidator());
 }
开发者ID:barryvdh,项目名称:laravel-form-bridge,代码行数:7,代码来源:FormValidatorExtension.php

示例11: getValidator

 /**
  * @return ValidatorInterface
  */
 public function getValidator()
 {
     if (is_null($this->validator)) {
         $this->validator = Validation::createValidatorBuilder()->enableAnnotationMapping($this->getAnnotationReader())->getValidator();
     }
     return $this->validator;
 }
开发者ID:internetmarketingsolutions,项目名称:packservice-sk,代码行数:10,代码来源:PackserviceSk.php

示例12: getValidator

 /**
  * @param Reader $reader
  *
  * @return ValidatorInterface
  */
 public function getValidator(Reader $reader = null)
 {
     if (null === $reader) {
         $reader = new AnnotationReader();
     }
     return Validation::createValidatorBuilder()->enableAnnotationMapping($reader)->getValidator();
 }
开发者ID:krzysztof-gzocha,项目名称:payu,代码行数:12,代码来源:ValidatorBuilder.php

示例13: register

 public function register(Container $app)
 {
     $app['validator'] = function ($app) {
         if (isset($app['translator'])) {
             $r = new \ReflectionClass('Symfony\\Component\\Validator\\Validation');
             $file = dirname($r->getFilename()) . '/Resources/translations/validators.' . $app['locale'] . '.xlf';
             if (file_exists($file)) {
                 $app['translator']->addResource('xliff', $file, $app['locale'], 'validators');
             }
         }
         return $app['validator.builder']->getValidator();
     };
     $app['validator.builder'] = function ($app) {
         $builder = Validation::createValidatorBuilder();
         $builder->setConstraintValidatorFactory($app['validator.validator_factory']);
         $builder->setTranslationDomain('validators');
         $builder->addObjectInitializers($app['validator.object_initializers']);
         $builder->setMetadataFactory($app['validator.mapping.class_metadata_factory']);
         if (isset($app['translator'])) {
             $builder->setTranslator($app['translator']);
         }
         return $builder;
     };
     $app['validator.mapping.class_metadata_factory'] = function ($app) {
         return new LazyLoadingMetadataFactory(new StaticMethodLoader());
     };
     $app['validator.validator_factory'] = function () use($app) {
         $validators = isset($app['validator.validator_service_ids']) ? $app['validator.validator_service_ids'] : array();
         return new ConstraintValidatorFactory($app, $validators);
     };
     $app['validator.object_initializers'] = function ($app) {
         return array();
     };
 }
开发者ID:rayrutjes,项目名称:Silex,代码行数:34,代码来源:ValidatorServiceProvider.php

示例14: setUp

 /**
  * Setting up the validator.
  */
 protected function setUp()
 {
     $this->now = new \DateTime();
     $this->validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
     $this->baseVacancy = new Vacancy();
     $this->baseVacancy = $this->baseVacancy->setId(1)->setTitle("this is a title")->setDescription("this is a description for a vacancy")->setStartDate($this->now)->setUrlid("/vacancy/this_is_a_title");
 }
开发者ID:howest-wsde,项目名称:VrijwilligersTool,代码行数:10,代码来源:VacancyTest.php

示例15: testPassesValidationWithNullScoreWithForfeit

 public function testPassesValidationWithNullScoreWithForfeit()
 {
     $setScore = new SetScore();
     $setScore->setTeamBForfeit();
     $validator = Validation::createValidatorBuilder()->addMethodMapping('loadValidatorMetadata')->getValidator();
     $this->assertEmpty($validator->validate($setScore));
 }
开发者ID:pdt256,项目名称:vbscraper,代码行数:7,代码来源:SetScoreTest.php


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