Description
Description
Problem
Currently the Symfony runtime plugin outputs the following configuration for the runtime (and similar behaviour for the runtime options):
$runtime = $_SERVER['APP_RUNTIME'] ?? $_ENV['APP_RUNTIME'] ?? 'Symfony\\Component\\Runtime\\SymfonyRuntime';
This provides three ways to set the runtime:
- Prioritizing server configuration
- Allowing the runtime to be set by environment variable
- Falling back to the project's
composer.json
configuration
Each of these options are aimed at providing the end-user (the project developer) with the ability to change the runtime. However, it provides no way for a framework besides Symfony to suggest a default while still enabling user change.
Context
I'm attempting to introduce the Symfony Runtime component into Drupal core. To make this an adoptable change it's not feasible to ask all developers that maintain a Drupal project to update their server configuration, environment, or composer.json.
In theory the SymfonyRuntime works fine and the DrupalKernel is executed using the HttpKernelRunner
. However, we would like to use our own runner so that we can adopt the Revolt event loop. The SymfonyRuntime does not provide a way for sometihng that implements HttpKernelInterface to register a more specific runner.
Proposed solution
If no runtime class is specified in the composer.json file, then provide an additional $FALLBACK_RUNTIME
(or $FRAMEWORK_RUNTIME
?) variable that's checked before falling back to SymfonyRuntime. This allows frameworks to easily set that variable before including autoload_runtime.php.
Example
Replacing
$runtimeClass = $extra['class'] ?? SymfonyRuntime::class;
unset($extra['class'], $extra['autoload_template']);
$code = strtr(file_get_contents($autoloadTemplate), [
'%project_dir%' => $projectDir,
'%runtime_class%' => var_export($runtimeClass, true),
'%runtime_options%' => '['.substr(var_export($extra, true), 7, -1)." 'project_dir' => {$projectDir},\n]",
]);
with
if (null !== $runtimeClass = $extra['class'] ?? null) {
$runtimeClass = var_export($runtimeClass, true);
}
else {
$runtimeClass = '$FALLBACK_RUNTIME ?? ' . var_export(SymfonyRuntime::class, true);
}
unset($extra['class'], $extra['autoload_template']);
$code = strtr(file_get_contents($autoloadTemplate), [
'%project_dir%' => $projectDir,
'%runtime_class%' => $runtimeClass,
'%runtime_options%' => '['.substr(var_export($extra, true), 7, -1)." 'project_dir' => {$projectDir},\n]",
]);
Would allow a framework to set its own fallback using
$FALLBACK_RUNTIME = DrupalRuntime::class;
require_once 'autoload_runtime.php';
Any Symfony application would keep working as expected and ignore the unset $FALLBACK_RUNTIME
.