Skip to content

Commit b60b5f8

Browse files
committed
#38933: Putting csp_whitelist.xml in theme does not work and creates intermittent issue
- Implemented caching of CSP whitelist per website area.
1 parent 89b4e2e commit b60b5f8

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

app/code/Magento/Csp/Model/Collector/CspWhitelistXml/FileResolver.php

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
namespace Magento\Csp\Model\Collector\CspWhitelistXml;
1010

11+
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\Config\CompositeFileIteratorFactory;
1113
use Magento\Framework\Config\FileResolverInterface;
1214
use Magento\Framework\Filesystem;
13-
use Magento\Framework\View\Design\ThemeInterface;
14-
use Magento\Framework\View\DesignInterface;
15+
use Magento\Framework\Filesystem\Directory\ReadInterface as DirectoryRead;
1516
use Magento\Framework\View\Design\Theme\CustomizationInterface;
1617
use Magento\Framework\View\Design\Theme\CustomizationInterfaceFactory;
17-
use Magento\Framework\App\Filesystem\DirectoryList;
18-
use Magento\Framework\Filesystem\Directory\ReadInterface as DirectoryRead;
19-
use Magento\Framework\Config\CompositeFileIteratorFactory;
18+
use Magento\Framework\View\Design\ThemeInterface;
19+
use Magento\Framework\View\DesignInterface;
2020

2121
/**
2222
* Combines configuration files from both modules and current theme.
@@ -74,22 +74,29 @@ public function __construct(
7474
*/
7575
public function get($filename, $scope)
7676
{
77-
$configs = $this->moduleFileResolver->get($filename, $scope);
78-
if ($scope === 'global') {
79-
$files = [];
80-
$theme = $this->theme;
81-
while ($theme) {
82-
/** @var CustomizationInterface $info */
83-
$info = $this->themeInfoFactory->create(['theme' => $theme]);
84-
$file = $info->getThemeFilesPath() .'/etc/' .$filename;
85-
if ($this->rootDir->isExist($file)) {
86-
$files[] = $file;
77+
$configs = $this->moduleFileResolver->get($filename, $scope);
78+
79+
switch ($scope) {
80+
case 'frontend':
81+
case 'adminhtml':
82+
$files = [];
83+
$theme = $this->theme;
84+
while ($theme) {
85+
/** @var CustomizationInterface $info */
86+
$info = $this->themeInfoFactory->create(['theme' => $theme]);
87+
$file = $info->getThemeFilesPath() . '/etc/' . $filename;
88+
if ($this->rootDir->isExist($file)) {
89+
$files[] = $file;
90+
}
91+
$theme = $theme->getParentTheme();
8792
}
88-
$theme = $theme->getParentTheme();
89-
}
90-
$configs = $this->iteratorFactory->create(
91-
['paths' => array_reverse($files), 'existingIterator' => $configs]
92-
);
93+
$configs = $this->iteratorFactory->create(
94+
['paths' => array_reverse($files), 'existingIterator' => $configs]
95+
);
96+
break;
97+
case 'global':
98+
default:
99+
break;
93100
}
94101

95102
return $configs;

0 commit comments

Comments
 (0)