Skip to content

Commit 565ab1b

Browse files
author
Dmitry Kologrivov
committed
Merge branch 'MAGETWO-44227-FIX-CONFIG-DATA' into 'master4'
MAGETWO-44227: fix config data See merge request !173
2 parents 98a41ec + 17f4106 commit 565ab1b

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

lib/internal/Magento/Framework/Config/FileResolver.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Filesystem;
1212
use Magento\Framework\View\DesignInterface;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
14-
use Symfony\Component\Config\Definition\Exception\Exception;
14+
use Magento\Framework\Component\ComponentRegistrar;
1515

1616
class FileResolver implements \Magento\Framework\Config\FileResolverInterface
1717
{
@@ -43,25 +43,30 @@ class FileResolver implements \Magento\Framework\Config\FileResolverInterface
4343
protected $area;
4444

4545
/**
46-
* Root directory
47-
*
48-
* @var ReadInterface
46+
* @var Filesystem\Directory\ReadInterface
4947
*/
5048
protected $rootDirectory;
5149

50+
/**
51+
* @var \Magento\Framework\Component\ComponentRegistrar
52+
*/
53+
protected $componentRegistrar;
54+
5255
/**
5356
* @param Reader $moduleReader
5457
* @param FileIteratorFactory $iteratorFactory
5558
* @param DesignInterface $designInterface
5659
* @param DirectoryList $directoryList
5760
* @param Filesystem $filesystem
61+
* @param ComponentRegistrar $componentRegistrar
5862
*/
5963
public function __construct(
6064
Reader $moduleReader,
6165
FileIteratorFactory $iteratorFactory,
6266
DesignInterface $designInterface,
6367
DirectoryList $directoryList,
64-
Filesystem $filesystem
68+
Filesystem $filesystem,
69+
ComponentRegistrar $componentRegistrar
6570
) {
6671
$this->directoryList = $directoryList;
6772
$this->iteratorFactory = $iteratorFactory;
@@ -70,6 +75,7 @@ public function __construct(
7075
$this->themePath = $designInterface->getThemePath($this->currentTheme);
7176
$this->area = $designInterface->getArea();
7277
$this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
78+
$this->componentRegistrar = $componentRegistrar;
7379
}
7480

7581
/**
@@ -80,7 +86,6 @@ public function get($filename, $scope)
8086
switch ($scope) {
8187
case 'global':
8288
$iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray();
83-
8489
$themeConfigFile = $this->currentTheme->getCustomization()->getCustomViewConfigPath();
8590
if ($themeConfigFile
8691
&& $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
@@ -89,20 +94,18 @@ public function get($filename, $scope)
8994
$this->rootDirectory->getRelativePath($themeConfigFile)
9095
);
9196
}
92-
9397
$designPath =
94-
$this->directoryList->getPath(DirectoryList::APP)
95-
. '/design/'
96-
. $this->area
97-
. '/'
98-
. $this->themePath
98+
$this->componentRegistrar->getPath(ComponentRegistrar::THEME, $this->area . '/' . $this->themePath)
9999
. '/etc/view.xml';
100100
if (file_exists($designPath)) {
101101
try {
102102
$designDom = new \DOMDocument;
103103
$designDom->load($designPath);
104104
$iterator[$designPath] = $designDom->saveXML();
105-
} catch (Exception $e) {
105+
} catch (\Exception $e) {
106+
throw new \Magento\Framework\Exception\LocalizedException(
107+
__('Could not read config file')
108+
);
106109
}
107110
}
108111
break;

lib/internal/Magento/Framework/Config/View.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class View extends \Magento\Framework\Config\Reader\Filesystem
1818
*/
1919
protected $xpath;
2020

21+
/**
22+
* View config data
23+
*
24+
* @var array
25+
*/
26+
protected $data;
27+
2128
/**
2229
* @param FileResolverInterface $fileResolver
2330
* @param ConverterInterface $converter
@@ -52,7 +59,6 @@ public function __construct(
5259
$domDocumentClass,
5360
$defaultScope
5461
);
55-
$this->data = $this->read();
5662
}
5763

5864
/**
@@ -65,6 +71,7 @@ public function __construct(
6571
*/
6672
public function getVars($module)
6773
{
74+
$this->setData();
6875
return isset($this->data['vars'][$module]) ? $this->data['vars'][$module] : [];
6976
}
7077

@@ -77,6 +84,7 @@ public function getVars($module)
7784
*/
7885
public function getVarValue($module, $var)
7986
{
87+
$this->setData();
8088
if (!isset($this->data['vars'][$module])) {
8189
return false;
8290
}
@@ -102,6 +110,7 @@ public function getVarValue($module, $var)
102110
*/
103111
public function getMediaEntities($module, $mediaType)
104112
{
113+
$this->setData();
105114
return isset($this->data['media'][$module][$mediaType]) ? $this->data['media'][$module][$mediaType] : [];
106115
}
107116

@@ -115,6 +124,7 @@ public function getMediaEntities($module, $mediaType)
115124
*/
116125
public function getMediaAttributes($module, $mediaType, $mediaId)
117126
{
127+
$this->setData();
118128
return isset($this->data['media'][$module][$mediaType][$mediaId])
119129
? $this->data['media'][$module][$mediaType][$mediaId]
120130
: [];
@@ -185,6 +195,14 @@ public function getExcludedDir()
185195
*/
186196
protected function getItems()
187197
{
198+
$this->setData();
188199
return isset($this->data['exclude']) ? $this->data['exclude'] : [];
189200
}
201+
202+
protected function setData()
203+
{
204+
if ($this->data === null) {
205+
$this->data = $this->read();
206+
}
207+
}
190208
}

0 commit comments

Comments
 (0)