@@ -53,20 +53,17 @@ public function generateFromPath($path, $format = 'es6', $withVendor = false, $l
53
53
54
54
$ locales = [];
55
55
$ files = [];
56
- $ dir = new DirectoryIterator ($ path );
56
+ $ dirList = $ this -> getDirList ($ path );
57
57
$ jsBody = '' ;
58
- foreach ($ dir as $ fileinfo ) {
59
- if (!$ fileinfo ->isDot ()) {
58
+ foreach ($ dirList as $ file ) {
60
59
if (!$ withVendor
61
- && in_array ($ fileinfo -> getFilename () , array_merge (['vendor ' ], $ this ->config ['excludes ' ]))
60
+ && in_array ($ file , array_merge (['vendor ' ], $ this ->config ['excludes ' ]))
62
61
) {
63
62
continue ;
64
63
}
65
64
66
- $ files [] = $ fileinfo ->getRealPath ();
67
- }
65
+ $ files [] = $ path . DIRECTORY_SEPARATOR . $ file ;
68
66
}
69
- asort ($ files );
70
67
71
68
foreach ($ files as $ fileName ) {
72
69
$ fileinfo = new \SplFileInfo ($ fileName );
@@ -127,25 +124,23 @@ public function generateMultiple($path, $format = 'es6', $multiLocales = false)
127
124
$ locales = [];
128
125
$ fileToCreate = '' ;
129
126
$ createdFiles = '' ;
130
- $ dir = new DirectoryIterator ($ path );
127
+ $ dirList = $ this -> getDirList ($ path );
131
128
$ jsBody = '' ;
132
- foreach ($ dir as $ fileinfo ) {
133
- if (!$ fileinfo ->isDot ()
134
- && !in_array ($ fileinfo ->getFilename (), array_merge (['vendor ' ], $ this ->config ['excludes ' ]))
135
- && $ fileinfo !== ''
136
- ) {
137
- $ noExt = $ this ->removeExtension ($ fileinfo ->getFilename ());
129
+ foreach ($ dirList as $ file ) {
130
+ if (!in_array ($ file , array_merge (['vendor ' ], $ this ->config ['excludes ' ]))) {
131
+ $ noExt = $ this ->removeExtension ($ file );
138
132
if ($ noExt !== '' ) {
139
133
if (class_exists ('App ' )) {
140
134
App::setLocale ($ noExt );
141
135
}
142
136
if (!in_array ($ noExt , $ this ->availableLocales )) {
143
137
$ this ->availableLocales [] = $ noExt ;
144
138
}
145
- if ($ fileinfo ->isDir ()) {
146
- $ local = $ this ->allocateLocaleArray ($ fileinfo ->getRealPath (), $ multiLocales );
139
+ $ filePath = $ path . DIRECTORY_SEPARATOR . $ file ;
140
+ if (is_dir ($ filePath )) {
141
+ $ local = $ this ->allocateLocaleArray ($ filePath , $ multiLocales );
147
142
} else {
148
- $ local = $ this ->allocateLocaleJSON ($ fileinfo -> getRealPath () );
143
+ $ local = $ this ->allocateLocaleJSON ($ filePath );
149
144
if ($ local === null ) continue ;
150
145
}
151
146
@@ -207,21 +202,15 @@ private function allocateLocaleJSON($path)
207
202
private function allocateLocaleArray ($ path , $ multiLocales = false )
208
203
{
209
204
$ data = [];
210
- $ dir = new DirectoryIterator ($ path );
205
+ $ dirList = $ this -> getDirList ($ path );
211
206
$ lastLocale = last ($ this ->availableLocales );
212
- foreach ($ dir as $ fileinfo ) {
213
- // Do not mess with dotfiles at all.
214
- if ($ fileinfo ->isDot ()) {
215
- continue ;
216
- }
217
-
218
- if ($ fileinfo ->isDir ()) {
219
- // Recursivley iterate through subdirs, until everything is allocated.
220
-
221
- $ data [$ fileinfo ->getFilename ()] = $ this ->allocateLocaleArray ($ path . DIRECTORY_SEPARATOR . $ fileinfo ->getFilename ());
207
+ foreach ($ dirList as $ file ) {
208
+ $ fileName = $ path . DIRECTORY_SEPARATOR . $ file ;
209
+ if (is_dir ($ fileName )) {
210
+ // Recursively iterate through subdirs, until everything is allocated.
211
+ $ data [$ file ] = $ this ->allocateLocaleArray ($ fileName );
222
212
} else {
223
- $ noExt = $ this ->removeExtension ($ fileinfo ->getFilename ());
224
- $ fileName = $ path . DIRECTORY_SEPARATOR . $ fileinfo ->getFilename ();
213
+ $ noExt = $ this ->removeExtension ($ file );
225
214
226
215
// Ignore non *.php files (ex.: .gitignore, vim swap files etc.)
227
216
if (pathinfo ($ fileName , PATHINFO_EXTENSION ) !== 'php ' ) {
@@ -362,6 +351,17 @@ function ($matches) {
362
351
);
363
352
}
364
353
354
+ /**
355
+ * Gets sorted directory list excluding dot files
356
+ *
357
+ * @param string $path
358
+ * @return array
359
+ */
360
+ private function getDirList ($ path )
361
+ {
362
+ return array_diff (scandir ($ path ), ['. ' , '.. ' ]);
363
+ }
364
+
365
365
/**
366
366
* Returns filename, with extension stripped
367
367
* @param string $filename
0 commit comments