11
11
use Magento \Framework \Exception \FileSystemException ;
12
12
use Magento \Framework \Filesystem \DriverInterface ;
13
13
use Magento \Framework \Filesystem \Glob ;
14
+ use Magento \Framework \Phrase ;
14
15
15
16
/**
16
- * Driver file class
17
+ * Filesystem driver that uses the local filesystem.
18
+ * Assumed that stat cache is cleanup before test filesystem
17
19
*
18
20
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
19
21
*/
@@ -47,11 +49,12 @@ protected function getWarningMessage()
47
49
*/
48
50
public function isExists ($ path )
49
51
{
50
- clearstatcache ();
51
- $ result = @file_exists ($ this ->getScheme () . $ path );
52
+ $ filename = $ this ->getScheme () . $ path ;
53
+ clearstatcache (false , $ filename );
54
+ $ result = @file_exists ($ filename );
52
55
if ($ result === null ) {
53
56
throw new FileSystemException (
54
- new \ Magento \ Framework \ Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
57
+ new Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
55
58
);
56
59
}
57
60
return $ result ;
@@ -66,11 +69,12 @@ public function isExists($path)
66
69
*/
67
70
public function stat ($ path )
68
71
{
69
- clearstatcache ();
70
- $ result = @stat ($ this ->getScheme () . $ path );
72
+ $ filename = $ this ->getScheme () . $ path ;
73
+ clearstatcache (false , $ filename );
74
+ $ result = @stat ($ filename );
71
75
if (!$ result ) {
72
76
throw new FileSystemException (
73
- new \ Magento \ Framework \ Phrase ('Cannot gather stats! %1 ' , [$ this ->getWarningMessage ()])
77
+ new Phrase ('Cannot gather stats! %1 ' , [$ this ->getWarningMessage ()])
74
78
);
75
79
}
76
80
return $ result ;
@@ -85,11 +89,12 @@ public function stat($path)
85
89
*/
86
90
public function isReadable ($ path )
87
91
{
88
- clearstatcache ();
89
- $ result = @is_readable ($ this ->getScheme () . $ path );
92
+ $ filename = $ this ->getScheme () . $ path ;
93
+ clearstatcache (false , $ filename );
94
+ $ result = @is_readable ($ filename );
90
95
if ($ result === null ) {
91
96
throw new FileSystemException (
92
- new \ Magento \ Framework \ Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
97
+ new Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
93
98
);
94
99
}
95
100
return $ result ;
@@ -104,11 +109,12 @@ public function isReadable($path)
104
109
*/
105
110
public function isFile ($ path )
106
111
{
107
- clearstatcache ();
108
- $ result = @is_file ($ this ->getScheme () . $ path );
112
+ $ filename = $ this ->getScheme () . $ path ;
113
+ clearstatcache (false , $ filename );
114
+ $ result = @is_file ($ filename );
109
115
if ($ result === null ) {
110
116
throw new FileSystemException (
111
- new \ Magento \ Framework \ Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
117
+ new Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
112
118
);
113
119
}
114
120
return $ result ;
@@ -123,11 +129,12 @@ public function isFile($path)
123
129
*/
124
130
public function isDirectory ($ path )
125
131
{
126
- clearstatcache ();
127
- $ result = @is_dir ($ this ->getScheme () . $ path );
132
+ $ filename = $ this ->getScheme () . $ path ;
133
+ clearstatcache (false , $ filename );
134
+ $ result = @is_dir ($ filename );
128
135
if ($ result === null ) {
129
136
throw new FileSystemException (
130
- new \ Magento \ Framework \ Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
137
+ new Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
131
138
);
132
139
}
133
140
return $ result ;
@@ -144,11 +151,12 @@ public function isDirectory($path)
144
151
*/
145
152
public function fileGetContents ($ path , $ flag = null , $ context = null )
146
153
{
147
- clearstatcache ();
148
- $ result = @file_get_contents ($ this ->getScheme () . $ path , $ flag , $ context );
154
+ $ filename = $ this ->getScheme () . $ path ;
155
+ clearstatcache (false , $ filename );
156
+ $ result = @file_get_contents ($ filename , $ flag , $ context );
149
157
if (false === $ result ) {
150
158
throw new FileSystemException (
151
- new \ Magento \ Framework \ Phrase (
159
+ new Phrase (
152
160
'The contents from the "%1" file can \'t be read. %2 ' ,
153
161
[$ path , $ this ->getWarningMessage ()]
154
162
)
@@ -166,11 +174,12 @@ public function fileGetContents($path, $flag = null, $context = null)
166
174
*/
167
175
public function isWritable ($ path )
168
176
{
169
- clearstatcache ();
170
- $ result = @is_writable ($ this ->getScheme () . $ path );
177
+ $ filename = $ this ->getScheme () . $ path ;
178
+ clearstatcache (false , $ filename );
179
+ $ result = @is_writable ($ filename );
171
180
if ($ result === null ) {
172
181
throw new FileSystemException (
173
- new \ Magento \ Framework \ Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
182
+ new Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
174
183
);
175
184
}
176
185
return $ result ;
@@ -224,7 +233,7 @@ private function mkdirRecursive($path, $permissions = 0777)
224
233
$ result = true ;
225
234
} else {
226
235
throw new FileSystemException (
227
- new \ Magento \ Framework \ Phrase (
236
+ new Phrase (
228
237
'Directory "%1" cannot be created %2 ' ,
229
238
[$ path , $ this ->getWarningMessage ()]
230
239
)
@@ -254,7 +263,7 @@ public function readDirectory($path)
254
263
sort ($ result );
255
264
return $ result ;
256
265
} catch (\Exception $ e ) {
257
- throw new FileSystemException (new \ Magento \ Framework \ Phrase ($ e ->getMessage ()), $ e );
266
+ throw new FileSystemException (new Phrase ($ e ->getMessage ()), $ e );
258
267
}
259
268
}
260
269
@@ -297,7 +306,7 @@ public function rename($oldPath, $newPath, DriverInterface $targetDriver = null)
297
306
}
298
307
if (!$ result ) {
299
308
throw new FileSystemException (
300
- new \ Magento \ Framework \ Phrase (
309
+ new Phrase (
301
310
'The path "%1" cannot be renamed into "%2" %3 ' ,
302
311
[$ oldPath , $ newPath , $ this ->getWarningMessage ()]
303
312
)
@@ -326,7 +335,7 @@ public function copy($source, $destination, DriverInterface $targetDriver = null
326
335
}
327
336
if (!$ result ) {
328
337
throw new FileSystemException (
329
- new \ Magento \ Framework \ Phrase (
338
+ new Phrase (
330
339
'The file or directory "%1" cannot be copied to "%2" %3 ' ,
331
340
[
332
341
$ source ,
@@ -356,7 +365,7 @@ public function symlink($source, $destination, DriverInterface $targetDriver = n
356
365
}
357
366
if (!$ result ) {
358
367
throw new FileSystemException (
359
- new \ Magento \ Framework \ Phrase (
368
+ new Phrase (
360
369
'A symlink for "%1" can \'t be created and placed to "%2". %3 ' ,
361
370
[
362
371
$ source ,
@@ -381,7 +390,7 @@ public function deleteFile($path)
381
390
$ result = @unlink ($ this ->getScheme () . $ path );
382
391
if (!$ result ) {
383
392
throw new FileSystemException (
384
- new \ Magento \ Framework \ Phrase (
393
+ new Phrase (
385
394
'The "%1" file can \'t be deleted. %2 ' ,
386
395
[$ path , $ this ->getWarningMessage ()]
387
396
)
@@ -417,7 +426,7 @@ public function deleteDirectory($path)
417
426
418
427
if (!empty ($ exceptionMessages )) {
419
428
throw new FileSystemException (
420
- new \ Magento \ Framework \ Phrase (
429
+ new Phrase (
421
430
\implode (' ' , $ exceptionMessages )
422
431
)
423
432
);
@@ -431,7 +440,7 @@ public function deleteDirectory($path)
431
440
}
432
441
if (!$ result ) {
433
442
throw new FileSystemException (
434
- new \ Magento \ Framework \ Phrase (
443
+ new Phrase (
435
444
'The directory "%1" cannot be deleted %2 ' ,
436
445
[$ path , $ this ->getWarningMessage ()]
437
446
)
@@ -453,7 +462,7 @@ public function changePermissions($path, $permissions)
453
462
$ result = @chmod ($ this ->getScheme () . $ path , $ permissions );
454
463
if (!$ result ) {
455
464
throw new FileSystemException (
456
- new \ Magento \ Framework \ Phrase (
465
+ new Phrase (
457
466
'The permissions can \'t be changed for the "%1" path. %2. ' ,
458
467
[$ path , $ this ->getWarningMessage ()]
459
468
)
@@ -481,7 +490,7 @@ public function changePermissionsRecursively($path, $dirPermissions, $filePermis
481
490
}
482
491
if (!$ result ) {
483
492
throw new FileSystemException (
484
- new \ Magento \ Framework \ Phrase (
493
+ new Phrase (
485
494
'The permissions can \'t be changed for the "%1" path. %2. ' ,
486
495
[$ path , $ this ->getWarningMessage ()]
487
496
)
@@ -503,7 +512,7 @@ public function changePermissionsRecursively($path, $dirPermissions, $filePermis
503
512
}
504
513
if (!$ result ) {
505
514
throw new FileSystemException (
506
- new \ Magento \ Framework \ Phrase (
515
+ new Phrase (
507
516
'The permissions can \'t be changed for the "%1" path. %2. ' ,
508
517
[$ path , $ this ->getWarningMessage ()]
509
518
)
@@ -530,7 +539,7 @@ public function touch($path, $modificationTime = null)
530
539
}
531
540
if (!$ result ) {
532
541
throw new FileSystemException (
533
- new \ Magento \ Framework \ Phrase (
542
+ new Phrase (
534
543
'The "%1" file or directory can \'t be touched. %2 ' ,
535
544
[$ path , $ this ->getWarningMessage ()]
536
545
)
@@ -553,7 +562,7 @@ public function filePutContents($path, $content, $mode = null)
553
562
$ result = @file_put_contents ($ this ->getScheme () . $ path , $ content , $ mode );
554
563
if ($ result === false ) {
555
564
throw new FileSystemException (
556
- new \ Magento \ Framework \ Phrase (
565
+ new Phrase (
557
566
'The specified "%1" file couldn \'t be written. %2 ' ,
558
567
[$ path , $ this ->getWarningMessage ()]
559
568
)
@@ -575,7 +584,7 @@ public function fileOpen($path, $mode)
575
584
$ result = @fopen ($ this ->getScheme () . $ path , $ mode );
576
585
if (!$ result ) {
577
586
throw new FileSystemException (
578
- new \ Magento \ Framework \ Phrase ('File "%1" cannot be opened %2 ' , [$ path , $ this ->getWarningMessage ()])
587
+ new Phrase ('File "%1" cannot be opened %2 ' , [$ path , $ this ->getWarningMessage ()])
579
588
);
580
589
}
581
590
return $ result ;
@@ -597,7 +606,7 @@ public function fileReadLine($resource, $length, $ending = null)
597
606
// phpcs:enable
598
607
if (false === $ result ) {
599
608
throw new FileSystemException (
600
- new \ Magento \ Framework \ Phrase ('File cannot be read %1 ' , [$ this ->getWarningMessage ()])
609
+ new Phrase ('File cannot be read %1 ' , [$ this ->getWarningMessage ()])
601
610
);
602
611
}
603
612
@@ -617,7 +626,7 @@ public function fileRead($resource, $length)
617
626
$ result = @fread ($ resource , $ length );
618
627
if ($ result === false ) {
619
628
throw new FileSystemException (
620
- new \ Magento \ Framework \ Phrase ('File cannot be read %1 ' , [$ this ->getWarningMessage ()])
629
+ new Phrase ('File cannot be read %1 ' , [$ this ->getWarningMessage ()])
621
630
);
622
631
}
623
632
return $ result ;
@@ -639,7 +648,7 @@ public function fileGetCsv($resource, $length = 0, $delimiter = ',', $enclosure
639
648
$ result = @fgetcsv ($ resource , $ length , $ delimiter , $ enclosure , $ escape );
640
649
if ($ result === null ) {
641
650
throw new FileSystemException (
642
- new \ Magento \ Framework \ Phrase (
651
+ new Phrase (
643
652
'The "%1" CSV handle is incorrect. Verify the handle and try again. ' ,
644
653
[$ this ->getWarningMessage ()]
645
654
)
@@ -660,7 +669,7 @@ public function fileTell($resource)
660
669
$ result = @ftell ($ resource );
661
670
if ($ result === null ) {
662
671
throw new FileSystemException (
663
- new \ Magento \ Framework \ Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
672
+ new Phrase ('An error occurred during "%1" execution. ' , [$ this ->getWarningMessage ()])
664
673
);
665
674
}
666
675
return $ result ;
@@ -680,7 +689,7 @@ public function fileSeek($resource, $offset, $whence = SEEK_SET)
680
689
$ result = @fseek ($ resource , $ offset , $ whence );
681
690
if ($ result === -1 ) {
682
691
throw new FileSystemException (
683
- new \ Magento \ Framework \ Phrase (
692
+ new Phrase (
684
693
'An error occurred during "%1" fileSeek execution. ' ,
685
694
[$ this ->getWarningMessage ()]
686
695
)
@@ -712,7 +721,7 @@ public function fileClose($resource)
712
721
$ result = @fclose ($ resource );
713
722
if (!$ result ) {
714
723
throw new FileSystemException (
715
- new \ Magento \ Framework \ Phrase (
724
+ new Phrase (
716
725
'An error occurred during "%1" fileClose execution. ' ,
717
726
[$ this ->getWarningMessage ()]
718
727
)
@@ -758,7 +767,7 @@ public function fileWrite($resource, $data)
758
767
*/
759
768
private function fileSystemException ($ message , $ arguments = [])
760
769
{
761
- throw new FileSystemException (new \ Magento \ Framework \ Phrase ($ message , $ arguments ));
770
+ throw new FileSystemException (new Phrase ($ message , $ arguments ));
762
771
}
763
772
764
773
/**
@@ -777,7 +786,7 @@ public function filePutCsv($resource, array $data, $delimiter = ',', $enclosure
777
786
* Security enhancement for CSV data processing by Excel-like applications.
778
787
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=1054702
779
788
*
780
- * @var $value string|\Magento\Framework\ Phrase
789
+ * @var $value string|Phrase
781
790
*/
782
791
foreach ($ data as $ key => $ value ) {
783
792
if (!is_string ($ value )) {
@@ -791,7 +800,7 @@ public function filePutCsv($resource, array $data, $delimiter = ',', $enclosure
791
800
$ result = @fputcsv ($ resource , $ data , $ delimiter , $ enclosure );
792
801
if (!$ result ) {
793
802
throw new FileSystemException (
794
- new \ Magento \ Framework \ Phrase (
803
+ new Phrase (
795
804
'An error occurred during "%1" filePutCsv execution. ' ,
796
805
[$ this ->getWarningMessage ()]
797
806
)
@@ -812,7 +821,7 @@ public function fileFlush($resource)
812
821
$ result = @fflush ($ resource );
813
822
if (!$ result ) {
814
823
throw new FileSystemException (
815
- new \ Magento \ Framework \ Phrase (
824
+ new Phrase (
816
825
'An error occurred during "%1" fileFlush execution. ' ,
817
826
[$ this ->getWarningMessage ()]
818
827
)
@@ -834,7 +843,7 @@ public function fileLock($resource, $lockMode = LOCK_EX)
834
843
$ result = @flock ($ resource , $ lockMode );
835
844
if (!$ result ) {
836
845
throw new FileSystemException (
837
- new \ Magento \ Framework \ Phrase (
846
+ new Phrase (
838
847
'An error occurred during "%1" fileLock execution. ' ,
839
848
[$ this ->getWarningMessage ()]
840
849
)
@@ -855,7 +864,7 @@ public function fileUnlock($resource)
855
864
$ result = @flock ($ resource , LOCK_UN );
856
865
if (!$ result ) {
857
866
throw new FileSystemException (
858
- new \ Magento \ Framework \ Phrase (
867
+ new Phrase (
859
868
'An error occurred during "%1" fileUnlock execution. ' ,
860
869
[$ this ->getWarningMessage ()]
861
870
)
@@ -947,7 +956,7 @@ public function readDirectoryRecursively($path = null)
947
956
$ result [] = $ file ->getPathname ();
948
957
}
949
958
} catch (\Exception $ e ) {
950
- throw new FileSystemException (new \ Magento \ Framework \ Phrase ($ e ->getMessage ()), $ e );
959
+ throw new FileSystemException (new Phrase ($ e ->getMessage ()), $ e );
951
960
}
952
961
return $ result ;
953
962
}
0 commit comments