Skip to content

Commit

Permalink
Remove dependency on laminas-config
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Nov 19, 2024
1 parent 7ec09d5 commit 574e884
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* *Nothing*

### Removed
* *Nothing*
* Remove dependency on `laminas/laminas-config`.

### Fixed
* *Nothing*
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
],
"require": {
"php": "^8.2",
"laminas/laminas-config": "^3.9",
"laminas/laminas-servicemanager": "^4.2 || ^3.22"
"laminas/laminas-servicemanager": "^4.2 || ^3.22",
"laminas/laminas-stdlib": "^3.20"
},
"suggest": {
"cuyz/valinor": "To be able to use ValinorConfigFactory"
Expand Down
15 changes: 12 additions & 3 deletions functions/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace Shlinkio\Shlink\Config;

use Laminas\Config\Factory;
use Laminas\Stdlib\ArrayUtils;
use Laminas\Stdlib\Glob;

use function file_exists;
use function getenv;
use function implode;
use function in_array;
Expand All @@ -15,17 +16,25 @@
use function is_scalar;
use function putenv;
use function sprintf;
use function str_ends_with;
use function strtolower;
use function trim;

use const PHP_SAPI;

function loadConfigFromGlob(string $globPattern): array
{
$config = [];
$files = Glob::glob($globPattern, Glob::GLOB_BRACE);

/** @var array $config */
$config = Factory::fromFiles($files);
foreach ($files as $file) {
if (! str_ends_with($file, '.php') || ! file_exists($file)) {
continue;
}

$config = ArrayUtils::merge($config, include $file);
}

return $config;
}

Expand Down
13 changes: 12 additions & 1 deletion test/Functions/LoadConfigFromGlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace ShlinkioTest\Shlink\Config\Functions;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;

use function Shlinkio\Shlink\Config\loadConfigFromGlob;
Expand All @@ -22,8 +23,18 @@ public function expectedConfigIsProduced(): void
],
'bar' => [
'number' => 123,
'array' => [1, 2, 3]
'array' => [1, 2, 3],
],
], $result);
}

#[Test]
#[TestWith([__DIR__ . '/../../test-resources/configs/does-not-exist.php'])]
#[TestWith([__DIR__ . '/../../composer.json'])]
#[TestWith(['does-not-exist.php'])]
public function nonPhpFilesAreNonExistingFilesAreSkipped(string $globPattern): void
{
$result = loadConfigFromGlob($globPattern);
self::assertEmpty($result);
}
}

0 comments on commit 574e884

Please sign in to comment.