本文整理汇总了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;
}
示例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;
}
示例3: getFormValidator
protected function getFormValidator()
{
if (is_null($this->formValidator)) {
$this->formValidator = \Symfony\Component\Validator\Validation::createValidator();
}
return $this->formValidator;
}
示例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'));
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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())];
}
示例10: setUp
protected function setUp()
{
parent::setUp();
$this->serializer = SerializerBuilder::create()->build();
$this->validator = Validation::createValidator();
$this->action->setSerializer($this->serializer)->setValidator($this->validator);
}
示例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;
}
示例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())];
}
示例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();
}
示例14: validate
public function validate()
{
$validator = SymphonyValidation::createValidator();
$violations = $validator->validateValue($this->val, $this->constraints);
if ($violations->count() > 0) {
throw new ValidationException($violations);
}
}
示例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;
}