Skip to content

Commit 22f2546

Browse files
[HttpKernel] Add parameters kernel.runtime_mode and kernel.runtime_mode.*, all set from env var APP_RUNTIME_MODE
1 parent 915f596 commit 22f2546

10 files changed

+14
-3
lines changed

Dumper/PhpDumper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class %s extends {$options['class']}
340340
341341
use Symfony\Component\DependencyInjection\Dumper\Preloader;
342342
343-
if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) {
343+
if (in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
344344
return;
345345
}
346346
@@ -388,6 +388,7 @@ class %s extends {$options['class']}
388388
'container.build_hash' => '$hash',
389389
'container.build_id' => '$id',
390390
'container.build_time' => $time,
391+
'container.runtime_mode' => \\in_array(\\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1',
391392
], __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}');
392393
393394
EOF;
@@ -1591,7 +1592,7 @@ private function addDefaultParametersMethod(): string
15911592
$export = $this->exportParameters([$value], '', 12, $hasEnum);
15921593
$export = explode('0 => ', substr(rtrim($export, " ]\n"), 2, -1), 2);
15931594

1594-
if ($hasEnum || preg_match("/\\\$container->(?:getEnv\('(?:[-.\w\\\\]*+:)*+\w++'\)|targetDir\.'')/", $export[1])) {
1595+
if ($hasEnum || preg_match("/\\\$container->(?:getEnv\('(?:[-.\w\\\\]*+:)*+\w*+'\)|targetDir\.'')/", $export[1])) {
15951596
$dynamicPhp[$key] = sprintf('%s%s => %s,', $export[0], $this->export($key), $export[1]);
15961597
$this->dynamicParameters[$key] = true;
15971598
} else {

EnvVarProcessor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
154154

155155
$returnNull = false;
156156
if ('' === $prefix) {
157+
if ('' === $name) {
158+
return null;
159+
}
157160
$returnNull = true;
158161
$prefix = 'string';
159162
}

ParameterBag/EnvPlaceholderParameterBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function get(string $name): array|bool|string|int|float|\UnitEnum|null
4141
return $placeholder; // return first result
4242
}
4343
}
44-
if (!preg_match('/^(?:[-.\w\\\\]*+:)*+\w++$/', $env)) {
44+
if (!preg_match('/^(?:[-.\w\\\\]*+:)*+\w*+$/', $env)) {
4545
throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name));
4646
}
4747
if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) {

Tests/Fixtures/php/services10_as_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ return new \Container%s\ProjectServiceContainer([
154154
'container.build_hash' => '%s',
155155
'container.build_id' => '%s',
156156
'container.build_time' => %d,
157+
'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1',
157158
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
158159

159160
)

Tests/Fixtures/php/services9_as_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ return new \Container%s\ProjectServiceContainer([
787787
'container.build_hash' => '%s',
788788
'container.build_id' => '%s',
789789
'container.build_time' => %d,
790+
'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1',
790791
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
791792

792793
)

Tests/Fixtures/php/services9_inlined_factories.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ return new \Container%s\ProjectServiceContainer([
604604
'container.build_hash' => '%s',
605605
'container.build_id' => '%s',
606606
'container.build_time' => 1563381341,
607+
'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1',
607608
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
608609

609610
)

Tests/Fixtures/php/services9_inlined_factories_with_tagged_iterrator.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ return new \Container%s\ProjectServiceContainer([
119119
'container.build_hash' => '%s',
120120
'container.build_id' => '%s',
121121
'container.build_time' => %d,
122+
'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1',
122123
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
123124

124125
)

Tests/Fixtures/php/services9_lazy_inlined_factories.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ return new \Container%s\ProjectServiceContainer([
187187
'container.build_hash' => '%s',
188188
'container.build_id' => '%s',
189189
'container.build_time' => 1563381341,
190+
'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1',
190191
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
191192

192193
)

Tests/Fixtures/php/services_deprecated_parameters_as_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ return new \Container%s\ProjectServiceContainer([
195195
'container.build_hash' => '%s',
196196
'container.build_id' => '%s',
197197
'container.build_time' => %d,
198+
'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1',
198199
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
199200

200201
)

Tests/Fixtures/php/services_non_shared_lazy_as_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ return new \Container%s\Symfony_DI_PhpDumper_Service_Non_Shared_Lazy_As_File([
164164
'container.build_hash' => '%s',
165165
'container.build_id' => '%s',
166166
'container.build_time' => %d,
167+
'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1',
167168
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
168169

169170
)

0 commit comments

Comments
 (0)