當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Validation::createValidator方法代碼示例

本文整理匯總了PHP中Symfony\Component\Validator\Validation::createValidator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validation::createValidator方法的具體用法?PHP Validation::createValidator怎麽用?PHP Validation::createValidator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Validator\Validation的用法示例。


在下文中一共展示了Validation::createValidator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

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

示例3: getFormValidator

 protected function getFormValidator()
 {
     if (is_null($this->formValidator)) {
         $this->formValidator = \Symfony\Component\Validator\Validation::createValidator();
     }
     return $this->formValidator;
 }
開發者ID:deltaphp,項目名稱:deltacore,代碼行數:7,代碼來源:TwigView.php

示例4: __construct

 /**
  * FormFactory constructor.
  * @param Container $container
  */
 public function __construct(Container $container)
 {
     # configuring the form factory
     $this->formFactory = Forms::createFormFactoryBuilder()->addExtension(new DoctrineOrmExtension(new ExtendedEntityManager($container->get('models'))))->addExtension(new ValidatorExtension(Validation::createValidator()))->getFormFactory();
     # registering all necessary smarty plugins
     new SmartyPlugins($this->getFormHelper(), $container->get('template'));
 }
開發者ID:bcremer,項目名稱:shopware-symfony-forms,代碼行數:11,代碼來源:FormFactory.php

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

示例6: searchByIsbn

 /**
  * Search by isbn
  *
  * @param  string $isbn
  * @return array
  */
 public function searchByIsbn($isbn)
 {
     $isbn = trim($isbn);
     $isbn = str_replace('-', '', $isbn);
     // Validate isbn
     $validator = Validation::createValidator();
     $violations = $validator->validateValue($isbn, new Isbn());
     if (count($violations) > 0) {
         return false;
     }
     // Use providers to search for book
     foreach ($this->providers as $provider) {
         $result = $provider['provider']->searchByIsbn($isbn)->getResult();
         if ($result) {
             if (isset($provider['name']) && null !== $provider['name']) {
                 $providerName = $provider['name'];
             } else {
                 $providerName = $provider['provider']->getDefaultName();
             }
             $response = new BookFinderResponse();
             $response->setProvider($provider['provider']);
             $response->setResult($result);
             $response->setProviderName($providerName);
             return $response;
         }
     }
     return false;
 }
開發者ID:sprain,項目名稱:SprainBookFinder,代碼行數:34,代碼來源:BookFinder.php

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

示例8: validateFieldValue

 /**
  * @param      $type
  * @param      $value
  * @param null $f
  *
  * @return array
  */
 public function validateFieldValue($type, $value, $f = null)
 {
     $errors = array();
     if (isset($this->types[$type]['constraints'])) {
         $validator = Validation::createValidator();
         foreach ($this->types[$type]['constraints'] as $constraint => $opts) {
             //don't check empty values unless the constraint is NotBlank
             if (strpos($constraint, 'NotBlank') === false && empty($value)) {
                 continue;
             }
             if ($type == 'captcha' && strpos($constraint, 'EqualTo') !== false) {
                 $props = $f->getProperties();
                 $opts['value'] = $props['captcha'];
             }
             $violations = $validator->validateValue($value, new $constraint($opts));
             if (count($violations)) {
                 foreach ($violations as $v) {
                     $transParameters = $v->getMessageParameters();
                     if ($f !== null) {
                         $transParameters['%label%'] = """ . $f->getLabel() . """;
                     }
                     $errors[] = $this->translator->trans($v->getMessage(), $transParameters, 'validators');
                 }
             }
         }
     }
     return $errors;
 }
開發者ID:Jandersolutions,項目名稱:mautic,代碼行數:35,代碼來源:FormFieldHelper.php

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

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

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

示例12: getExtensions

 /**
  * @return array
  */
 protected function getExtensions()
 {
     $entityType = new EntityType([1 => $this->getEntity('OroB2B\\Bundle\\PricingBundle\\Entity\\PriceList', 1), 2 => $this->getEntity('OroB2B\\Bundle\\PricingBundle\\Entity\\PriceList', 2)]);
     $productUnitSelection = new EntityType($this->prepareProductUnitSelectionChoices(), ProductUnitSelectionType::NAME);
     $priceType = new PriceType();
     $priceType->setDataClass('Oro\\Bundle\\CurrencyBundle\\Model\\Price');
     return [new PreloadedExtension([$entityType->getName() => $entityType, PriceListSelectType::NAME => new PriceListSelectTypeStub(), ProductUnitSelectionType::NAME => $productUnitSelection, PriceType::NAME => $priceType, CurrencySelectionType::NAME => new CurrencySelectionTypeStub()], []), new ValidatorExtension(Validation::createValidator())];
 }
