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,24 @@ 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
59
55
*/
60
56
public function __construct (
61
- \ Magento \ Framework \ ObjectManagerInterface $ objectManager ,
62
- \ Magento \ Framework \ Module \ Dir \ Reader $ moduleReader ,
57
+ ObjectManagerInterface $ objectManager ,
58
+ Reader $ moduleReader ,
63
59
FrontendInterface $ cache
64
60
) {
65
61
$ this ->_objectManager = $ objectManager ;
66
62
$ this ->moduleReader = $ moduleReader ;
67
- $ this ->cache = $ cache ;
68
63
}
69
64
70
65
/**
@@ -75,32 +70,23 @@ public function __construct(
75
70
protected function _initializeConfigList ()
76
71
{
77
72
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
- }
73
+ $ this ->_configFiles = $ this ->moduleReader ->getConfigurationFiles ('validation.xml ' );
89
74
}
90
75
}
91
76
92
77
/**
93
78
* Create and set default translator to \Magento\Framework\Validator\AbstractValidator.
94
79
*
95
80
* @return void
81
+ * @throws \Zend_Translate_Exception
96
82
*/
97
83
protected function _initializeDefaultTranslator ()
98
84
{
99
85
if (!$ this ->isDefaultTranslatorInitialized ) {
100
86
// Pass translations to \Magento\Framework\TranslateInterface from validators
101
87
$ translatorCallback = function () {
102
88
$ argc = func_get_args ();
103
- return (string )new \ Magento \ Framework \ Phrase (array_shift ($ argc ), $ argc );
89
+ return (string )new Phrase (array_shift ($ argc ), $ argc );
104
90
};
105
91
/** @var \Magento\Framework\Translate\Adapter $translator */
106
92
$ translator = $ this ->_objectManager ->create (\Magento \Framework \Translate \Adapter::class);
@@ -115,14 +101,15 @@ protected function _initializeDefaultTranslator()
115
101
*
116
102
* Will instantiate \Magento\Framework\Validator\Config
117
103
*
118
- * @return \Magento\Framework\Validator\Config
104
+ * @return Config
105
+ * @throws \Zend_Translate_Exception
119
106
*/
120
107
public function getValidatorConfig ()
121
108
{
122
109
$ this ->_initializeConfigList ();
123
110
$ this ->_initializeDefaultTranslator ();
124
111
return $ this ->_objectManager ->create (
125
- \ Magento \ Framework \ Validator \ Config::class,
112
+ Config::class,
126
113
['configFiles ' => $ this ->_configFiles ]
127
114
);
128
115
}
@@ -133,7 +120,8 @@ public function getValidatorConfig()
133
120
* @param string $entityName
134
121
* @param string $groupName
135
122
* @param array|null $builderConfig
136
- * @return \Magento\Framework\Validator\Builder
123
+ * @return Builder
124
+ * @throws \Zend_Translate_Exception
137
125
*/
138
126
public function createValidatorBuilder ($ entityName , $ groupName , array $ builderConfig = null )
139
127
{
@@ -147,43 +135,12 @@ public function createValidatorBuilder($entityName, $groupName, array $builderCo
147
135
* @param string $entityName
148
136
* @param string $groupName
149
137
* @param array|null $builderConfig
150
- * @return \Magento\Framework\Validator
138
+ * @return Validator
139
+ * @throws \Zend_Translate_Exception
151
140
*/
152
141
public function createValidator ($ entityName , $ groupName , array $ builderConfig = null )
153
142
{
154
143
$ this ->_initializeDefaultTranslator ();
155
144
return $ this ->getValidatorConfig ()->createValidator ($ entityName , $ groupName , $ builderConfig );
156
145
}
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
146
}
0 commit comments