6
6
7
7
namespace Magento \Framework \Validator ;
8
8
9
+ use Magento \Framework \Module \Dir \Reader ;
10
+ use Magento \Framework \ObjectManagerInterface ;
11
+ use Magento \Framework \Phrase ;
12
+ use Magento \Framework \Validator ;
9
13
use Magento \Framework \Cache \FrontendInterface ;
10
14
15
+ /**
16
+ * Factory for \Magento\Framework\Validator and \Magento\Framework\Validator\Builder.
17
+ */
11
18
class Factory
12
19
{
13
- /** cache key */
20
+ /**
21
+ * cache key
22
+ *
23
+ * @deprecated
24
+ */
14
25
const CACHE_KEY = __CLASS__ ;
15
26
16
27
/**
17
- * @var \Magento\Framework\ ObjectManagerInterface
28
+ * @var ObjectManagerInterface
18
29
*/
19
30
protected $ _objectManager ;
20
31
21
32
/**
22
33
* Validator config files
23
34
*
24
- * @var array |null
35
+ * @var iterable |null
25
36
*/
26
37
protected $ _configFiles = null ;
27
38
@@ -31,40 +42,25 @@ class Factory
31
42
private $ isDefaultTranslatorInitialized = false ;
32
43
33
44
/**
34
- * @var \Magento\Framework\Module\Dir\ Reader
45
+ * @var Reader
35
46
*/
36
47
private $ moduleReader ;
37
48
38
- /**
39
- * @var FrontendInterface
40
- */
41
- private $ cache ;
42
-
43
- /**
44
- * @var \Magento\Framework\Serialize\SerializerInterface
45
- */
46
- private $ serializer ;
47
-
48
- /**
49
- * @var \Magento\Framework\Config\FileIteratorFactory
50
- */
51
- private $ fileIteratorFactory ;
52
-
53
49
/**
54
50
* Initialize dependencies
55
51
*
56
- * @param \Magento\Framework\ObjectManagerInterface $objectManager
57
- * @param \Magento\Framework\Module\Dir\Reader $moduleReader
58
- * @param FrontendInterface $cache
52
+ * @param ObjectManagerInterface $objectManager
53
+ * @param Reader $moduleReader
54
+ * @param FrontendInterface $cache @deprecated
55
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
59
56
*/
60
57
public function __construct (
61
- \ Magento \ Framework \ ObjectManagerInterface $ objectManager ,
62
- \ Magento \ Framework \ Module \ Dir \ Reader $ moduleReader ,
58
+ ObjectManagerInterface $ objectManager ,
59
+ Reader $ moduleReader ,
63
60
FrontendInterface $ cache
64
61
) {
65
62
$ this ->_objectManager = $ objectManager ;
66
63
$ this ->moduleReader = $ moduleReader ;
67
- $ this ->cache = $ cache ;
68
64
}
69
65
70
66
/**
@@ -75,32 +71,23 @@ public function __construct(
75
71
protected function _initializeConfigList ()
76
72
{
77
73
if (!$ this ->_configFiles ) {
78
- $ this ->_configFiles = $ this ->cache ->load (self ::CACHE_KEY );
79
- if (!$ this ->_configFiles ) {
80
- $ this ->_configFiles = $ this ->moduleReader ->getConfigurationFiles ('validation.xml ' );
81
- $ this ->cache ->save (
82
- $ this ->getSerializer ()->serialize ($ this ->_configFiles ->toArray ()),
83
- self ::CACHE_KEY
84
- );
85
- } else {
86
- $ filesArray = $ this ->getSerializer ()->unserialize ($ this ->_configFiles );
87
- $ this ->_configFiles = $ this ->getFileIteratorFactory ()->create (array_keys ($ filesArray ));
88
- }
74
+ $ this ->_configFiles = $ this ->moduleReader ->getConfigurationFiles ('validation.xml ' );
89
75
}
90
76
}
91
77
92
78
/**
93
79
* Create and set default translator to \Magento\Framework\Validator\AbstractValidator.
94
80
*
95
81
* @return void
82
+ * @throws \Zend_Translate_Exception
96
83
*/
97
84
protected function _initializeDefaultTranslator ()
98
85
{
99
86
if (!$ this ->isDefaultTranslatorInitialized ) {
100
87
// Pass translations to \Magento\Framework\TranslateInterface from validators
101
88
$ translatorCallback = function () {
102
89
$ argc = func_get_args ();
103
- return (string )new \ Magento \ Framework \ Phrase (array_shift ($ argc ), $ argc );
90
+ return (string )new Phrase (array_shift ($ argc ), $ argc );
104
91
};
105
92
/** @var \Magento\Framework\Translate\Adapter $translator */
106
93
$ translator = $ this ->_objectManager ->create (\Magento \Framework \Translate \Adapter::class);
@@ -115,14 +102,15 @@ protected function _initializeDefaultTranslator()
115
102
*
116
103
* Will instantiate \Magento\Framework\Validator\Config
117
104
*
118
- * @return \Magento\Framework\Validator\Config
105
+ * @return Config
106
+ * @throws \Zend_Translate_Exception
119
107
*/
120
108
public function getValidatorConfig ()
121
109
{
122
110
$ this ->_initializeConfigList ();
123
111
$ this ->_initializeDefaultTranslator ();
124
112
return $ this ->_objectManager ->create (
125
- \ Magento \ Framework \ Validator \ Config::class,
113
+ Config::class,
126
114
['configFiles ' => $ this ->_configFiles ]
127
115
);
128
116
}
@@ -133,7 +121,8 @@ public function getValidatorConfig()
133
121
* @param string $entityName
134
122
* @param string $groupName
135
123
* @param array|null $builderConfig
136
- * @return \Magento\Framework\Validator\Builder
124
+ * @return Builder
125
+ * @throws \Zend_Translate_Exception
137
126
*/
138
127
public function createValidatorBuilder ($ entityName , $ groupName , array $ builderConfig = null )
139
128
{
@@ -147,43 +136,12 @@ public function createValidatorBuilder($entityName, $groupName, array $builderCo
147
136
* @param string $entityName
148
137
* @param string $groupName
149
138
* @param array|null $builderConfig
150
- * @return \Magento\Framework\Validator
139
+ * @return Validator
140
+ * @throws \Zend_Translate_Exception
151
141
*/
152
142
public function createValidator ($ entityName , $ groupName , array $ builderConfig = null )
153
143
{
154
144
$ this ->_initializeDefaultTranslator ();
155
145
return $ this ->getValidatorConfig ()->createValidator ($ entityName , $ groupName , $ builderConfig );
156
146
}
157
-
158
- /**
159
- * Get serializer
160
- *
161
- * @return \Magento\Framework\Serialize\SerializerInterface
162
- * @deprecated 100.2.0
163
- */
164
- private function getSerializer ()
165
- {
166
- if ($ this ->serializer === null ) {
167
- $ this ->serializer = $ this ->_objectManager ->get (
168
- \Magento \Framework \Serialize \SerializerInterface::class
169
- );
170
- }
171
- return $ this ->serializer ;
172
- }
173
-
174
- /**
175
- * Get file iterator factory
176
- *
177
- * @return \Magento\Framework\Config\FileIteratorFactory
178
- * @deprecated 100.2.0
179
- */
180
- private function getFileIteratorFactory ()
181
- {
182
- if ($ this ->fileIteratorFactory === null ) {
183
- $ this ->fileIteratorFactory = $ this ->_objectManager ->get (
184
- \Magento \Framework \Config \FileIteratorFactory::class
185
- );
186
- }
187
- return $ this ->fileIteratorFactory ;
188
- }
189
147
}
0 commit comments