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

[HttpKernel] Add parameters kernel.runtime_mode and kernel.runtime_mode.*, all set from env var APP_RUNTIME_MODE #52079

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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%']);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

aligning with other checks we have in place for APCu (not need to enable it for phpdbg/embed)

return $opcache;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/ChainAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/ContractsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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])) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this change allows to derivate dynamic parameters from other ones, eg %env(key:foo:default:bar:)% extracts key foo from parameter bar (which is supposed to be an array here)

$dynamicPhp[$key] = sprintf('%s%s => %s,', $export[0], $this->export($key), $export[1]);
$this->dynamicParameters[$key] = true;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

)
Original file line number Diff line number Diff line change
Expand Up @@ -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');

)
Original file line number Diff line number Diff line change
Expand Up @@ -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');

)
Original file line number Diff line number Diff line change
Expand Up @@ -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');

)
Original file line number Diff line number Diff line change
Expand Up @@ -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');

)
Original file line number Diff line number Diff line change
Expand Up @@ -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');

)
Original file line number Diff line number Diff line change
Expand Up @@ -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');

)
2 changes: 1 addition & 1 deletion src/Symfony/Component/ErrorHandler/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/ErrorHandler/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
nicolas-grekas marked this conversation as resolved.
Show resolved Hide resolved

$exception = $renderer->render($exception);

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ 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;
$this->fileLinkFormat = $fileLinkFormat instanceof FileLinkFormatter && false === $fileLinkFormat->format('', 0) ? false : $fileLinkFormat;
$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 = [
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,29 @@ 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);
}

/**
* Configures the error handler.
*/
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()) {
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Copy link
Member Author

Choose a reason for hiding this comment

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

Unlike the logic in $response->send(), we call this unconditionally. The reason is that here, in the runtime, we know we want to flush whatever the SAPI.

flush();
}
} else {
$response->send();
}

if ($this->kernel instanceof TerminableInterface) {
$this->kernel->terminate($this->request, $response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/VarDumper/VarDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down