Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Factory.php
Go to the documentation of this file.
1 <?php
10 
14 
19 class Factory
20 {
25 
29  public function __construct(UniversalFactory $validatorBuilderFactory)
30  {
31  $this->_validatorBuilderFactory = $validatorBuilderFactory;
32  }
33 
40  public function createColorValidator($currentColor)
41  {
42  $message = __(
43  'Conversion Color value is not valid "%1". Please set hexadecimal 6-digit value.',
44  $currentColor
45  );
47  $builder = $this->_validatorBuilderFactory->create(
48  \Magento\Framework\Validator\Builder::class,
49  [
50  'constraints' => [
51  [
52  'alias' => 'Regex',
53  'type' => '',
54  'class' => \Magento\Framework\Validator\Regex::class,
55  'options' => [
56  'arguments' => ['pattern' => '/^[0-9a-f]{6}$/i'],
57  'methods' => [
58  [
59  'method' => 'setMessages',
60  'arguments' => [
62  ],
63  ],
64  ],
65  ],
66  ],
67  ]
68  ]
69  );
70  return $builder->createValidator();
71  }
72 
79  public function createConversionIdValidator($currentId)
80  {
81  $message = __('Conversion Id value is not valid "%1". Conversion Id should be an integer.', $currentId);
83  $builder = $this->_validatorBuilderFactory->create(
84  \Magento\Framework\Validator\Builder::class,
85  [
86  'constraints' => [
87  [
88  'alias' => 'Int',
89  'type' => '',
90  'class' => \Magento\Framework\Validator\IntUtils::class,
91  'options' => [
92  'methods' => [
93  [
94  'method' => 'setMessages',
95  'arguments' => [[IntUtils::NOT_INT => $message, IntUtils::INVALID => $message]],
96  ],
97  ],
98  ],
99  ],
100  ]
101  ]
102  );
103  return $builder->createValidator();
104  }
105 }
__construct(UniversalFactory $validatorBuilderFactory)
Definition: Factory.php:29
__()
Definition: __.php:13
$message
const NOT_INT
Definition: Int.php:41
const INVALID
Definition: Int.php:40