1212use Magento \Csp \Model \SubresourceIntegrityFactory ;
1313use Magento \Deploy \Service \Bundle ;
1414use Magento \Framework \App \Filesystem \DirectoryList ;
15- use Magento \Framework \App \Utility \Files ;
1615use Magento \Framework \Exception \FileSystemException ;
1716use Magento \Framework \Filesystem ;
1817
@@ -38,30 +37,22 @@ class GenerateBundleAssetIntegrity
3837 */
3938 private Filesystem $ filesystem ;
4039
41- /**
42- * @var Files
43- */
44- private Files $ utilityFiles ;
45-
4640 /**
4741 * @param HashGenerator $hashGenerator
4842 * @param SubresourceIntegrityFactory $integrityFactory
4943 * @param SubresourceIntegrityCollector $integrityCollector
5044 * @param Filesystem $filesystem
51- * @param Files $utilityFiles
5245 */
5346 public function __construct (
5447 HashGenerator $ hashGenerator ,
5548 SubresourceIntegrityFactory $ integrityFactory ,
5649 SubresourceIntegrityCollector $ integrityCollector ,
57- Filesystem $ filesystem ,
58- Files $ utilityFiles
50+ Filesystem $ filesystem
5951 ) {
6052 $ this ->hashGenerator = $ hashGenerator ;
6153 $ this ->integrityFactory = $ integrityFactory ;
6254 $ this ->integrityCollector = $ integrityCollector ;
6355 $ this ->filesystem = $ filesystem ;
64- $ this ->utilityFiles = $ utilityFiles ;
6556 }
6657
6758 /**
@@ -79,20 +70,19 @@ public function __construct(
7970 public function afterDeploy (Bundle $ subject , ?string $ result , string $ area , string $ theme , string $ locale )
8071 {
8172 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+ );
8777 foreach ($ files as $ file ) {
8878 $ integrity = $ this ->integrityFactory ->create (
8979 [
9080 "data " => [
9181 'hash ' => $ this ->hashGenerator ->generate (
92- file_get_contents ($ file )
82+ $ pubStaticDir -> readFile ($ file )
9383 ),
9484 'path ' => $ area . '/ ' . $ theme . '/ ' . $ locale .
95- "/ " . Bundle::BUNDLE_JS_DIR . '/ ' . basename ($ file )
85+ "/ " . Bundle::BUNDLE_JS_DIR . '/ ' . pathinfo ($ file )[ ' basename ' ]
9686 ]
9787 ]
9888 );
0 commit comments