5
5
*/
6
6
namespace Magento \Deploy \Model ;
7
7
8
- use Symfony \Component \Console \Output \OutputInterface ;
9
- use Magento \Framework \App \State ;
10
- use Magento \Framework \App \DeploymentConfig \Writer ;
11
8
use Magento \Framework \App \Filesystem \DirectoryList ;
12
9
use Magento \Framework \Exception \LocalizedException ;
10
+ use Magento \Framework \Validator \Locale ;
13
11
use Magento \User \Model \ResourceModel \User \Collection as UserCollection ;
12
+ use Symfony \Component \Console \Output \OutputInterface ;
14
13
15
14
/**
16
15
* Generate static files, compile
17
16
*
18
- * Сlear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories
17
+ * Clear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories
19
18
*
20
19
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21
20
*/
@@ -50,21 +49,6 @@ class Filesystem
50
49
*/
51
50
const DEFAULT_THEME = 'Magento/blank ' ;
52
51
53
- /**
54
- * @var \Magento\Framework\App\DeploymentConfig\Writer
55
- */
56
- private $ writer ;
57
-
58
- /**
59
- * @var \Magento\Framework\App\DeploymentConfig\Reader
60
- */
61
- private $ reader ;
62
-
63
- /**
64
- * @var \Magento\Framework\ObjectManagerInterface
65
- */
66
- private $ objectManager ;
67
-
68
52
/**
69
53
* @var \Magento\Framework\Filesystem
70
54
*/
@@ -101,33 +85,35 @@ class Filesystem
101
85
private $ userCollection ;
102
86
103
87
/**
104
- * @param \Magento\Framework\App\DeploymentConfig\Writer $writer
105
- * @param \Magento\Framework\App\DeploymentConfig\Reader $reader
106
- * @param \Magento\Framework\ObjectManagerInterface $objectManager
88
+ * @var Locale
89
+ */
90
+ private $ locale ;
91
+
92
+ /**
107
93
* @param \Magento\Framework\Filesystem $filesystem
108
94
* @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
109
95
* @param \Magento\Framework\Filesystem\Driver\File $driverFile
110
96
* @param \Magento\Store\Model\Config\StoreView $storeView
111
97
* @param \Magento\Framework\ShellInterface $shell
98
+ * @param UserCollection $userCollection
99
+ * @param Locale $locale
112
100
*/
113
101
public function __construct (
114
- \Magento \Framework \App \DeploymentConfig \Writer $ writer ,
115
- \Magento \Framework \App \DeploymentConfig \Reader $ reader ,
116
- \Magento \Framework \ObjectManagerInterface $ objectManager ,
117
102
\Magento \Framework \Filesystem $ filesystem ,
118
103
\Magento \Framework \App \Filesystem \DirectoryList $ directoryList ,
119
104
\Magento \Framework \Filesystem \Driver \File $ driverFile ,
120
105
\Magento \Store \Model \Config \StoreView $ storeView ,
121
- \Magento \Framework \ShellInterface $ shell
106
+ \Magento \Framework \ShellInterface $ shell ,
107
+ UserCollection $ userCollection ,
108
+ Locale $ locale
122
109
) {
123
- $ this ->writer = $ writer ;
124
- $ this ->reader = $ reader ;
125
- $ this ->objectManager = $ objectManager ;
126
110
$ this ->filesystem = $ filesystem ;
127
111
$ this ->directoryList = $ directoryList ;
128
112
$ this ->driverFile = $ driverFile ;
129
113
$ this ->storeView = $ storeView ;
130
114
$ this ->shell = $ shell ;
115
+ $ this ->userCollection = $ userCollection ;
116
+ $ this ->locale = $ locale ;
131
117
$ this ->functionCallPath =
132
118
PHP_BINARY . ' -f ' . BP . DIRECTORY_SEPARATOR . 'bin ' . DIRECTORY_SEPARATOR . 'magento ' ;
133
119
}
@@ -141,7 +127,7 @@ public function __construct(
141
127
public function regenerateStatic (
142
128
OutputInterface $ output
143
129
) {
144
- // Сlear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories
130
+ // Clear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories
145
131
$ this ->cleanupFilesystem (
146
132
[
147
133
DirectoryList::CACHE ,
@@ -193,7 +179,7 @@ protected function deployStaticContent(
193
179
private function getAdminUserInterfaceLocales ()
194
180
{
195
181
$ locales = [];
196
- foreach ($ this ->getUserCollection () as $ user ) {
182
+ foreach ($ this ->userCollection as $ user ) {
197
183
$ locales [] = $ user ->getInterfaceLocale ();
198
184
}
199
185
return $ locales ;
@@ -203,32 +189,26 @@ private function getAdminUserInterfaceLocales()
203
189
* Get used store and admin user locales
204
190
*
205
191
* @return array
192
+ * @throws \InvalidArgumentException if unknown locale is provided by the store configuration
206
193
*/
207
194
private function getUsedLocales ()
208
195
{
209
196
$ usedLocales = array_merge (
210
197
$ this ->storeView ->retrieveLocales (),
211
198
$ this ->getAdminUserInterfaceLocales ()
212
199
);
213
- return array_unique ($ usedLocales );
214
- }
215
-
216
- /**
217
- * Get user collection
218
- *
219
- * @return UserCollection
220
- * @deprecated 100.1.0 Added to not break backward compatibility of the constructor signature
221
- * by injecting the new dependency directly.
222
- * The method can be removed in a future major release, when constructor signature can be changed.
223
- */
224
- private function getUserCollection ()
225
- {
226
- if (!($ this ->userCollection instanceof UserCollection)) {
227
- return \Magento \Framework \App \ObjectManager::getInstance ()->get (
228
- UserCollection::class
229
- );
230
- }
231
- return $ this ->userCollection ;
200
+ return array_map (
201
+ function ($ locale ) {
202
+ if (!$ this ->locale ->isValid ($ locale )) {
203
+ throw new \InvalidArgumentException (
204
+ $ locale .
205
+ ' argument has invalid value, run info:language:list for list of available locales '
206
+ );
207
+ }
208
+ return $ locale ;
209
+ },
210
+ array_unique ($ usedLocales )
211
+ );
232
212
}
233
213
234
214
/**
0 commit comments