12
12
use Magento \Csp \Model \SubresourceIntegrityFactory ;
13
13
use Magento \Deploy \Service \Bundle ;
14
14
use Magento \Framework \App \Filesystem \DirectoryList ;
15
- use Magento \Framework \App \Utility \Files ;
16
15
use Magento \Framework \Exception \FileSystemException ;
17
16
use Magento \Framework \Filesystem ;
18
17
@@ -38,30 +37,22 @@ class GenerateBundleAssetIntegrity
38
37
*/
39
38
private Filesystem $ filesystem ;
40
39
41
- /**
42
- * @var Files
43
- */
44
- private Files $ utilityFiles ;
45
-
46
40
/**
47
41
* @param HashGenerator $hashGenerator
48
42
* @param SubresourceIntegrityFactory $integrityFactory
49
43
* @param SubresourceIntegrityCollector $integrityCollector
50
44
* @param Filesystem $filesystem
51
- * @param Files $utilityFiles
52
45
*/
53
46
public function __construct (
54
47
HashGenerator $ hashGenerator ,
55
48
SubresourceIntegrityFactory $ integrityFactory ,
56
49
SubresourceIntegrityCollector $ integrityCollector ,
57
- Filesystem $ filesystem ,
58
- Files $ utilityFiles
50
+ Filesystem $ filesystem
59
51
) {
60
52
$ this ->hashGenerator = $ hashGenerator ;
61
53
$ this ->integrityFactory = $ integrityFactory ;
62
54
$ this ->integrityCollector = $ integrityCollector ;
63
55
$ this ->filesystem = $ filesystem ;
64
- $ this ->utilityFiles = $ utilityFiles ;
65
56
}
66
57
67
58
/**
@@ -79,20 +70,19 @@ public function __construct(
79
70
public function afterDeploy (Bundle $ subject , ?string $ result , string $ area , string $ theme , string $ locale )
80
71
{
81
72
if (PHP_SAPI == 'cli ' ) {
82
- $ pubStaticDir = $ this ->filesystem ->getDirectoryWrite (DirectoryList::STATIC_VIEW );
83
- $ bundleDir = $ pubStaticDir ->getAbsolutePath ($ area . '/ ' . $ theme . '/ ' . $ locale ) .
84
- "/ " . Bundle::BUNDLE_JS_DIR ;
85
- $ files = $ this ->utilityFiles ->getFiles ([$ bundleDir ], '*.js ' );
86
-
73
+ $ pubStaticDir = $ this ->filesystem ->getDirectoryRead (DirectoryList::STATIC_VIEW );
74
+ $ files = $ pubStaticDir ->search (
75
+ $ area ."/ " . $ theme . "/ " . $ locale . "/ " . Bundle::BUNDLE_JS_DIR . "/*.js "
76
+ );
87
77
foreach ($ files as $ file ) {
88
78
$ integrity = $ this ->integrityFactory ->create (
89
79
[
90
80
"data " => [
91
81
'hash ' => $ this ->hashGenerator ->generate (
92
- file_get_contents ($ file )
82
+ $ pubStaticDir -> readFile ($ file )
93
83
),
94
84
'path ' => $ area . '/ ' . $ theme . '/ ' . $ locale .
95
- "/ " . Bundle::BUNDLE_JS_DIR . '/ ' . basename ($ file )
85
+ "/ " . Bundle::BUNDLE_JS_DIR . '/ ' . pathinfo ($ file )[ ' basename ' ]
96
86
]
97
87
]
98
88
);
0 commit comments