Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
"sail",
"lando",
"ddev",
"docker",
"local"
],
"enumItemLabels": [
Expand All @@ -241,6 +242,7 @@
"Sail",
"Lando",
"DDEV",
"Docker",
"Local"
],
"markdownEnumDescriptions": [
Expand All @@ -250,6 +252,7 @@
"Sail",
"Lando",
"DDEV",
"Docker",
"Use PHP installed on the local machine."
],
"default": "auto",
Expand All @@ -259,6 +262,16 @@
"type": "string",
"description": "Template for running PHP code. Use {code} as an optional placeholder for the php file to run. e.g. `php \"{code}\"`.\n\nIf no {code} is present, code filepath will be appended to the command."
},
"Laravel.dockerService": {
"type": "string",
"default": "php",
"description": "Name of the Docker service container holding PHP executable and Laravel app source code."
},
"Laravel.dockerBase": {
"type": "string",
"default": "/app",
"description": "Base path of the Laravel app source code inside Docker container."
},
"Laravel.basePath": {
"type": "string",
"default": "",
Expand Down Expand Up @@ -674,4 +687,4 @@
"vscode-languageserver-textdocument": "^1.0.11",
"vscode-languageserver-types": "^3.17.5"
}
}
}
14 changes: 11 additions & 3 deletions src/commands/pint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fixFilePath } from "@src/support/php";
import { fixFilePath, getPhpCommand, getPhpEnv } from "@src/support/php";
import {
statusBarError,
statusBarSuccess,
Expand All @@ -12,6 +12,7 @@ import { showErrorPopup } from "../support/popup";
import {
getWorkspaceFolders,
projectPath,
pathForPhpEnv,
projectPathExists,
} from "../support/project";

Expand All @@ -27,7 +28,8 @@ const runPintCommand = (
): Promise<string> => {
return new Promise<string>((resolve, reject) => {
// Check if pint exists in vendor/bin
const pintPath = projectPath("vendor/bin/pint");
const pintBin = "vendor/bin/pint";
const pintPath = projectPath(pintBin);

if (!projectPathExists("vendor/bin/pint")) {
const errorMessage =
Expand All @@ -37,7 +39,13 @@ const runPintCommand = (
return;
}

const command = `"${pintPath}" ${args}`.trim();
let command = `"${pintPath}" ${args}`.trim();

if (getPhpEnv() !== "local") {
const phpcmd = getPhpCommand();
const pintInEnv = pathForPhpEnv("vendor/bin/pint");
command = `${phpcmd} "${pintInEnv}" ${args}`.trim();
}

cp.exec(
command,
Expand Down
2 changes: 2 additions & 0 deletions src/support/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ type ConfigKey =
| "basePath"
| "phpEnvironment"
| "phpCommand"
| "dockerService"
| "dockerBase"
| "tests.docker.enabled"
| "tests.ssh.enabled"
| "tests.suiteSuffix"
Expand Down
14 changes: 12 additions & 2 deletions src/support/php.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getTemplate, TemplateName } from "@src/templates";
import * as cp from "child_process";
import * as fs from "fs";
import { sep as pathsep } from "path";
import * as vscode from "vscode";
import { BoundedFileCache } from "./cache";
import { config } from "./config";
Expand Down Expand Up @@ -91,7 +92,7 @@ export const initVendorWatchers = () => {
registerWatcher(autoloadWatcher);
};

const getPhpCommand = (): string => {
export const getPhpCommand = (): string => {
const phpEnv = config<PhpEnvironment>("phpEnvironment", "auto");

for (const [key, option] of Object.entries(phpEnvironments)) {
Expand All @@ -110,6 +111,15 @@ const getPhpCommand = (): string => {
let check = checks.shift();
let result = "";

if (key === "docker") {
const dockerService = config<string>("dockerService", "php");
check = check?.replace("{dockerService}", dockerService);
option.command = option.command.replace(
"{dockerService}",
dockerService,
);
}

while (check) {
info(`Checking ${key} PHP installation: ${check}`);

Expand Down Expand Up @@ -251,7 +261,7 @@ export const runInLaravel = <T>(

export const fixFilePath = (path: string) => {
if (phpEnvironmentsThatUseRelativePaths.includes(phpEnvKey!)) {
return relativePath(path);
return relativePath(path).replaceAll(pathsep, "/");
}

return path;
Expand Down
7 changes: 7 additions & 0 deletions src/support/phpEnvironments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type PhpEnvironment =
| "sail"
| "lando"
| "ddev"
| "docker"
| "local";

export const phpEnvironments: Record<PhpEnvironment, PhpEnvironmentConfig> = {
Expand Down Expand Up @@ -52,6 +53,12 @@ export const phpEnvironments: Record<PhpEnvironment, PhpEnvironmentConfig> = {
command: "ddev php",
relativePath: true,
},
docker: {
label: "Docker",
check: "docker compose exec {dockerService} which php",
command: 'docker compose exec {dockerService} "{binaryPath}"',
relativePath: true,
},
local: {
label: "Local",
description: "Use PHP installed on the local machine.",
Expand Down
10 changes: 9 additions & 1 deletion src/support/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "fs";
import * as path from "path";
import * as vscode from "vscode";
import { config } from "./config";
import { isPhpEnv } from "./php";
import { getPhpEnv, isPhpEnv } from "./php";

let internalVendorExists: boolean | null = null;

Expand Down Expand Up @@ -35,6 +35,14 @@ export const pathForPhpEnv = (srcPath: string): string => {
return srcPath.replace(new RegExp("^/var/www/html/"), "");
}

if (srcPath.match(/^\//) && getPhpEnv() === "docker") {
const dockerBase = config<string>("dockerBase", "/app").replace(
/\/$/,
"",
);
return projectPath(srcPath.replace(new RegExp(`^${dockerBase}/?`), ""));
}

return srcPath;
};

Expand Down