8000 [HttpKernel] Add parameter `kernel.runtime_mode`, defined as `%env(de… · symfony/symfony@1387951 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1387951

Browse files
[HttpKernel] Add parameter kernel.runtime_mode, defined as %env(default:container.runtime_mode:APP_RUNTIME_MODE)%
1 parent f13a4b1 commit 1387951

16 files changed

+29
-15
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
11711171
$container->setDefinition('debug.log_processor', $definition);
11721172

11731173
$container->register('debug.debug_logger_configurator', DebugLoggerConfigurator::class)
1174-
->setArguments([new Reference('debug.log_processor')]);
1174+
->setArguments([new Reference('debug.log_processor'), new Reference('kernel.is_web_runtime_mode')]);
11751175
}
11761176
}
11771177

src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
->tag('monolog.logger', ['channel' => 'php'])
3333

3434
->set('debug.debug_handlers_listener', DebugHandlersListener::class)
35+
->args([null, service('kernel.is_web_runtime_mode')])
3536
->tag('kernel.event_subscriber')
3637

3738
->set('debug.file_link_formatter', FileLinkFormatter::class)

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php

+4
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,9 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
241241
->set(Request::class)->abstract()->tag('container.excluded')
242242
->set(Response::class)->abstract()->tag('container.excluded')
243243
->set(SessionInterface::class)->abstract()->tag('container.excluded')
244+
245+
->set('kernel.is_web_runtime_mode', 'bool')
246+
->factory('str_starts_with')
247+
->args(['%kernel.runtime_mode%', 'web'])
244248
;
245249
};

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

+1
Original file line numberDiff line numberDiff line change
@@ -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' => \PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg' ? 'cli' : 'web',
391392
], __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}');
392393
393394
EOF;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10_as_files.txt

+1
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' => \PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg' ? 'cli' : 'web',
157158
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
158159

159160
)

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt

+1
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' => \PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg' ? 'cli' : 'web',
790791
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
791792

792793
)

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt

+1
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' => \PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg' ? 'cli' : 'web',
607608
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
608609

609610
)

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories_with_tagged_iterrator.txt

+1
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' => \PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg' ? 'cli' : 'web',
122123
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
123124

124125
)

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt

+1
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' => \PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg' ? 'cli' : 'web',
190191
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
191192

192193
)

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters_as_files.txt

+1
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' => \PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg' ? 'cli' : 'web',
198199
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
199200

200201
)

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_non_shared_lazy_as_files.txt

+1
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' => \PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg' ? 'cli' : 'web',
167168
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
168169

169170
)

src/Symfony/Component/HttpKernel/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Add argument `$validationFailedStatusCode` to `#[MapQueryString]` and `#[MapRequestPayload]`
1212
* Add argument `$debug` to `Logger`
1313
* Add class `DebugLoggerConfigurator`
14+
* Add parameter `kernel.runtime_mode`, defined as `%env(default:container.runtime_mode:APP_RUNTIME_MODE)%`
1415
* Deprecate `Kernel::stripComments()`
1516
* Support the `!` character at the beginning of a string as a negation operator in the url filter of the profiler
1617
* Deprecate `UriSigner`, use `UriSigner` from the HttpFoundation component instead

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
4242
private ?RequestStack $requestStack;
4343
private DataDumperInterface|Connection|null $dumper;
4444
private mixed $sourceContextProvider;
45+
private bool $webMode;
4546

46-
public function __construct(Stopwatch $stopwatch = null, string|FileLinkFormatter $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, DataDumperInterface|Connection $dumper = null)
47+
public function __construct(Stopwatch $stopwatch = null, string|FileLinkFormatter $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, DataDumperInterface|Connection $dumper = null, bool $webMode = null)
4748
{
4849
$fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4950
$this->stopwatch = $stopwatch;
5051
$this->fileLinkFormat = $fileLinkFormat instanceof FileLinkFormatter && false === $fileLinkFormat->format('', 0) ? false : $fileLinkFormat;
5152
$this->charset = $charset ?: \ini_get('php.output_encoding') ?: \ini_get('default_charset') ?: 'UTF-8';
5253
$this->requestStack = $requestStack;
5354
$this->dumper = $dumper;
55+
$this->webMode = $webMode ?? !\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true);
5456

5557
// All clones share these properties by reference:
5658
$this->rootRefs = [
@@ -231,7 +233,7 @@ public function __destruct()
231233
--$i;
232234
}
233235

234-
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && stripos($h[$i], 'html')) {
236+
if ($this->webMode) {
235237
$dumper = new HtmlDumper('php://output', $this->charset);
236238
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
237239
} else {

src/Symfony/Component/HttpKernel/DependencyInjection/LoggerPass.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,11 @@ public function process(ContainerBuilder $container)
3838
}
3939

4040
if ($debug = $container->getParameter('kernel.debug')) {
41-
// Build an expression that will be equivalent to `!in_array(PHP_SAPI, ['cli', 'phpdbg'])`
42-
$debug = (new Definition('bool'))
43-
->setFactory('in_array')
44-
->setArguments([
45-
(new Definition('string'))->setFactory('constant')->setArguments(['PHP_SAPI']),
46-
['cli', 'phpdbg'],
47-
]);
48-
$debug = (new Definition('bool'))
49-
->setFactory('in_array')
50-
->setArguments([$debug, [false]]);
41+
$debug = $container->hasDefinition('kernel.is_web_runtime_mode')
42+
? new Reference('kernel.is_web_runtime_mode')
43+
: (new Definition('bool'))
44+
->setFactory('str_starts_with')
45+
->setArguments(['%kernel.runtime_mode%', 'web']);
5146
}
5247

5348
$container->register('logger', Logger::class)

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,29 @@ class DebugHandlersListener implements EventSubscriberInterface
3232
{
3333
private string|object|null $earlyHandler;
3434
private ?\Closure $exceptionHandler;
35+
private bool $webMode;
3536
private bool $firstCall = true;
3637
private bool $hasTerminatedWithException = false;
3738

3839
/**
3940
* @param callable|null $exceptionHandler A handler that must support \Throwable instances that will be called on Exception
4041
*/
41-
public function __construct(callable $exceptionHandler = null)
42+
public function __construct(callable $exceptionHandler = null, bool $webMode = null)
4243
{
4344
$handler = set_exception_handler('is_int');
4445
$this->earlyHandler = \is_array($handler) ? $handler[0] : null;
4546
restore_exception_handler();
4647

4748
$this->exceptionHandler = null === $exceptionHandler ? null : $exceptionHandler(...);
49+
$this->webMode = $webMode ?? !\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true);
4850
}
4951

5052
/**
5153
* Configures the error handler.
5254
*/
5355
public function configure(object $event = null): void
5456
{
55-
if ($event instanceof ConsoleEvent && !\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
57+
if ($event instanceof ConsoleEvent && $this->webMode) {
5658
return;
5759
}
5860
if (!$event instanceof KernelEvent ? !$this->firstCall : !$event->isMainRequest()) {

src/Symfony/Component/HttpKernel/Kernel.php

+1
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ protected function getKernelParameters(): array
570570
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
571571
'kernel.environment' => $this->environment,
572572
'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%',
573+
'kernel.runtime_mode' => '%env(default:container.runtime_mode:APP_RUNTIME_MODE)%',
573574
'kernel.debug' => $this->debug,
574575
'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir,
575576
'kernel.cache_dir' => realpath($cacheDir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $cacheDir,

0 commit comments

Comments
 (0)
0