Skip to content

Commit fab6a16

Browse files
committed
MC-36785: Unable to set YouTube API key by CLI
1 parent 030d86f commit fab6a16

File tree

4 files changed

+88
-66
lines changed

4 files changed

+88
-66
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\App\Config\Source;
9+
10+
use Magento\Config\Model\Config\Structure\Reader;
11+
use Magento\Framework\App\Area;
12+
use Magento\Framework\App\Config\ConfigSourceInterface;
13+
use Magento\Framework\DataObject;
14+
15+
/**
16+
* Class for retrieving configuration structure
17+
*/
18+
class ConfigStructureSource implements ConfigSourceInterface
19+
{
20+
/**
21+
* @var Reader
22+
*/
23+
private $reader;
24+
25+
/**
26+
* @param Reader $reader
27+
*/
28+
public function __construct(Reader $reader)
29+
{
30+
$this->reader = $reader;
31+
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function get($path = '')
37+
{
38+
$configStructure = $this->reader->read(Area::AREA_ADMINHTML);
39+
$sections = $configStructure['config']['system']['sections'] ?? [];
40+
$defaultConfig = $this->merge([], $sections);
41+
$data = new DataObject(['default' => $defaultConfig]);
42+
43+
return $data->getData($path);
44+
}
45+
46+
/**
47+
* Merge existed config with config structure
48+
*
49+
* @param array $config
50+
* @param array $sections
51+
* @return array
52+
*/
53+
private function merge(array $config, array $sections): array
54+
{
55+
foreach ($sections as $section) {
56+
if (isset($section['children'])) {
57+
$config[$section['id']] = $this->merge(
58+
$config[$section['id']] ?? [],
59+
$section['children']
60+
);
61+
} elseif ($section['_elementType'] === 'field') {
62+
$config += [$section['id'] => null];
63+
}
64+
}
65+
66+
return $config;
67+
}
68+
}

app/code/Magento/Config/App/Config/Source/ModularConfigSource.php

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
*/
66
namespace Magento\Config\App\Config\Source;
77

8-
use Magento\Config\Model\Config\Structure\Reader as ConfigStructureReader;
9-
use Magento\Framework\App\Area;
108
use Magento\Framework\App\Config\ConfigSourceInterface;
11-
use Magento\Framework\App\ObjectManager;
129
use Magento\Framework\DataObject;
13-
use Magento\Framework\App\Config\Initial\Reader as InitialConfigReader;
10+
use Magento\Framework\App\Config\Initial\Reader;
1411

1512
/**
1613
* Class for retrieving initial configuration from modules
@@ -21,26 +18,16 @@
2118
class ModularConfigSource implements ConfigSourceInterface
2219
{
2320
/**
24-
* @var InitialConfigReader
21+
* @var Reader
2522
*/
26-
private $initialConfigReader;
23+
private $reader;
2724

2825
/**
29-
* @var ConfigStructureReader
26+
* @param Reader $reader
3027
*/
31-
private $configStructureReader;
32-
33-
/**
34-
* @param InitialConfigReader $initialConfigReader
35-
* @param ConfigStructureReader|null $configStructureReader
36-
*/
37-
public function __construct(
38-
InitialConfigReader $initialConfigReader,
39-
?ConfigStructureReader $configStructureReader = null
40-
) {
41-
$this->initialConfigReader = $initialConfigReader;
42-
$this->configStructureReader = $configStructureReader
43-
?? ObjectManager::getInstance()->get(ConfigStructureReader::class);
28+
public function __construct(Reader $reader)
29+
{
30+
$this->reader = $reader;
4431
}
4532

4633
/**
@@ -52,39 +39,10 @@ public function __construct(
5239
*/
5340
public function get($path = '')
5441
{
55-
$initialConfig = $this->initialConfigReader->read();
56-
$configStructure = $this->configStructureReader->read(Area::AREA_ADMINHTML);
57-
$sections = $configStructure['config']['system']['sections'] ?? [];
58-
$defaultConfig = $initialConfig['data']['default'] ?? [];
59-
$initialConfig['data']['default'] = $this->merge($defaultConfig, $sections);
60-
61-
$data = new DataObject($initialConfig);
42+
$data = new DataObject($this->reader->read());
6243
if ($path !== '') {
6344
$path = '/' . $path;
6445
}
6546
return $data->getData('data' . $path) ?: [];
6647
}
67-
68-
/**
69-
* Merge initial config with config structure
70-
*
71-
* @param array $config
72-
* @param array $sections
73-
* @return array
74-
*/
75-
private function merge(array $config, array $sections): array
76-
{
77-
foreach ($sections as $section) {
78-
if (isset($section['children'])) {
79-
$config[$section['id']] = $this->merge(
80-
$config[$section['id']] ?? [],
81-
$section['children']
82-
);
83-
} elseif ($section['_elementType'] === 'field') {
84-
$config += [$section['id'] => null];
85-
}
86-
}
87-
88-
return $config;
89-
}
9048
}

app/code/Magento/Config/Test/Unit/App/Config/Source/ModularConfigSourceTest.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
namespace Magento\Config\Test\Unit\App\Config\Source;
99

1010
use Magento\Config\App\Config\Source\ModularConfigSource;
11-
use Magento\Config\Model\Config\Structure\Reader as ConfigStructureReader;
12-
use Magento\Framework\App\Config\Initial\Reader as InitialConfigReader;
11+
use Magento\Framework\App\Config\Initial\Reader;
1312
use PHPUnit\Framework\MockObject\MockObject;
1413
use PHPUnit\Framework\TestCase;
1514

@@ -19,14 +18,9 @@
1918
class ModularConfigSourceTest extends TestCase
2019
{
2120
/**
22-
* @var InitialConfigReader|MockObject
21+
* @var Reader|MockObject
2322
*/
24-
private $initialConfigReader;
25-
26-
/**
27-
* @var ConfigStructureReader|MockObject
28-
*/
29-
private $configStructureReader;
23+
private $reader;
3024

3125
/**
3226
* @var ModularConfigSource
@@ -35,17 +29,15 @@ class ModularConfigSourceTest extends TestCase
3529

3630
protected function setUp(): void
3731
{
38-
$this->initialConfigReader = $this->createMock(InitialConfigReader::class);
39-
$this->configStructureReader = $this->createMock(ConfigStructureReader::class);
40-
$this->source = new ModularConfigSource(
41-
$this->initialConfigReader,
42-
$this->configStructureReader
43-
);
32+
$this->reader = $this->getMockBuilder(Reader::class)
33+
->disableOriginalConstructor()
34+
->getMock();
35+
$this->source = new ModularConfigSource($this->reader);
4436
}
4537

4638
public function testGet()
4739
{
48-
$this->initialConfigReader->expects($this->once())
40+
$this->reader->expects($this->once())
4941
->method('read')
5042
->willReturn(['data' => ['path' => 'value']]);
5143
$this->assertEquals('value', $this->source->get('path'));

app/code/Magento/Config/etc/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@
207207
<virtualType name="appDumpSystemSource" type="Magento\Config\App\Config\Source\DumpConfigSourceAggregated">
208208
<arguments>
209209
<argument name="sources" xsi:type="array">
210+
<item name="structure" xsi:type="array">
211+
<item name="source" xsi:type="object">Magento\Config\App\Config\Source\ConfigStructureSource</item>
212+
<item name="sortOrder" xsi:type="string">1</item>
213+
</item>
210214
<item name="modular" xsi:type="array">
211215
<item name="source" xsi:type="object">Magento\Config\App\Config\Source\ModularConfigSource</item>
212216
<item name="sortOrder" xsi:type="string">10</item>

0 commit comments

Comments
 (0)