diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 569b8f417eda..a720e96a4661 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1176,7 +1176,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con $container->setDefinition('debug.log_processor', $definition); $container->register('debug.debug_logger_configurator', DebugLoggerConfigurator::class) - ->setArguments([new Reference('debug.log_processor')]); + ->setArguments([new Reference('debug.log_processor'), '%kernel.runtime_mode.web%']); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.php index af6ca27dcabf..074f0128d976 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.php @@ -32,6 +32,7 @@ ->tag('monolog.logger', ['channel' => 'php']) ->set('debug.debug_handlers_listener', DebugHandlersListener::class) + ->args([null, param('kernel.runtime_mode.web')]) ->tag('kernel.event_subscriber') ->set('debug.file_link_formatter', FileLinkFormatter::class) diff --git a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php index 40eb4978b1b3..ed90f4716c7f 100644 --- a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php @@ -97,7 +97,7 @@ public static function createSystemCache(string $namespace, int $defaultLifetime return $opcache; } - if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) { + if ('cli' === \PHP_SAPI && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) { return $opcache; } diff --git a/src/Symfony/Component/Cache/Adapter/ChainAdapter.php b/src/Symfony/Component/Cache/Adapter/ChainAdapter.php index ffaa56f3ed3e..8c2e7e111b00 100644 --- a/src/Symfony/Component/Cache/Adapter/ChainAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ChainAdapter.php @@ -53,7 +53,7 @@ public function __construct(array $adapters, int $defaultLifetime = 0) if (!$adapter instanceof CacheItemPoolInterface) { throw new InvalidArgumentException(sprintf('The class "%s" does not implement the "%s" interface.', get_debug_type($adapter), CacheItemPoolInterface::class)); } - if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && $adapter instanceof ApcuAdapter && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) { + if ('cli' === \PHP_SAPI && $adapter instanceof ApcuAdapter && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) { continue; // skip putting APCu in the chain when the backend is disabled } diff --git a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php index 4260cf5766dd..41ea8604c495 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php @@ -61,7 +61,7 @@ public static function isSupported() { self::$startTime ??= $_SERVER['REQUEST_TIME'] ?? time(); - return \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOL)); + return \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOL)); } public function prune(): bool diff --git a/src/Symfony/Component/Cache/Traits/ContractsTrait.php b/src/Symfony/Component/Cache/Traits/ContractsTrait.php index 476883a679e3..083ce1f9dbd3 100644 --- a/src/Symfony/Component/Cache/Traits/ContractsTrait.php +++ b/src/Symfony/Component/Cache/Traits/ContractsTrait.php @@ -44,7 +44,7 @@ public function setCallbackWrapper(?callable $callbackWrapper): callable if (!isset($this->callbackWrapper)) { $this->callbackWrapper = LockRegistry::compute(...); - if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { + if (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { $this->setCallbackWrapper(null); } } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 8a5b4b1467a5..ff11062b99b9 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -340,7 +340,7 @@ class %s extends {$options['class']} use Symfony\Component\DependencyInjection\Dumper\Preloader; -if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) { +if (in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { return; } @@ -388,6 +388,7 @@ class %s extends {$options['class']} 'container.build_hash' => '$hash', 'container.build_id' => '$id', 'container.build_time' => $time, + 'container.runtime_mode' => \\in_array(\\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', ], __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}'); EOF; @@ -1591,7 +1592,7 @@ private function addDefaultParametersMethod(): string $export = $this->exportParameters([$value], '', 12, $hasEnum); $export = explode('0 => ', substr(rtrim($export, " ]\n"), 2, -1), 2); - if ($hasEnum || preg_match("/\\\$container->(?:getEnv\('(?:[-.\w\\\\]*+:)*+\w++'\)|targetDir\.'')/", $export[1])) { + if ($hasEnum || preg_match("/\\\$container->(?:getEnv\('(?:[-.\w\\\\]*+:)*+\w*+'\)|targetDir\.'')/", $export[1])) { $dynamicPhp[$key] = sprintf('%s%s => %s,', $export[0], $this->export($key), $export[1]); $this->dynamicParameters[$key] = true; } else { diff --git a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php index 7c77e1a1490c..bae5e289d7ec 100644 --- a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php +++ b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php @@ -154,6 +154,9 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed $returnNull = false; if ('' === $prefix) { + if ('' === $name) { + return null; + } $returnNull = true; $prefix = 'string'; } diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php index 9c66e1f94416..4719d2126cca 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php @@ -41,7 +41,7 @@ public function get(string $name): array|bool|string|int|float|\UnitEnum|null return $placeholder; // return first result } } - if (!preg_match('/^(?:[-.\w\\\\]*+:)*+\w++$/', $env)) { + if (!preg_match('/^(?:[-.\w\\\\]*+:)*+\w*+$/', $env)) { throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name)); } if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10_as_files.txt index 25d0b3257f0d..1e6b86f8dcd9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10_as_files.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10_as_files.txt @@ -154,6 +154,7 @@ return new \Container%s\ProjectServiceContainer([ 'container.build_hash' => '%s', 'container.build_id' => '%s', 'container.build_time' => %d, + 'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', ], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); ) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt index 0b367ccb4456..cfe6777b10b6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt @@ -787,6 +787,7 @@ return new \Container%s\ProjectServiceContainer([ 'container.build_hash' => '%s', 'container.build_id' => '%s', 'container.build_time' => %d, + 'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', ], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); ) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt index 7ef2e555a452..0f64f93ac696 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt @@ -604,6 +604,7 @@ return new \Container%s\ProjectServiceContainer([ 'container.build_hash' => '%s', 'container.build_id' => '%s', 'container.build_time' => 1563381341, + 'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', ], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); ) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories_with_tagged_iterrator.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories_with_tagged_iterrator.txt index 61ea67f6b952..17bc9ed6e6e8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories_with_tagged_iterrator.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories_with_tagged_iterrator.txt @@ -119,6 +119,7 @@ return new \Container%s\ProjectServiceContainer([ 'container.build_hash' => '%s', 'container.build_id' => '%s', 'container.build_time' => %d, + 'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', ], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); ) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt index 07dd32230637..909e1dcc15b8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt @@ -187,6 +187,7 @@ return new \Container%s\ProjectServiceContainer([ 'container.build_hash' => '%s', 'container.build_id' => '%s', 'container.build_time' => 1563381341, + 'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', ], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); ) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters_as_files.txt index a16e843217ca..53c99dc7106b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters_as_files.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters_as_files.txt @@ -195,6 +195,7 @@ return new \Container%s\ProjectServiceContainer([ 'container.build_hash' => '%s', 'container.build_id' => '%s', 'container.build_time' => %d, + 'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', ], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); ) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_non_shared_lazy_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_non_shared_lazy_as_files.txt index fd9d7b20c400..c06a6c1458f5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_non_shared_lazy_as_files.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_non_shared_lazy_as_files.txt @@ -164,6 +164,7 @@ return new \Container%s\Symfony_DI_PhpDumper_Service_Non_Shared_Lazy_As_File([ 'container.build_hash' => '%s', 'container.build_id' => '%s', 'container.build_time' => %d, + 'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', ], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); ) diff --git a/src/Symfony/Component/ErrorHandler/Debug.php b/src/Symfony/Component/ErrorHandler/Debug.php index 641c273446f8..d54a38c4cac1 100644 --- a/src/Symfony/Component/ErrorHandler/Debug.php +++ b/src/Symfony/Component/ErrorHandler/Debug.php @@ -22,7 +22,7 @@ public static function enable(): ErrorHandler { error_reporting(-1); - if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { + if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { ini_set('display_errors', 0); } elseif (!filter_var(\ini_get('log_errors'), \FILTER_VALIDATE_BOOL) || \ini_get('error_log')) { // CLI - display errors only if they're not already logged to STDERR diff --git a/src/Symfony/Component/ErrorHandler/ErrorHandler.php b/src/Symfony/Component/ErrorHandler/ErrorHandler.php index c5339dc1ad12..1ee29e1b8e71 100644 --- a/src/Symfony/Component/ErrorHandler/ErrorHandler.php +++ b/src/Symfony/Component/ErrorHandler/ErrorHandler.php @@ -640,7 +640,7 @@ public static function handleFatalError(array $error = null): void */ private function renderException(\Throwable $exception): void { - $renderer = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliErrorRenderer() : new HtmlErrorRenderer($this->debug); + $renderer = \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? new CliErrorRenderer() : new HtmlErrorRenderer($this->debug); $exception = $renderer->render($exception); diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 29db6297f183..dca93df616a0 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -433,7 +433,7 @@ public function send(/* bool $flush = true */): static fastcgi_finish_request(); } elseif (\function_exists('litespeed_finish_request')) { litespeed_finish_request(); - } elseif (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { + } elseif (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { static::closeOutputBuffers(0, true); flush(); } diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 5714af6e68dc..65b4a6aadd7e 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -11,6 +11,7 @@ CHANGELOG * Add argument `$validationFailedStatusCode` to `#[MapQueryString]` and `#[MapRequestPayload]` * Add argument `$debug` to `Logger` * Add class `DebugLoggerConfigurator` + * Add parameters `kernel.runtime_mode` and `kernel.runtime_mode.*`, all set from env var `APP_RUNTIME_MODE` * Deprecate `Kernel::stripComments()` * Support the `!` character at the beginning of a string as a negation operator in the url filter of the profiler * Deprecate `UriSigner`, use `UriSigner` from the HttpFoundation component instead diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index 4f518e7bbc2f..ce02b545bf17 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -42,8 +42,9 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface private ?RequestStack $requestStack; private DataDumperInterface|Connection|null $dumper; private mixed $sourceContextProvider; + private bool $webMode; - public function __construct(Stopwatch $stopwatch = null, string|FileLinkFormatter $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, DataDumperInterface|Connection $dumper = null) + public function __construct(Stopwatch $stopwatch = null, string|FileLinkFormatter $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, DataDumperInterface|Connection $dumper = null, bool $webMode = null) { $fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); $this->stopwatch = $stopwatch; @@ -51,6 +52,7 @@ public function __construct(Stopwatch $stopwatch = null, string|FileLinkFormatte $this->charset = $charset ?: \ini_get('php.output_encoding') ?: \ini_get('default_charset') ?: 'UTF-8'; $this->requestStack = $requestStack; $this->dumper = $dumper; + $this->webMode = $webMode ?? !\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true); // All clones share these properties by reference: $this->rootRefs = [ @@ -231,7 +233,7 @@ public function __destruct() --$i; } - if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && stripos($h[$i], 'html')) { + if ($this->webMode) { $dumper = new HtmlDumper('php://output', $this->charset); $dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]); } else { diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/LoggerPass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/LoggerPass.php index cfe35b03f071..aafe59d0011d 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/LoggerPass.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/LoggerPass.php @@ -37,18 +37,7 @@ public function process(ContainerBuilder $container) return; } - if ($debug = $container->getParameter('kernel.debug')) { - // Build an expression that will be equivalent to `!in_array(PHP_SAPI, ['cli', 'phpdbg'])` - $debug = (new Definition('bool')) - ->setFactory('in_array') - ->setArguments([ - (new Definition('string'))->setFactory('constant')->setArguments(['PHP_SAPI']), - ['cli', 'phpdbg'], - ]); - $debug = (new Definition('bool')) - ->setFactory('in_array') - ->setArguments([$debug, [false]]); - } + $debug = $container->getParameter('kernel.debug') && $container->getParameter('kernel.runtime_mode.web'); $container->register('logger', Logger::class) ->setArguments([null, null, null, new Reference(RequestStack::class), $debug]); diff --git a/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php b/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php index 399a69431e1e..4b0d1491811f 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php @@ -32,19 +32,21 @@ class DebugHandlersListener implements EventSubscriberInterface { private string|object|null $earlyHandler; private ?\Closure $exceptionHandler; + private bool $webMode; private bool $firstCall = true; private bool $hasTerminatedWithException = false; /** * @param callable|null $exceptionHandler A handler that must support \Throwable instances that will be called on Exception */ - public function __construct(callable $exceptionHandler = null) + public function __construct(callable $exceptionHandler = null, bool $webMode = null) { $handler = set_exception_handler('is_int'); $this->earlyHandler = \is_array($handler) ? $handler[0] : null; restore_exception_handler(); $this->exceptionHandler = null === $exceptionHandler ? null : $exceptionHandler(...); + $this->webMode = $webMode ?? !\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true); } /** @@ -52,7 +54,7 @@ public function __construct(callable $exceptionHandler = null) */ public function configure(object $event = null): void { - if ($event instanceof ConsoleEvent && !\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { + if ($event instanceof ConsoleEvent && $this->webMode) { return; } if (!$event instanceof KernelEvent ? !$this->firstCall : !$event->isMainRequest()) { diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index e55cfdf3dca2..ee5cf2756e9e 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -570,6 +570,10 @@ protected function getKernelParameters(): array 'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(), 'kernel.environment' => $this->environment, 'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%', + 'kernel.runtime_mode' => '%env(query_string:default:container.runtime_mode:APP_RUNTIME_MODE)%', + 'kernel.runtime_mode.web' => '%env(bool:default::key:web:default:kernel.runtime_mode:)%', + 'kernel.runtime_mode.cli' => '%env(not:default:kernel.runtime_mode.web:)%', + 'kernel.runtime_mode.worker' => '%env(bool:default::key:worker:default:kernel.runtime_mode:)%', 'kernel.debug' => $this->debug, 'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir, 'kernel.cache_dir' => realpath($cacheDir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $cacheDir, diff --git a/src/Symfony/Component/HttpKernel/Log/DebugLoggerConfigurator.php b/src/Symfony/Component/HttpKernel/Log/DebugLoggerConfigurator.php index b3e408af84a0..a6e61f622bf4 100644 --- a/src/Symfony/Component/HttpKernel/Log/DebugLoggerConfigurator.php +++ b/src/Symfony/Component/HttpKernel/Log/DebugLoggerConfigurator.php @@ -22,7 +22,7 @@ class DebugLoggerConfigurator public function __construct(DebugLoggerInterface $processor, bool $enable = null) { - if ($enable ?? !\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { + if ($enable ?? !\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { $this->processor = $processor; } } diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 045a035a2f04..be3db21cc7de 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -343,7 +343,7 @@ private function getConfigCacheFactory(): ConfigCacheFactoryInterface private static function getCompiledRoutes(string $path): array { - if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOL))) { + if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOL))) { self::$cache = null; } diff --git a/src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php b/src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php index 63e11973b5a6..3567c99eace1 100644 --- a/src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php +++ b/src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php @@ -22,7 +22,7 @@ public static function register(bool $debug): void { error_reporting(-1); - if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { + if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { ini_set('display_errors', $debug); } elseif (!filter_var(\ini_get('log_errors'), \FILTER_VALIDATE_BOOL) || \ini_get('error_log')) { // CLI - display errors only if they're not already logged to STDERR diff --git a/src/Symfony/Component/Runtime/Runner/Symfony/HttpKernelRunner.php b/src/Symfony/Component/Runtime/Runner/Symfony/HttpKernelRunner.php index a5176a9ca309..13c9037ca853 100644 --- a/src/Symfony/Component/Runtime/Runner/Symfony/HttpKernelRunner.php +++ b/src/Symfony/Component/Runtime/Runner/Symfony/HttpKernelRunner.php @@ -12,7 +12,9 @@ namespace Symfony\Component\Runtime\Runner\Symfony; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\TerminableInterface; use Symfony\Component\Runtime\RunnerInterface; @@ -31,7 +33,21 @@ public function __construct( public function run(): int { $response = $this->kernel->handle($this->request); - $response->send(!$this->debug); + + if (Kernel::VERSION_ID >= 60400) { + $response->send(false); + + if (\function_exists('fastcgi_finish_request') && !$this->debug) { + fastcgi_finish_request(); + } elseif (\function_exists('litespeed_finish_request') && !$this->debug) { + litespeed_finish_request(); + } else { + Response::closeOutputBuffers(0, true); + flush(); + } + } else { + $response->send(); + } if ($this->kernel instanceof TerminableInterface) { $this->kernel->terminate($this->request, $response); diff --git a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php index 93f23cd95fe4..541b6c8322bb 100644 --- a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php @@ -22,7 +22,7 @@ class PhpFileLoader extends FileLoader protected function loadResource(string $resource): array { - if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOL))) { + if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOL))) { self::$cache = null; } diff --git a/src/Symfony/Component/VarDumper/Resources/functions/dump.php b/src/Symfony/Component/VarDumper/Resources/functions/dump.php index a0e5addff109..f2ff74c0caee 100644 --- a/src/Symfony/Component/VarDumper/Resources/functions/dump.php +++ b/src/Symfony/Component/VarDumper/Resources/functions/dump.php @@ -45,7 +45,7 @@ function dump(mixed ...$vars): mixed if (!function_exists('dd')) { function dd(mixed ...$vars): never { - if (!in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && !headers_sent()) { + if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) && !headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } diff --git a/src/Symfony/Component/VarDumper/VarDumper.php b/src/Symfony/Component/VarDumper/VarDumper.php index cfc6b2807b4d..baff2115b489 100644 --- a/src/Symfony/Component/VarDumper/VarDumper.php +++ b/src/Symfony/Component/VarDumper/VarDumper.php @@ -85,11 +85,11 @@ private static function register(): void case 'server' === $format: case $format && 'tcp' === parse_url($format, \PHP_URL_SCHEME): $host = 'server' === $format ? $_SERVER['VAR_DUMPER_SERVER'] ?? '127.0.0.1:9912' : $format; - $dumper = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliDumper() : new HtmlDumper(); + $dumper = \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? new CliDumper() : new HtmlDumper(); $dumper = new ServerDumper($host, $dumper, self::getDefaultContextProviders()); break; default: - $dumper = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliDumper() : new HtmlDumper(); + $dumper = \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? new CliDumper() : new HtmlDumper(); } if (!$dumper instanceof ServerDumper) { @@ -111,7 +111,7 @@ private static function getDefaultContextProviders(): array { $contextProviders = []; - if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && class_exists(Request::class)) { + if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) && class_exists(Request::class)) { $requestStack = new RequestStack(); $requestStack->push(Request::createFromGlobals()); $contextProviders['request'] = new RequestContextProvider($requestStack);