VOOZH about

URL: https://deepwiki.com/invokable/laravel-boost-phpstorm-copilot/8.2-withwsl-trait-api

⇱ WithWSL Trait API | invokable/laravel-boost-phpstorm-copilot | DeepWiki


Loading...
Last indexed: 28 February 2026 (57ef88)
Menu

WithWSL Trait API

This page is the complete API reference for the WithWSL trait located at src/Concerns/WithWSL.php It covers the three methods exposed by the trait, their exact signatures, parameter contracts, return values, and the step-by-step behavior of each. For an explanation of why the WSL pipeline exists and how it fits into the broader installation flow, see 5.3. For how PhpStormCopilot calls these methods as part of installFileMcp, see 4.3.


Trait Location and Usage

ItemValue
Filesrc/Concerns/WithWSL.php
NamespaceRevolution\Laravel\Boost\Concerns
Used byRevolution\Laravel\Boost\PhpStormCopilot
Visibility of all three methodsprotected (except transformMcpCommandForWsl, which is public)

PhpStormCopilot mixes in the trait with use WithWSL; at src/PhpStormCopilot.php17

Diagram: Trait Composition


Sources: src/Concerns/WithWSL.php1-129 src/PhpStormCopilot.php17


Method Reference

isWSL()

src/Concerns/WithWSL.php11-14

protected function isWSL(): bool

Purpose: Determine whether the current PHP process is running inside Windows Subsystem for Linux.

Mechanism: Reads the WSL_DISTRO_NAME environment variable. The variable is automatically set by the WSL kernel for every process running in a WSL distribution. Returns true if the variable is non-empty.

DetailValue
Visibilityprotected
Return typebool
Environment variable checkedWSL_DISTRO_NAME
Returns true whenWSL_DISTRO_NAME is set and non-empty
Returns false whenRunning on native Linux, macOS, or Windows

Called from: PhpStormCopilot::installFileMcp() at src/PhpStormCopilot.php125-127 to select the WSL-specific installation branch.

Sources: src/Concerns/WithWSL.php11-14 src/PhpStormCopilot.php125-127


installMcpViaWsl()

src/Concerns/WithWSL.php16-76

protected function installMcpViaWsl(string $name, string $command, array $args): bool

Purpose: Write the MCP server entry into the Windows-side mcp.json from within a WSL process. Because PhpStorm runs on Windows, the config file must reside on the Windows filesystem at %LOCALAPPDATA%\github-copilot\intellij\mcp.json, which is not directly writable from Linux paths. All file I/O is performed via powershell.exe calls.

Parameters

ParameterTypeDescription
$namestringThe key to use inside mcp.json's servers object (e.g., "laravel-boost")
$commandstringThe raw command string produced by laravel/boost (may be a PHP path, Sail path, or wsl.exe)
$argsarrayThe argument array accompanying $command

Return Value

Returns bool. Returns true when the final powershell.exe copy operation succeeds, false if wslvar LOCALAPPDATA returns an empty string or any powershell.exe process call fails. Process failures also throw via ->throw() on the Process facade result.

Step-by-Step Execution

Diagram: installMcpViaWsl Execution Steps


Internal Details

StepMechanism
Read Windows LOCALAPPDATAProcess::run('wslvar LOCALAPPDATA') — requires wslu package
Windows target path{LOCALAPPDATA}\github-copilot\intellij\mcp.json
Read existing mcp.jsonpowershell.exe -NoProfile -Command "if (Test-Path ...) { Get-Content ... -Raw } else { '{}' }"
Config key namespace$this->mcpConfigKey() — returns "servers" for PhpStormCopilot
Command normalization$this->transformMcpCommandForWsl($command, $args)
Empty array cleanup$this->removeEmptyArrays($config) — defined on PhpStormCopilot
Safe file writeJSON encoded to Base64, decoded by [System.Convert]::FromBase64String in PowerShell, written to a temp file, then copied to the final destination
Temp file namemcp_{uniqid()}.json written into {LOCALAPPDATA}\Temp\
Final copyNew-Item -ItemType Directory -Force + Copy-Item + Remove-Item (temp cleanup)

The Base64 encoding step exists to safely pass arbitrary JSON (including quotes, backslashes, and Unicode) through the Windows command-line argument parser without escaping conflicts.

Sources: src/Concerns/WithWSL.php16-76


transformMcpCommandForWsl()

src/Concerns/WithWSL.php85-128

public function transformMcpCommandForWsl(string $command, array $args): array

Purpose: Convert the Linux-side $command / $args pair into a form that PhpStorm (running on Windows) can invoke via wsl.exe. PhpStorm's MCP client executes the command written in mcp.json as a Windows process; to run a command inside WSL it must call wsl.exe with appropriate flags.

Parameters

ParameterTypeDescription
$commandstringThe incoming command (Sail path, wsl.exe, or a PHP binary path)
$argsarrayThe argument list accompanying the command

Return Value

array{command: string, args: array} — always returns an associative array with keys command and args.

Dispatch Logic (Three Cases)

Diagram: transformMcpCommandForWsl Branch Logic


Case Details

CaseTrigger ConditionOutput commandOutput args
1 — Sail$command ends with /vendor/bin/sail (Unix) or \vendor\bin\sail (Windows)"wsl.exe"["--cd", base_path(), "./vendor/bin/sail", ...$args]
2 — Already wsl.exe$command starts with "wsl"$command (pass-through)$args (pass-through)
3 — Direct PHP pathAny other value (e.g., /usr/bin/php, php)"wsl.exe"["--cd", base_path(), $command, ...$args]

The --cd flag instructs wsl.exe to change to the project directory before executing, which ensures relative paths (like ./vendor/bin/sail) resolve correctly.

Test Coverage

The test file tests/Feature/PhpStormCopilotTest.php92-202 covers all three cases and several path variants:

Test nameCase covered
transformMcpCommandForWsl handles Sail with relative pathCase 1 — ./vendor/bin/sail
transformMcpCommandForWsl handles Sail with absolute pathCase 1 — /home/user/project/vendor/bin/sail
transformMcpCommandForWsl handles Sail with Windows-style pathCase 1 — C:\...\vendor\bin\sail
transformMcpCommandForWsl handles WSL without SailCase 2 — wsl.exe
transformMcpCommandForWsl handles direct PHP pathCase 3 — /usr/bin/php
transformMcpCommandForWsl handles relative PHP pathCase 3 — php

Sources: src/Concerns/WithWSL.php85-128 tests/Feature/PhpStormCopilotTest.php92-202


Call Graph Within PhpStormCopilot

Diagram: How PhpStormCopilot::installFileMcp Delegates to WithWSL


Sources: src/PhpStormCopilot.php119-132 src/Concerns/WithWSL.php16-76 src/Concerns/WithWSL.php85-128


Dependencies

DependencyUsed inPurpose
Illuminate\Support\Facades\ProcessinstallMcpViaWslExecutes wslvar and powershell.exe subprocesses
wslvar (from wslu package)installMcpViaWslReads Windows environment variables from within WSL
powershell.exeinstallMcpViaWslReads/writes files on the Windows filesystem
base_path()transformMcpCommandForWslProvides the project root as an absolute Linux path for wsl.exe --cd
$this->mcpConfigKey()installMcpViaWslThe JSON key used to namespace the server entry ("servers")
$this->removeEmptyArrays()installMcpViaWslStrips empty arrays before writing; defined on PhpStormCopilot

Sources: src/Concerns/WithWSL.php1-129