1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Turbo;
4:
5: use PHPStan\Process\Restart\RestartManager;
6:
7: /**
8: * Kept for programs that load PHPStan's phar and restart into PHPStan Turbo
9: * themselves, Rector for example. PHPStan's own bin/phpstan calls
10: * RestartManager directly.
11: */
12: final class TurboProcessRestarter
13: {
14:
15: /**
16: * On success the call never returns — the process image is replaced.
17: *
18: * Another program that loads PHPStan's phar, Rector for example, passes
19: * the path to that phar: Phar::running() only knows the phar that runs.
20: *
21: * Without $appName only what the turbo extension needs is restarted for,
22: * as before. With it, the same single restart also neutralizes xdebug,
23: * pcov and the other hooks PHPStan's own restart does, unless --xdebug is
24: * in $argv or <APP>_ALLOW_XDEBUG is set - the variable composer/xdebug-handler
25: * reads for that application, so a caller can drop its own xdebug restart.
26: *
27: * @api
28: * @param list<string> $argv
29: */
30: public static function restartIfSuitable(array $argv, ?string $pharPath = null, ?string $appName = null): void
31: {
32: if ($appName === null) {
33: RestartManager::run($argv, $pharPath, ['phpstan_turbo', 'tideways', 'opcache']);
34: return;
35: }
36:
37: RestartManager::run($argv, $pharPath, appName: $appName);
38: }
39:
40: }
41: