Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6418aa

Browse files
committed
feature#52079 [HttpKernel] Add parameterskernel.runtime_mode andkernel.runtime_mode.*, all set from env varAPP_RUNTIME_MODE (nicolas-grekas)
This PR was merged into the 6.4 branch.Discussion----------[HttpKernel] Add parameters `kernel.runtime_mode` and `kernel.runtime_mode.*`, all set from env var `APP_RUNTIME_MODE`| Q | A| ------------- | ---| Branch? | 6.4| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets |Fix#51340| License | MIT| Doc PR | TODOAlternative to#51408. I think this approach is simpler and more powerful.Here, we ensure that the kernel always provides a new `kernel.runtime_mode` parameter. This parameter is an array derived by default from the `APP_RUNTIME_MODE` env var, using the `query_string` processor.This also creates 3 new parameters that should be the most common: `kernel.runtime_mode.web`, `kernel.runtime_mode.cli`, and `kernel.runtime_mode.worker`.A long-running server would typically set `APP_RUNTIME_MODE` to `web=1&worker=1` or `web=0&worker=1` when appropriate (eghttps://github.com/php-runtime/frankenphp-symfony/ should do so when `FRANKENPHP_WORKER` is set.)I screened the codebase and updated them all except cache pools (where the SAPI is used to enable/disable locking) and error renderers (where the SAPI is used to turn html-rendering on/off.) These require more work that could be done later on. There are a few other remaining usages of `PHP_SAPI` but these look not appropriate for the new flag.Commits-------7c70aec [HttpKernel] Add parameters `kernel.runtime_mode` and `kernel.runtime_mode.*`, all set from env var `APP_RUNTIME_MODE`
2 parents0e201d1 +7c70aec commitb6418aa

File tree

31 files changed

+62
-36
lines changed

31 files changed

+62
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
11841184
$container->setDefinition('debug.log_processor',$definition);
11851185

11861186
$container->register('debug.debug_logger_configurator', DebugLoggerConfigurator::class)
1187-
->setArguments([newReference('debug.log_processor')]);
1187+
->setArguments([newReference('debug.log_processor'),'%kernel.runtime_mode.web%']);
11881188
}
11891189
}
11901190

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

Lines changed: 1 addition & 0 deletions
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,param('kernel.runtime_mode.web')])
3536
->tag('kernel.event_subscriber')
3637

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

‎src/Symfony/Component/Cache/Adapter/AbstractAdapter.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static function createSystemCache(string $namespace, int $defaultLifetime
9797
return$opcache;
9898
}
9999

100-
if (\in_array(\PHP_SAPI, ['cli','phpdbg'],true) && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) {
100+
if ('cli' === \PHP_SAPI && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) {
101101
return$opcache;
102102
}
103103

‎src/Symfony/Component/Cache/Adapter/ChainAdapter.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(array $adapters, int $defaultLifetime = 0)
5353
if (!$adapterinstanceof CacheItemPoolInterface) {
5454
thrownewInvalidArgumentException(sprintf('The class "%s" does not implement the "%s" interface.',get_debug_type($adapter), CacheItemPoolInterface::class));
5555
}
56-
if (\in_array(\PHP_SAPI, ['cli','phpdbg'],true) &&$adapterinstanceof ApcuAdapter && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) {
56+
if ('cli' === \PHP_SAPI &&$adapterinstanceof ApcuAdapter && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) {
5757
continue;// skip putting APCu in the chain when the backend is disabled
5858
}
5959

‎src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function isSupported()
6161
{
6262
self::$startTime ??=$_SERVER['REQUEST_TIME'] ??time();
6363

64-
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));
64+
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));
6565
}
6666

6767
publicfunctionprune():bool

‎src/Symfony/Component/Cache/Traits/ContractsTrait.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function setCallbackWrapper(?callable $callbackWrapper): callable
4444
if (!isset($this->callbackWrapper)) {
4545
$this->callbackWrapper = LockRegistry::compute(...);
4646

47-
if (\in_array(\PHP_SAPI, ['cli','phpdbg'],true)) {
47+
if (\in_array(\PHP_SAPI, ['cli','phpdbg','embed'],true)) {
4848
$this->setCallbackWrapper(null);
4949
}
5050
}

‎src/Symfony/Component/DependencyInjection/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 {

‎src/Symfony/Component/DependencyInjection/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+
returnnull;
159+
}
157160
$returnNull =true;
158161
$prefix ='string';
159162
}

‎src/Symfony/Component/DependencyInjection/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
thrownewInvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.',$name));
4646
}
4747
if ($this->has($name) &&null !== ($defaultValue =parent::get($name)) && !\is_string($defaultValue)) {

‎src/Symfony/Component/DependencyInjection/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
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp