From 0b730b1d3054904b0d38388f11a90efee24cb964 Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Mon, 19 Jul 2021 17:13:28 +0000 Subject: [PATCH 1/3] Support for Linux on WSL Linux on WSL can still use the `host.docker.internal` host name to resolve the Docker VM, so we need to account for that too when switching between the Docker Engine IP used in Linux vs Linux on WSL. --- inc/composer/class-command.php | 18 ++++++++++++++++++ .../class-docker-compose-generator.php | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index 30c49ca4..ea9edd77 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -719,6 +719,24 @@ public static function is_macos() : bool { return php_uname( 's' ) === 'Darwin'; } + /** + * Check if the current host is Windows. + * + * @return boolean + */ + public static function is_windows() : bool { + return php_uname( 's' ) === 'Windows'; + } + + /** + * Check if the current host is WSL. + * + * @return boolean + */ + public static function is_wsl() : bool { + return ! empty( $_ENV['WSL_INTEROP'] ); + } + /** * Check if Mutagen is installed. * diff --git a/inc/composer/class-docker-compose-generator.php b/inc/composer/class-docker-compose-generator.php index 466a85e0..65665905 100644 --- a/inc/composer/class-docker-compose-generator.php +++ b/inc/composer/class-docker-compose-generator.php @@ -140,7 +140,10 @@ protected function get_php_reusable() : array { 'ALTIS_ANALYTICS_PINPOINT_ENDPOINT' => "https://pinpoint-{$this->hostname}", 'ALTIS_ANALYTICS_COGNITO_ENDPOINT' => "https://cognito-{$this->hostname}", // Enables XDebug for all processes and allows setting remote_host externally for Linux support. - 'XDEBUG_CONFIG' => sprintf( 'client_host=%s', Command::is_linux() ? '172.17.0.1' : 'host.docker.internal' ), + 'XDEBUG_CONFIG' => sprintf( + 'client_host=%s', + Command::is_linux() && ! Command::is_wsl() ? '172.17.0.1' : 'host.docker.internal' + ), 'PHP_IDE_CONFIG' => "serverName={$this->hostname}", 'XDEBUG_SESSION' => $this->hostname, // Set XDebug mode, fall back to "off" to avoid any performance hits. From 667517f181bd246fef1d7c846d4c5d712ec0d883 Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Mon, 19 Jul 2021 17:24:05 +0000 Subject: [PATCH 2/3] Update docs --- docs/using-xdebug.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/using-xdebug.md b/docs/using-xdebug.md index b98e989d..6fb0a72b 100644 --- a/docs/using-xdebug.md +++ b/docs/using-xdebug.md @@ -60,10 +60,11 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi ### VSCode +1. Install a [PHP Debug extension](https://github.com/xdebug/vscode-php-debug) 1. Open the debug tab (the bug icon on the menu sidebar). -2. In the dropdown menu at the top of the left hand side bar choose "Add configuration". -3. In the popup that appears select "PHP" as your environment. -4. You will be taken a new file called `.vscode/launch.json` with the default settings: +1. In the dropdown menu at the top of the left hand side bar choose "Add configuration". +1. In the popup that appears select "PHP" as your environment. +1. You will be taken a new file called `.vscode/launch.json` with the default settings: ```json { "version": "0.2.0", @@ -80,12 +81,12 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi "request": "launch", "program": "${file}", "cwd": "${fileDirname}", - "port": 9003, + "port": 9003 } ] } ``` -5. Add the following `pathMappings` property to each configuration: +1. Add the following `hostname` and `pathMappings` property to each configuration: ```json { "version": "0.2.0", @@ -95,6 +96,7 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi "type": "php", "request": "launch", "port": 9003, + "hostname": "0.0.0.0", "pathMappings": { "/usr/src/app": "${workspaceRoot}" } @@ -106,6 +108,7 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi "program": "${file}", "cwd": "${fileDirname}", "port": 9003, + "hostname": "0.0.0.0", "pathMappings": { "/usr/src/app": "${workspaceRoot}" } @@ -113,7 +116,7 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi ] } ``` -6. You are done, click the green play button to start the debug client. +1. You are done, click the green play button to start the debug client. For more information on the available configuration options, including Xdebug settings, [view the VSCode Debugging documentation here](https://go.microsoft.com/fwlink/?linkid=830387). From 04a83394f63c054cebeaac274d09c60811f785b4 Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Mon, 19 Jul 2021 17:36:48 +0000 Subject: [PATCH 3/3] Use getenv instead as `$_ENV` isn't reliable Co-authored-by: Ryan McCue --- inc/composer/class-command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index ea9edd77..431b9033 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -734,7 +734,7 @@ public static function is_windows() : bool { * @return boolean */ public static function is_wsl() : bool { - return ! empty( $_ENV['WSL_INTEROP'] ); + return getenv( 'WSL_INTEROP' ) !== false; } /**