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