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


PHP Validator\Validation类代码示例

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


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

示例1: validate

 /**
  * Runs the validation against the provided array of fields
  *
  * @param array $data
  */
 public function validate(array $data)
 {
     $this->original_values = $data;
     $this->final_values = $data;
     $validator = SymfonyValidation::createValidator();
     $violations_arr = [];
     $this->violations = new ViolationCollection([]);
     foreach ($this->constraints as $key => $constraint) {
         // we always keep the variables set someway
         if (!isset($this->final_values[$key])) {
             $this->final_values[$key] = false;
         }
         // if it isn't an array and we just request a Trim
         if (!is_array($constraint) && $constraint instanceof ActiveConstraint) {
             $this->final_values[$key] = $constraint->run($this->final_values[$key]);
             // it's not a classic symfony constraint, get rid of it
             $constraint = [];
         }
         if (is_array($constraint)) {
             foreach ($constraint as $k => $c) {
                 if ($c instanceof ActiveConstraint) {
                     $this->final_values[$key] = $c->run($this->final_values[$key]);
                     // it's not a classic symfony constraint, get rid of it
                     unset($constraint[$k]);
                 }
             }
         }
         $violations = $validator->validateValue($this->final_values[$key], $constraint);
         if ($violations->count() > 0) {
             $violations_arr[$key] = new Violation($violations, $key, $this->labels[$key]);
         }
         $this->violations = new ViolationCollection($violations_arr);
     }
 }
开发者ID:KasaiDot,项目名称:FoolFrame,代码行数:39,代码来源:Validator.php

示例2: __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

示例3: 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

示例4: 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

示例5: getExtensions

 /**
  * @return array
  */
 protected function getExtensions()
 {
     $accountUserRoleSelectType = new EntitySelectTypeStub($this->getRoles(), AccountUserRoleSelectType::NAME, new AccountUserRoleSelectType());
     $addressEntityType = new EntityType($this->getAddresses(), 'test_address_entity');
     $accountSelectType = new AccountSelectTypeStub($this->getAccounts(), AccountSelectType::NAME);
     return [new PreloadedExtension([OroDateType::NAME => new OroDateType(), AccountUserRoleSelectType::NAME => $accountUserRoleSelectType, $accountSelectType->getName() => $accountSelectType, AddressCollectionTypeStub::NAME => new AddressCollectionTypeStub(), $addressEntityType->getName() => $addressEntityType], []), new ValidatorExtension(Validation::createValidator())];
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:10,代码来源:AccountUserTypeTest.php

示例6: 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

示例7: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->serializer = SerializerBuilder::create()->build();
     $this->validator = Validation::createValidator();
     $this->action->setSerializer($this->serializer)->setValidator($this->validator);
 }
开发者ID:amstaffix,项目名称:rest-crud-actions,代码行数:7,代码来源:PostActionTest.php

示例8: validate

 public function validate(array $parameters)
 {
     $validator = Validation::createValidator();
     $constraints = new Collection(['method' => new Assert\Required(), 'source_id' => [new Assert\Required(), new Assert\Length(['max' => 45])], 'amount' => [new Assert\GreaterThan(0), new Assert\Required()], 'currency' => [new Assert\Length(3), new Assert\Optional()], 'description' => [new Assert\Length(['max' => 250]), new Assert\Required()], 'order_id' => [new Assert\Length(['max' => 100]), new Assert\Optional()], 'device_session_id' => [new Assert\Length(['max' => 255]), new Assert\Optional()], 'capture' => new Assert\Optional(), 'customer' => new Assert\Optional(), 'metadata' => new Assert\Optional(), 'use_card_points' => new Assert\Optional()]);
     $violations = $validator->validate($parameters, $constraints);
     return $violations;
 }
开发者ID:degaray,项目名称:openpay-php-client,代码行数:7,代码来源:OpenpayChargeValidator.php

示例9: 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

示例10: validate

 public function validate(array $parameters)
 {
     $validator = Validation::createValidator();
     $constraints = new Collection(['token_id' => new Assert\Required(), 'device_session_id' => new Assert\Optional()]);
     $violations = $validator->validate($parameters, $constraints);
     return $violations;
 }
开发者ID:degaray,项目名称:openpay-php-client,代码行数:7,代码来源:OpenpayCardTokenValidator.php

示例11: validate

 public function validate(array $parameters)
 {
     $validator = Validation::createValidator();
     $constraints = new Collection(['line1' => new Assert\Required(), 'line2' => new Assert\Optional(), 'line3' => new Assert\Optional(), 'postal_code' => new Assert\Length(['min' => 5]), 'state' => [new Assert\Length(['min' => 2]), new Assert\Required()], 'city' => new Assert\Required(), 'country_code' => [new Assert\Length(['min' => 2, 'max' => 2]), new Assert\Required()]]);
     $violations = $validator->validate($parameters, $constraints);
     return $violations;
 }
开发者ID:degaray,项目名称:openpay-php-client,代码行数:7,代码来源:OpenpayAddressValidator.php

示例12: 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

示例13: validate

 public function validate(array $parameters)
 {
     $validator = Validation::createValidator();
     $constraints = new Collection(['customer_id' => [new Assert\Required(), new Assert\Length(['max' => 45])], 'amount' => [new Assert\GreaterThan(0), new Assert\Required()], 'description' => [new Assert\Length(['max' => 250]), new Assert\Required()], 'order_id' => [new Assert\Length(['max' => 100]), new Assert\Optional()]]);
     $violations = $validator->validate($parameters, $constraints);
     return $violations;
 }
开发者ID:degaray,项目名称:openpay-php-client,代码行数:7,代码来源:OpenpayFeeValidator.php

示例14: 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

示例15: 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


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