Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
ValidationRules.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
15  protected $inputValidationMap = [
16  'alpha' => 'validate-alpha',
17  'numeric' => 'validate-number',
18  'alphanumeric' => 'validate-alphanum',
19  'url' => 'validate-url',
20  'email' => 'validate-email',
21  ];
22 
30  public function getValidationRules($isRequired, $validationRules)
31  {
32  $rules = [];
33  if ($isRequired) {
34  $rules['required-entry'] = true;
35  }
36  if (empty($validationRules)) {
37  return $rules;
38  }
40  foreach ($validationRules as $rule) {
41  if (!$rule instanceof ValidationRuleInterface) {
42  continue;
43  }
44  $validationClass = $this->getValidationClass($rule);
45  if ($validationClass) {
46  $rules[$validationClass] = $this->getRuleValue($rule);
47  }
48  }
49 
50  return $rules;
51  }
52 
60  {
61  $key = $rule->getName() == 'input_validation' ? $rule->getValue() : $rule->getName();
62  return isset($this->inputValidationMap[$key])
63  ? $this->inputValidationMap[$key]
64  : $key;
65  }
66 
74  {
75  return $rule->getName() != 'input_validation' ? $rule->getValue() : true;
76  }
77 }