Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplicate loading of configuration files #19585

Merged
merged 4 commits into from Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,6 +17,12 @@ class Layout extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
*/
protected $pageLayoutBuilder;

/**
* @inheritdoc
* @deprecated since the cache is now handled by \Magento\Theme\Model\PageLayout\Config\Builder::$configFiles
*/
protected $_options = null;

/**
* @param \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface $pageLayoutBuilder
*/
Expand All @@ -26,14 +32,14 @@ public function __construct(\Magento\Framework\View\Model\PageLayout\Config\Buil
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getAllOptions()
{
if (!$this->_options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a bit wired to set a value to the property and avoid using it. I think existing method body is more clear and avoids additional options processing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no any additional "option processing".

It looks a bit wired to set a value to the property and avoid using it

This is what current recommendation says. It would be much better to just remove property as probability of BC break is negligible, but if you insist on keeping it deprecated - let's just keep it prepared for removal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys, are you expecting something from me?

Because I made what was the most logical thing from my point of view:

  • deprecate the property
  • keep assigning a value to the deprecated property
  • remove internal usages of the property to prepare its removal

But I'm not sure to understand exactly what you want right now... 馃槃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajardin yeah, everything is fine from my point of view. Remaining part is to convince Sergey, no code changes required until we agree upon them.

$this->_options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
array_unshift($this->_options, ['value' => '', 'label' => __('No layout updates')]);
}
return $this->_options;
$options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
array_unshift($options, ['value' => '', 'label' => __('No layout updates')]);
$this->_options = $options;

return $options;
ajardin marked this conversation as resolved.
Show resolved Hide resolved
}
}
18 changes: 12 additions & 6 deletions app/code/Magento/Catalog/Model/Product/Attribute/Source/Layout.php
Expand Up @@ -17,6 +17,12 @@ class Layout extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
*/
protected $pageLayoutBuilder;

/**
* @inheritdoc
* @deprecated since the cache is now handled by \Magento\Theme\Model\PageLayout\Config\Builder::$configFiles
*/
protected $_options = null;

/**
* @param \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface $pageLayoutBuilder
*/
Expand All @@ -26,14 +32,14 @@ public function __construct(\Magento\Framework\View\Model\PageLayout\Config\Buil
}

/**
* @return array
* @inheritdoc
*/
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
array_unshift($this->_options, ['value' => '', 'label' => __('No layout updates')]);
}
return $this->_options;
$options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
array_unshift($options, ['value' => '', 'label' => __('No layout updates')]);
$this->_options = $options;

return $options;
}
}
11 changes: 3 additions & 8 deletions app/code/Magento/Cms/Model/Page/Source/PageLayout.php
Expand Up @@ -20,6 +20,7 @@ class PageLayout implements OptionSourceInterface

/**
* @var array
* @deprecated since the cache is now handled by \Magento\Theme\Model\PageLayout\Config\Builder::$configFiles
*/
protected $options;

Expand All @@ -34,16 +35,10 @@ public function __construct(BuilderInterface $pageLayoutBuilder)
}

/**
* Get options
*
* @return array
* @inheritdoc
*/
public function toOptionArray()
{
if ($this->options !== null) {
return $this->options;
}

$configOptions = $this->pageLayoutBuilder->getPageLayoutsConfig()->getOptions();
$options = [];
foreach ($configOptions as $key => $value) {
Expand All @@ -54,6 +49,6 @@ public function toOptionArray()
}
$this->options = $options;

return $this->options;
return $options;
}
}
18 changes: 13 additions & 5 deletions app/code/Magento/Theme/Model/PageLayout/Config/Builder.php
Expand Up @@ -27,6 +27,11 @@ class Builder implements \Magento\Framework\View\Model\PageLayout\Config\Builder
*/
protected $themeCollection;

/**
* @var array
*/
private $configFiles = [];

/**
* @param \Magento\Framework\View\PageLayout\ConfigFactory $configFactory
* @param \Magento\Framework\View\PageLayout\File\Collector\Aggregated $fileCollector
Expand All @@ -44,7 +49,7 @@ public function __construct(
}

/**
* @return \Magento\Framework\View\PageLayout\Config
* @inheritdoc
*/
public function getPageLayoutsConfig()
{
Expand All @@ -56,11 +61,14 @@ public function getPageLayoutsConfig()
*/
protected function getConfigFiles()
{
$configFiles = [];
foreach ($this->themeCollection->loadRegisteredThemes() as $theme) {
$configFiles = array_merge($configFiles, $this->fileCollector->getFilesContent($theme, 'layouts.xml'));
if (!$this->configFiles) {
$configFiles = [];
ajardin marked this conversation as resolved.
Show resolved Hide resolved
foreach ($this->themeCollection->loadRegisteredThemes() as $theme) {
$configFiles[] = $this->fileCollector->getFilesContent($theme, 'layouts.xml');
}
$this->configFiles = array_merge(...$configFiles);
}

return $configFiles;
return $this->configFiles;
}
}
Expand Up @@ -83,7 +83,7 @@ public function testGetPageLayoutsConfig()
->disableOriginalConstructor()
->getMock();

$this->themeCollection->expects($this->any())
$this->themeCollection->expects($this->once())
->method('loadRegisteredThemes')
->willReturn([$theme1, $theme2]);

Expand Down