diff --git a/module/CLI/src/ConfigProvider.php b/module/CLI/src/ConfigProvider.php index ba3a5747..45fd4755 100644 --- a/module/CLI/src/ConfigProvider.php +++ b/module/CLI/src/ConfigProvider.php @@ -3,13 +3,12 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI; -use Zend\Config\Factory; -use Zend\Stdlib\Glob; +use function Shlinkio\Shlink\Common\loadConfigFromGlob; class ConfigProvider { public function __invoke() { - return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE)); + return loadConfigFromGlob(__DIR__ . '/../config/{,*.}config.php'); } } diff --git a/module/Common/functions/functions.php b/module/Common/functions/functions.php index e07603ce..aab0ef26 100644 --- a/module/Common/functions/functions.php +++ b/module/Common/functions/functions.php @@ -3,6 +3,9 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common; +use Zend\Config\Factory; +use Zend\Stdlib\Glob; + use function getenv; use function json_decode as spl_json_decode; use function json_last_error; @@ -59,3 +62,11 @@ function json_decode(string $json, int $depth = 512, int $options = 0): array return $data; } + +/** + * Loads configuration files which match provided glob pattern, and returns the merged result as array + */ +function loadConfigFromGlob(string $globPattern): array +{ + return Factory::fromFiles(Glob::glob($globPattern, Glob::GLOB_BRACE)); +} diff --git a/module/Common/src/ConfigProvider.php b/module/Common/src/ConfigProvider.php index 0d0c8a0d..7d900823 100644 --- a/module/Common/src/ConfigProvider.php +++ b/module/Common/src/ConfigProvider.php @@ -3,13 +3,10 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common; -use Zend\Config\Factory; -use Zend\Stdlib\Glob; - class ConfigProvider { public function __invoke(): array { - return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE)); + return loadConfigFromGlob(__DIR__ . '/../config/{,*.}config.php'); } } diff --git a/module/Core/src/ConfigProvider.php b/module/Core/src/ConfigProvider.php index a58f0c55..b8d01a7a 100644 --- a/module/Core/src/ConfigProvider.php +++ b/module/Core/src/ConfigProvider.php @@ -3,13 +3,12 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core; -use Zend\Config\Factory; -use Zend\Stdlib\Glob; +use function Shlinkio\Shlink\Common\loadConfigFromGlob; class ConfigProvider { public function __invoke() { - return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE)); + return loadConfigFromGlob(__DIR__ . '/../config/{,*.}config.php'); } } diff --git a/module/EventDispatcher/src/ConfigProvider.php b/module/EventDispatcher/src/ConfigProvider.php index 70b6ab2e..88f2045e 100644 --- a/module/EventDispatcher/src/ConfigProvider.php +++ b/module/EventDispatcher/src/ConfigProvider.php @@ -3,13 +3,12 @@ declare(strict_types=1); namespace Shlinkio\Shlink\EventDispatcher; -use Zend\Config\Factory; -use Zend\Stdlib\Glob; +use function Shlinkio\Shlink\Common\loadConfigFromGlob; class ConfigProvider { public function __invoke() { - return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE)); + return loadConfigFromGlob(__DIR__ . '/../config/{,*.}config.php'); } } diff --git a/module/IpGeolocation/src/ConfigProvider.php b/module/IpGeolocation/src/ConfigProvider.php index 2801342b..7b8b6e7e 100644 --- a/module/IpGeolocation/src/ConfigProvider.php +++ b/module/IpGeolocation/src/ConfigProvider.php @@ -5,11 +5,12 @@ namespace Shlinkio\Shlink\IpGeolocation; use Zend\Config\Factory; use Zend\Stdlib\Glob; +use function Shlinkio\Shlink\Common\loadConfigFromGlob; class ConfigProvider { public function __invoke(): array { - return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE)); + return loadConfigFromGlob(__DIR__ . '/../config/{,*.}config.php'); } } diff --git a/module/IpGeolocation/test/ConfigProviderTest.php b/module/IpGeolocation/test/ConfigProviderTest.php new file mode 100644 index 00000000..a6dbdcbd --- /dev/null +++ b/module/IpGeolocation/test/ConfigProviderTest.php @@ -0,0 +1,28 @@ +configProvider = new ConfigProvider(); + } + + /** @test */ + public function configIsReturned(): void + { + $config = $this->configProvider->__invoke(); + + $this->assertArrayHasKey('dependencies', $config); + $this->assertArrayHasKey(ConfigAbstractFactory::class, $config); + } +}