開發者ID:adam-paterson,項目名稱:orocommerce,代碼行數:11,代碼來源:ProductPriceTypeTest.php

示例13: __construct

 public function __construct($form_config, $csrf_provider_service)
 {
     FormService::validate($form_config);
     $this->config = $form_config;
     // $csrfProvider = new DefaultCsrfProvider( $form_config['csrf_secret'] );
     // setup forms to use csrf and validator component
     $this->formFactory = Forms::createFormFactoryBuilder()->addExtension(new CsrfExtension($csrf_provider_service))->addExtension(new ValidatorExtension(Validation::createValidator()))->addExtension(new HttpFoundationExtension())->getFormFactory();
 }
開發者ID:renegare,項目名稱:skip_php_framework,代碼行數:8,代碼來源:FormService.php

示例14: validate

 public function validate()
 {
     $validator = SymphonyValidation::createValidator();
     $violations = $validator->validateValue($this->val, $this->constraints);
     if ($violations->count() > 0) {
         throw new ValidationException($violations);
     }
 }
開發者ID:fliglio,項目名稱:web,代碼行數:8,代碼來源:Param.php

示例15: validateData

 /**
  * @param $data
  * @param $service
  * @return \Symfony\Component\Validator\ConstraintViolationListInterface
  */
 public static function validateData($data, $service)
 {
     $translator = Translator::getInstance();
     $validator = Validation::createValidator();
     $constraints = new Constraints\Collection(['fields' => ['tnt_service' => [new Constraints\Choice(['choices' => array('INDIVIDUAL', 'ENTERPRISE', 'DEPOT', 'DROPOFFPOINT'), 'message' => $translator->trans('Unknown service', [], TNTFrance::MESSAGE_DOMAIN), 'groups' => ['INDIVIDUAL', 'ENTERPRISE', 'DEPOT', 'DROPOFFPOINT']])], 'tnt_serviceCode' => [new Constraints\Length(['min' => 1, 'minMessage' => $translator->trans('The service is not valid', [], TNTFrance::MESSAGE_DOMAIN), 'groups' => ['INDIVIDUAL', 'ENTERPRISE', 'DEPOT', 'DROPOFFPOINT']])], 'tnt_instructions' => [new Constraints\Length(['min' => 0, 'max' => 60, 'maxMessage' => $translator->trans('Instructions are too long', [], TNTFrance::MESSAGE_DOMAIN), 'groups' => ['INDIVIDUAL', 'ENTERPRISE', 'DEPOT', 'DROPOFFPOINT']])], 'tnt_contactLastName' => [new Constraints\NotBlank(['groups' => ['DEPOT', 'DROPOFFPOINT']]), new Constraints\Length(['min' => 0, 'max' => 19, 'maxMessage' => $translator->trans('Last name is too long', [], TNTFrance::MESSAGE_DOMAIN), 'groups' => ['DEPOT', 'DROPOFFPOINT']])], 'tnt_contactFirstName' => [new Constraints\NotBlank(['groups' => ['DEPOT', 'DROPOFFPOINT']]), new Constraints\Length(['min' => 0, 'max' => 12, 'maxMessage' => $translator->trans('First name is too long', [], TNTFrance::MESSAGE_DOMAIN), 'groups' => ['DEPOT', 'DROPOFFPOINT']])], 'tnt_emailAdress' => [new Constraints\Email(['groups' => ['DEPOT', 'DROPOFFPOINT']]), new Constraints\Length(['min' => 0, 'max' => 60, 'maxMessage' => $translator->trans('Email is too long', [], TNTFrance::MESSAGE_DOMAIN), 'groups' => ['DEPOT', 'DROPOFFPOINT']])], 'tnt_phoneNumber' => [new Constraints\NotBlank(['groups' => ['INDIVIDUAL', 'DROPOFFPOINT']]), new Constraints\Length(['min' => 0, 'max' => 60, 'maxMessage' => $translator->trans('Phone number is too long', [], TNTFrance::MESSAGE_DOMAIN), 'groups' => ['INDIVIDUAL', 'DROPOFFPOINT']])], 'tnt_pexcode' => new Constraints\NotBlank(['groups' => ['DEPOT']]), 'tnt_depot_address' => new Constraints\NotBlank(['groups' => ['DEPOT']]), 'tnt_xettcode' => new Constraints\NotBlank(['groups' => ['DROPOFFPOINT']]), 'tnt_dop_address' => new Constraints\NotBlank(['groups' => ['DROPOFFPOINT']])], 'allowMissingFields' => true, 'allowExtraFields' => true]);
     $errors = $validator->validateValue($data, $constraints, [$service]);
     return $errors;
 }
開發者ID:roadster31,項目名稱:TNTFrance,代碼行數:13,代碼來源:DataValidator.php


注:本文中的Symfony\Component\Validator\Validation::createValidator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。