Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime options set in composer.json are not loaded #51

Open
starred-gijs opened this issue Jan 5, 2022 · 0 comments
Open

Runtime options set in composer.json are not loaded #51

starred-gijs opened this issue Jan 5, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@starred-gijs
Copy link

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 :)

@mnapoli mnapoli added the bug Something isn't working label Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants