CakePHP 4 + VSCode + DebugKit SETUP

There are three configurations this…

Login

Blog History

There are three configurations this post covers

Local Development

Use the default if working locally

If you are using CakePHP 4 and developing on the local file system (straight from Windows) use this:

Debugger::setEditor('vscode');

If your project is in C:\Users\ja.TGNT\cake_test you get a URL as follows on a Windows 11 System

vscode://file/C:\Users\ja.TGNT\cake_test\vendor\cakephp\cakephp\src\Controller\Controller.php:547

For WSL

To get to a file hosted in WSL you have to make sure the link targets the full path to the file in the WSL environment.

In this case I have the source code being served from a folder in WSL via a Docker container.

So I have to remove the CakePHP 4 ROOT (/var/www/wms) and prepend the WSL path to that mounted folder.

Debugger::addEditor('wsl', function ($file, $line) {
    $file = str_replace(ROOT, '', $file);

    $prefix = '/home/ja/dev/wms';

    return "vscode://vscode-remote/wsl+Ubuntu-22.04{$prefix}{$file}:{$line}";
});

Debugger::setEditor('wsl');

An example of a URL for WSL

vscode://vscode-remote/wsl+Ubuntu-22.04/home/ja/dev/wms/vendor/cakephp/cakephp/src/Database/Expression/QueryExpression.php:647

Note the /wsl+Ubuntu-22.04 which is the Windows Subsystem for Linux Distribution being used

Windows 11 Host and Docker using WSL2 Engine

This will allow you to attach to a running docker Development container

Debugger::addEditor('docker', function ($file, $line) {
    $container = [
        'containerName' => 'wms-php-1'
    ];

    $json = json_encode($container);

    $hex = bin2hex($json);

    return "vscode://vscode-remote/attached-container+{$hex}{$file}:{$line}";
});

Debugger::setEditor('docker');

An example of a URL for attaching to a running Docker container

vscode://vscode-remote/attached-container+7b22636f6e7461696e65724e616d65223a22776d732d7068702d31227d/var/www/wms/vendor/cakephp/cakephp/src/Database/Expression/QueryExpression.php:647

References

https://github.com/microsoft/vscode-remote-release/issues/6832

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.