File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
lib/internal/Magento/Framework Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \Framework ;
9
+
10
+ use Magento \Framework \App \ObjectManager ;
11
+ use Magento \Framework \Validator \RegexFactory ;
12
+
13
+ class RegexValidator extends RegexFactory
14
+ {
15
+
16
+ /**
17
+ * @var RegexFactory
18
+ */
19
+ private RegexFactory $ regexValidatorFactory ;
20
+
21
+ /**
22
+ * Validation pattern for handles array
23
+ */
24
+ private const VALIDATION_RULE_PATTERN = '/^[a-z0-9,.]+[a-z0-9_,.]*$/i ' ;
25
+
26
+ /**
27
+ * @param RegexFactory|null $regexValidatorFactory
28
+ */
29
+ public function __construct (
30
+ ?RegexFactory $ regexValidatorFactory = null
31
+ ) {
32
+ $ this ->regexValidatorFactory = $ regexValidatorFactory
33
+ ?: ObjectManager::getInstance ()->get (RegexFactory::class);
34
+ }
35
+
36
+ /**
37
+ * Validates parameter regex
38
+ *
39
+ * @param string $params
40
+ * @param string $pattern
41
+ * @return bool
42
+ */
43
+ public function validateParamRegex ($ params , $ pattern = self ::VALIDATION_RULE_PATTERN )
44
+ {
45
+ $ validator = $ this ->regexValidatorFactory ->create (['pattern ' => $ pattern ]);
46
+
47
+ if ($ params && !$ validator ->isValid ($ params )) {
48
+ return false ;
49
+ }
50
+
51
+ return true ;
52
+ }
53
+ }
You can’t perform that action at this time.
0 commit comments