Skip to content

Commit

Permalink
Promote installer config options as env vars explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Oct 8, 2024
1 parent 00169a5 commit 11a4702
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
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 11a4702

Please sign in to comment.