symfony-bridge
symfony-bridge copied to clipboard
Runtime options set in composer.json are not loaded
Im testing the new BrefRuntime package and I noticed something. Im still figuring out how exactly it works, but this is the scenario:
I have a runtime option set in composer.json 'extra.runtime.options'
{
"require": {
"...": "..."
},
"extra": {
"runtime": {
"use_putenv": true
}
}
}
This will generate the autoload_runtime.php with 1 extra line
$runtime = $_SERVER['APP_RUNTIME'] ?? $_ENV['APP_RUNTIME'] ?? 'Symfony\\Component\\Runtime\\SymfonyRuntime';
$runtime = new $runtime(($_SERVER['APP_RUNTIME_OPTIONS'] ?? $_ENV['APP_RUNTIME_OPTIONS'] ?? []) + [
'use_putenv' => true, // <<<=== THIS LINE IS ADDED
'project_dir' => dirname(__DIR__, 1),
]);
But I think the part of the file is not loaded because $_SERVER['SCRIPT_FILENAME']
is empty (please confirm this)
if (true === (require_once __DIR__.'/autoload.php') || empty($_SERVER['SCRIPT_FILENAME'])) {
return;
}
And in HandlerResolver
the BrefRuntime is created without the use_putenv
option:
// Use the Symfony Runtime component to resolve the closure and get the PSR-11 container
$options = $_SERVER['APP_RUNTIME_OPTIONS'] ?? [];
if ($projectDir) {
$options['project_dir'] = $projectDir;
}
$runtime = new BrefRuntime($options);
The workaround is to use the other way of setting options, in public/index.php
:
<?php
use App\Kernel;
$_SERVER['APP_RUNTIME_OPTIONS'] = [
'use_putenv' => true,
];
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
Not sure if this is a feature this bridge would like to support, but if not, a warning message in the docs would be nice :)