當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。