Skip to content

Commit 1f279e1

Browse files
committed
Execute pint inside active PHP environment, e.g. when not in local
1 parent d8ab4bc commit 1f279e1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/commands/pint.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fixFilePath } from "@src/support/php";
1+
import { fixFilePath, getPhpCommand, getPhpEnv } from "@src/support/php";
22
import {
33
statusBarError,
44
statusBarSuccess,
@@ -12,6 +12,7 @@ import { showErrorPopup } from "../support/popup";
1212
import {
1313
getWorkspaceFolders,
1414
projectPath,
15+
pathForPhpEnv,
1516
projectPathExists,
1617
} from "../support/project";
1718

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

3234
if (!projectPathExists("vendor/bin/pint")) {
3335
const errorMessage =
@@ -37,7 +39,13 @@ const runPintCommand = (
3739
return;
3840
}
3941

40-
const command = `"${pintPath}" ${args}`.trim();
42+
let command = `"${pintPath}" ${args}`.trim();
43+
44+
if (getPhpEnv() !== "local") {
45+
const phpcmd = getPhpCommand();
46+
const pintInEnv = pathForPhpEnv("vendor/bin/pint");
47+
command = `${phpcmd} "${pintInEnv}" ${args}`.trim();
48+
}
4149

4250
cp.exec(
4351
command,

src/support/php.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const initVendorWatchers = () => {
9292
registerWatcher(autoloadWatcher);
9393
};
9494

95-
const getPhpCommand = (): string => {
95+
export const getPhpCommand = (): string => {
9696
const phpEnv = config<PhpEnvironment>("phpEnvironment", "auto");
9797

9898
for (const [key, option] of Object.entries(phpEnvironments)) {

0 commit comments

Comments
 (0)