Skip to content

Commit

Permalink
Merge pull request #1478 from hydephp/fix-dot-notation-support-in-yam…
Browse files Browse the repository at this point in the history
…l-configuration

Expand dot notation when merging Yaml configuration hydephp/develop@79907bd
  • Loading branch information
github-actions committed Nov 27, 2023
1 parent c03d972 commit 66f03c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Foundation/Internal/LoadYamlConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Hyde\Hyde;
use Hyde\Facades\Config;
use Illuminate\Support\Arr;
use Symfony\Component\Yaml\Yaml;

use function array_key_first;
Expand Down Expand Up @@ -48,7 +49,7 @@ protected function hasYamlConfigFile(): bool
/** @return array<string, mixed> */
protected function getYaml(): array
{
return (array) Yaml::parse(file_get_contents($this->getFile()));
return Arr::undot((array) Yaml::parse(file_get_contents($this->getFile())));
}

protected function getFile(): string
Expand All @@ -67,7 +68,7 @@ protected function mergeParsedConfiguration(): void
if ($this->configurationContainsNamespaces($yaml)) {
/** @var array<string, array<string, scalar>> $yaml */
foreach ($yaml as $namespace => $data) {
$this->mergeConfiguration($namespace, (array) $data);
$this->mergeConfiguration($namespace, Arr::undot((array) $data));
}

return;
Expand Down
35 changes: 35 additions & 0 deletions tests/Feature/LoadYamlConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,41 @@ public function testHydeNamespaceCanBlank()
$this->assertSame('baz', Config::get('foo.bar'));
}

public function testDotNotationCanBeUsed()
{
config(['hyde' => []]);

$this->file('hyde.yml', <<<'YAML'
foo.bar.baz: qux
YAML);
$this->runBootstrapper();

$this->assertSame(['foo' => ['bar' => ['baz' => 'qux']]], Config::get('hyde'));
$this->assertSame('qux', Config::get('hyde.foo.bar.baz'));
}

public function testDotNotationCanBeUsedWithNamespaces()
{
config(['hyde' => []]);

$this->file('hyde.yml', <<<'YAML'
hyde:
foo.bar.baz: qux
one:
foo:
bar:
baz: qux
two:
foo.bar.baz: qux
YAML);
$this->runBootstrapper();

$expected = ['foo' => ['bar' => ['baz' => 'qux']]];
$this->assertSame($expected, Config::get('hyde'));
$this->assertSame($expected, Config::get('one'));
$this->assertSame($expected, Config::get('two'));
}

protected function runBootstrapper(): void
{
$this->app->bootstrapWith([LoadYamlConfiguration::class]);
Expand Down

0 comments on commit 66f03c8

Please sign in to comment.