Last active
December 29, 2023 23:57
-
-
Save adrolter/58f3415dc8f3668abec1a86351b3e0bf to your computer and use it in GitHub Desktop.
Symfony Xdebug bypass when building the container in dev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/php -dxdebug.mode=off | |
<?php | |
declare(strict_types=1); | |
use App\Kernel; | |
switch (\ini_get('xdebug.mode')) { | |
case false: | |
case 'off': | |
/** NOP */ | |
break; | |
default: | |
throw new \RuntimeException( | |
<<<'TXT' | |
This script should not be run with Xdebug enabled! | |
Call it with "php -d xdebug.mode=off ...", set the XDEBUG_MODE environment variable to "off", or include a config file that disables it. | |
TXT | |
); | |
} | |
\set_time_limit(60); | |
require '/app/vendor/autoload_runtime.php'; | |
return static function (array $context) { | |
return new Kernel($context['APP_ENV'], (bool)$context['APP_DEBUG'], $_SERVER['argv'][1]); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ruN '--exclude=PATCHES.txt' http-kernel/Kernel.php http-kernel.dev-container-build-xdebug-bypass/Kernel.php | |
--- http-kernel/Kernel.php 2023-12-11 14:14:49.781237797 -0500 | |
+++ http-kernel.dev-container-build-xdebug-bypass/Kernel.php 2023-12-11 14:04:13.717919757 -0500 | |
@@ -422,6 +423,38 @@ | |
} catch (\Throwable $e) { | |
} | |
+ if ($this->environment === 'dev') { | |
+ switch ($_ENV['XDEBUG_MODE'] ?? \ini_get('xdebug.mode')) { | |
+ case false: | |
+ case 'off': | |
+ /** NOP */ | |
+ break; | |
+ default: | |
+ \exec( | |
+ \sprintf( | |
+ 'XDEBUG_MODE=off /app/bin/build-dev-container %s', | |
+ \escapeshellarg($buildDir) | |
+ ), | |
+ $output, | |
+ $exitCode, | |
+ ); | |
+ | |
+ if ($exitCode !== 0) { | |
+ throw new \RuntimeException( | |
+ \sprintf( | |
+ <<<'TXT' | |
+ FATAL: Failed compiling the service container via build-dev-container (Exit code: %d) | |
+ ======%s | |
+ TXT, | |
+ $exitCode, | |
+ \implode(\PHP_EOL, $output), | |
+ ) | |
+ ); | |
+ } | |
+ return $this->initializeContainer(); | |
+ } | |
+ } | |
+ | |
$oldContainer = \is_object($this->container) ? new \ReflectionClass($this->container) : $this->container = null; | |
try { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment