Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Aug 25, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #60755
License MIT

cc @nicolas-grekas since I think you worked a lot on this.

When setting the APP_RUNTIME_OPTIONS with docker or anything else than php, only a string can be used ; so it could be useful to support a string format for such options, I propose the classic json format and then use json_decode on string.

WDYT ?

I'm unsure how this template is tested...

@carsonbot carsonbot added this to the 7.4 milestone Aug 25, 2025
@carsonbot carsonbot changed the title Support runtime options as a string Support runtime options as a string Aug 25, 2025
@carsonbot carsonbot changed the title Support runtime options as a string [Runtime] Support runtime options as a string Aug 25, 2025
@Spomky
Copy link
Contributor

Spomky commented Aug 26, 2025

Looks good to me.
An env var is always a string anyway, so supporting JSON here makes sense.

You could add JSON_THROW_ON_ERROR and fail clearly on invalid JSON,

@nicolas-grekas
Copy link
Member

Very close to #45535.

Did you consider populating $_SERVER['APP_RUNTIME_OPTIONS'] in your index.php file instead? Just wondering about alternatives:

--- a/public/index.php
+++ b/public/index.php
@@ -4,6 +4,10 @@ use App\Kernel;
 
 require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
 
+if (is_string($_SERVER['APP_RUNTIME_OPTIONS'] ??= $_ENV['APP_RUNTIME_OPTIONS'] ?? [])) {
+    $_SERVER['APP_RUNTIME_OPTIONS'] = json_decode($_SERVER['APP_RUNTIME_OPTIONS'], true, JSON_THROW_ON_ERROR);
+}
+
 return function (array $context) {
     return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
 };

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @ro0NL FYI

@VincentLanglet
Copy link
Contributor Author

Did you consider populating $_SERVER['APP_RUNTIME_OPTIONS'] in your index.php file instead? Just wondering about alternatives:

--- a/public/index.php
+++ b/public/index.php
@@ -4,6 +4,10 @@ use App\Kernel;
 
 require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
 
+if (is_string($_SERVER['APP_RUNTIME_OPTIONS'] ??= $_ENV['APP_RUNTIME_OPTIONS'] ?? [])) {
+    $_SERVER['APP_RUNTIME_OPTIONS'] = json_decode($_SERVER['APP_RUNTIME_OPTIONS'], true, JSON_THROW_ON_ERROR);
+}
+
 return function (array $context) {
     return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
 };

"Funny", I currently only used the bin/console so I added a similar check in my bin/console file but indeed, I will certainly have the same need in the index.php.

I think adding this directly in Symfony runtime will

  • avoid people to add this themself
  • avoid having to add this on different php files (index.php, bin/console, another ?)

I'm only sad about the fact it's obviously considered as a new feature and I'll have to wait 7.4 ^^

@nicolas-grekas
Copy link
Member

(please add a line in the changelog of the component)

@VincentLanglet
Copy link
Contributor Author

(please add a line in the changelog of the component)

Updated

7.4
---

* Add support for using json_encoded `APP_RUNTIME_OPTIONS` value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Add support for using json_encoded `APP_RUNTIME_OPTIONS` value
* Add support for using a JSON encoded value for `APP_RUNTIME_OPTIONS`

@fabpot
Copy link
Member

fabpot commented Aug 27, 2025

Thank you @VincentLanglet.

@fabpot fabpot merged commit c228caa into symfony:7.4 Aug 27, 2025
11 of 12 checks passed
fabpot added a commit that referenced this pull request Sep 3, 2025
…UNTIME']` (nicolas-grekas)

This PR was merged into the 7.4 branch.

Discussion
----------

[Runtime] Expose the runtime class in `$_SERVER['APP_RUNTIME']`

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | -
| License       | MIT

Let's make this var consistently contain the runtime class.
Options were already make so in #61522

Commits
-------

1f1bf89 [Runtime] Expose the runtime class in `$_SERVER['APP_RUNTIME']`
This was referenced Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to set disable_dotenv via environment variable

6 participants