Skip to content

Commit

Permalink
Merge pull request #2211 from acelaya-forks/feature/explicit-env-from…
Browse files Browse the repository at this point in the history
…-config

Promote installer config options as env vars explicitly
  • Loading branch information
acelaya authored Oct 8, 2024
2 parents 00169a5 + 15b53ef commit a8e4b2f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]
### Added
* *Nothing*

### Changed
* [#2208](https://github.com/shlinkio/shlink/issues/2208) Explicitly promote installer config options as env vars, instead of as a side effect of loading the app config.

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* *Nothing*


## [4.2.1] - 2024-10-04
### Added
* [#2183](https://github.com/shlinkio/shlink/issues/2183) Redis database index to be used can now be specified in the connection URI path, and Shlink will honor it.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ramsey/uuid": "^4.7",
"shlinkio/doctrine-specification": "^2.1.1",
"shlinkio/shlink-common": "^6.3",
"shlinkio/shlink-config": "^3.0",
"shlinkio/shlink-config": "dev-main#76a96ee as 3.1",
"shlinkio/shlink-event-dispatcher": "^4.1",
"shlinkio/shlink-importer": "^5.3.2",
"shlinkio/shlink-installer": "^9.2",
Expand Down
5 changes: 0 additions & 5 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@
use Laminas\Diactoros;
use Mezzio;
use Mezzio\ProblemDetails;
use Shlinkio\Shlink\Config\ConfigAggregator\EnvVarLoaderProvider;

use function Shlinkio\Shlink\Config\env;
use function Shlinkio\Shlink\Core\enumValues;

$isTestEnv = env('APP_ENV') === 'test';

return (new ConfigAggregator\ConfigAggregator(
providers: [
! $isTestEnv
? new EnvVarLoaderProvider('config/params/generated_config.php', enumValues(Core\Config\EnvVars::class))
: new ConfigAggregator\ArrayProvider([]),
Mezzio\ConfigProvider::class,
Mezzio\Router\ConfigProvider::class,
Mezzio\Router\FastRouteRouter\ConfigProvider::class,
Expand Down
13 changes: 8 additions & 5 deletions config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
use Shlinkio\Shlink\Core\Config\EnvVars;
use Symfony\Component\Lock;

use function Shlinkio\Shlink\Config\loadEnvVarsFromConfig;
use function Shlinkio\Shlink\Core\enumValues;

use const Shlinkio\Shlink\LOCAL_LOCK_FACTORY;

chdir(dirname(__DIR__));

require 'vendor/autoload.php';

// This is one of the first files loaded. Configure the timezone here
// Promote env vars from installer config
loadEnvVarsFromConfig('config/params/generated_config.php', enumValues(EnvVars::class));

// This is one of the first files loaded. Configure the timezone and memory limit here
ini_set('memory_limit', EnvVars::MEMORY_LIMIT->loadFromEnv('512M'));
date_default_timezone_set(EnvVars::TIMEZONE->loadFromEnv(date_default_timezone_get()));

// This class alias tricks the ConfigAbstractFactory to return Lock\Factory instances even with a different service name
Expand All @@ -23,10 +30,6 @@ class_alias(Lock\LockFactory::class, LOCAL_LOCK_FACTORY);

return (static function (): ServiceManager {
$config = require __DIR__ . '/config.php';

// Set memory limit right after loading config, to ensure installer config has been promoted as env vars
ini_set('memory_limit', EnvVars::MEMORY_LIMIT->loadFromEnv('512M'));

$container = new ServiceManager($config['dependencies']);
$container->setService('config', $config);

Expand Down

0 comments on commit a8e4b2f

Please sign in to comment.