Skip to content

Commit cc4d14c

Browse files
authored
Merge pull request #358 from tlwt/master
Adding php support
2 parents a72bb0b + f7de1b6 commit cc4d14c

7 files changed

Lines changed: 66 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

7+
## [Unreleased]
8+
9+
### Added
10+
- Support for PHP (Thanks to @tlwt)
11+
712

813

914
## [2.0.0]

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,18 @@ puts "Hello, World!"
437437
```
438438
</details>
439439

440+
<details>
441+
<summary>PHP</summary>
442+
443+
- Requirements: PHP is installed and the correct path is set in the settings.
444+
445+
```php
446+
<?php
447+
echo "Hello, World!";
448+
?>
449+
```
450+
</details>
451+
440452
<details>
441453
<summary>Octave</summary>
442454

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {ReleaseNoteModel} from "./ReleaseNoteModal";
3737
export const languageAliases = ["javascript", "typescript", "bash", "csharp", "wolfram", "nb", "wl", "hs", "py"] as const;
3838
export const canonicalLanguages = ["js", "ts", "cs", "lean", "lua", "python", "cpp", "prolog", "shell", "groovy", "r",
3939
"go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "swift", "racket", "fsharp", "c", "dart",
40-
"ruby", "batch", "sql", "octave", "maxima", "applescript", "zig", "ocaml"] as const;
40+
"ruby", "batch", "sql", "octave", "maxima", "applescript", "zig", "ocaml", "php"] as const;
4141
export const supportedLanguages = [...languageAliases, ...canonicalLanguages] as const;
4242
export type LanguageId = typeof canonicalLanguages[number];
4343

@@ -440,6 +440,12 @@ export default class ExecuteCodePlugin extends Plugin {
440440
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
441441
this.runCodeInShell(transformedCode, out, button, this.settings.ocamlPath, this.settings.ocamlArgs, "ocaml", language, file);
442442
})
443+
} else if (language === "php") {
444+
button.addEventListener("click", async () => {
445+
button.className = runButtonDisabledClass;
446+
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
447+
this.runCodeInShell(transformedCode, out, button, this.settings.phpPath, this.settings.phpArgs, this.settings.phpFileExtension, language, file);
448+
})
443449
}
444450

445451
}

src/settings/Settings.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ export interface ExecutorSettings {
109109
mathematicaArgs: string;
110110
mathematicaFileExtension: string;
111111
mathematicaInject: string;
112+
phpPath: string;
113+
phpArgs: string;
114+
phpFileExtension: string;
115+
phpInject: string;
112116
scalaPath: string;
113117
scalaArgs: string;
114118
scalaFileExtension: string;
@@ -175,6 +179,7 @@ export interface ExecutorSettings {
175179
applescriptInteractive: boolean;
176180
zigInteractive: boolean;
177181
ocamlInteractive: boolean;
182+
phpInteractive: boolean;
178183
}
179184

180185

@@ -319,6 +324,10 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
319324
ocamlPath: "ocaml",
320325
ocamlArgs: "",
321326
ocamlInject: "",
327+
phpPath: "php",
328+
phpArgs: "",
329+
phpFileExtension: "php",
330+
phpInject: "",
322331
jsInteractive: true,
323332
tsInteractive: false,
324333
csInteractive: false,
@@ -352,4 +361,5 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
352361
applescriptInteractive: false,
353362
zigInteractive: false,
354363
ocamlInteractive: false,
364+
phpInteractive: false,
355365
}

src/settings/SettingsTab.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import makeLeanSettings from "./per-lang/makeLeanSettings";
1515
import makeLuaSettings from "./per-lang/makeLuaSettings";
1616
import makeDartSettings from "./per-lang/makeDartSettings";
1717
import makeMathematicaSettings from "./per-lang/makeMathematicaSettings";
18+
import makePhpSettings from "./per-lang/makePhpSettings";
1819
import makePowershellSettings from "./per-lang/makePowershellSettings";
1920
import makePrologSettings from "./per-lang/makePrologSettings";
2021
import makePythonSettings from "./per-lang/makePythonSettings";
@@ -243,6 +244,9 @@ export class SettingsTab extends PluginSettingTab {
243244
// ========== OCaml ============
244245
makeOCamlSettings(this, this.makeContainerFor("ocaml"));
245246

247+
// ========== Ruby ============
248+
makePhpSettings(this, this.makeContainerFor("php"));
249+
246250
this.focusContainer(this.plugin.settings.lastOpenLanguageTab || canonicalLanguages[0]);
247251
}
248252

src/settings/languageDisplayName.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const DISPLAY_NAMES: Record<LanguageId, string> = {
1111
kotlin: "Kotlin",
1212
lua: "Lua",
1313
mathematica: "Mathematica",
14+
php: "PHP",
1415
powershell: "Powershell",
1516
prolog: "Prolog",
1617
python: "Python",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Setting } from "obsidian";
2+
import { SettingsTab } from "../SettingsTab";
3+
4+
export default (tab: SettingsTab, containerEl: HTMLElement) => {
5+
containerEl.createEl('h3', { text: 'PHP Settings' });
6+
new Setting(containerEl)
7+
.setName('php path')
8+
.setDesc("Path to your php installation")
9+
.addText(text => text
10+
.setValue(tab.plugin.settings.phpPath)
11+
.onChange(async (value) => {
12+
const sanitized = tab.sanitizePath(value);
13+
tab.plugin.settings.phpPath = sanitized;
14+
console.log('php path set to: ' + sanitized);
15+
await tab.plugin.saveSettings();
16+
}));
17+
new Setting(containerEl)
18+
.setName('php arguments')
19+
.addText(text => text
20+
.setValue(tab.plugin.settings.phpArgs)
21+
.onChange(async (value) => {
22+
tab.plugin.settings.phpArgs = value;
23+
console.log('php args set to: ' + value);
24+
await tab.plugin.saveSettings();
25+
}));
26+
tab.makeInjectSetting(containerEl, "php");
27+
}

0 commit comments

Comments
 (0)