diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 2cabb36..64d535f 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -79,6 +79,7 @@ C4205A7E27F4D21800191A39 /* ValetProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4205A7D27F4D21800191A39 /* ValetProxy.swift */; }; C4205A7F27F4D21800191A39 /* ValetProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4205A7D27F4D21800191A39 /* ValetProxy.swift */; }; C4232EE52612526500158FC6 /* Credits.html in Resources */ = {isa = PBXBuildFile; fileRef = C4232EE42612526500158FC6 /* Credits.html */; }; + C42337A3281F19F000459A48 /* Xdebug.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42337A2281F19F000459A48 /* Xdebug.swift */; }; C42759672627662800093CAE /* NSMenuExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42759662627662800093CAE /* NSMenuExtension.swift */; }; C42759682627662800093CAE /* NSMenuExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42759662627662800093CAE /* NSMenuExtension.swift */; }; C42C49DB27C2806F0074ABAC /* MainMenu+FixMyValet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42C49DA27C2806F0074ABAC /* MainMenu+FixMyValet.swift */; }; @@ -311,6 +312,7 @@ C41E87192763D42300161EE0 /* DomainListVC+ContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DomainListVC+ContextMenu.swift"; sourceTree = ""; }; C4205A7D27F4D21800191A39 /* ValetProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValetProxy.swift; sourceTree = ""; }; C4232EE42612526500158FC6 /* Credits.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = Credits.html; sourceTree = ""; }; + C42337A2281F19F000459A48 /* Xdebug.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Xdebug.swift; sourceTree = ""; }; C42759662627662800093CAE /* NSMenuExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSMenuExtension.swift; sourceTree = ""; }; C42C49DA27C2806F0074ABAC /* MainMenu+FixMyValet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MainMenu+FixMyValet.swift"; sourceTree = ""; }; C42CFB1527DFDE7900862737 /* nginx-site.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-site.test"; sourceTree = ""; }; @@ -453,6 +455,7 @@ C48D6C6E279CD29C00F26D7E /* PHP Version */, C4D9ADC2277610E4007277F4 /* Switcher */, C4F30B01278E169B00755FCE /* Homebrew */, + C42337A1281F19DC00459A48 /* Extensions */, C41C1B4A22B019FF00E7CF16 /* ActivePhpInstallation.swift */, C4F2E4392752F7D00020E974 /* PhpInstallation.swift */, C4ACA38E25C754C100060C66 /* PhpExtension.swift */, @@ -604,6 +607,14 @@ path = Domain; sourceTree = ""; }; + C42337A1281F19DC00459A48 /* Extensions */ = { + isa = PBXGroup; + children = ( + C42337A2281F19F000459A48 /* Xdebug.swift */, + ); + path = Extensions; + sourceTree = ""; + }; C44067F327E256560045BD4E /* Cells */ = { isa = PBXGroup; children = ( @@ -1181,6 +1192,7 @@ C4C3ED412783497000AB15D8 /* MainMenu+Startup.swift in Sources */, C4D89BC62783C99400A02B68 /* ComposerJson.swift in Sources */, C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */, + C42337A3281F19F000459A48 /* Xdebug.swift in Sources */, C4B97B75275CF08C003F3378 /* AppDelegate+MenuOutlets.swift in Sources */, C41C02A627E60D7A009F26CB /* SiteScanner.swift in Sources */, C464ADAC275A7A3F003FCD53 /* DomainListWC.swift in Sources */, diff --git a/phpmon-tests/Parsers/PhpExtensionTest.swift b/phpmon-tests/Parsers/PhpExtensionTest.swift index d36682e..777172d 100644 --- a/phpmon-tests/Parsers/PhpExtensionTest.swift +++ b/phpmon-tests/Parsers/PhpExtensionTest.swift @@ -68,5 +68,10 @@ class PhpExtensionTest: XCTestCase { // Make sure if we load the data again, it's disabled XCTAssertEqual(PhpExtension.load(from: destination).first!.enabled, false) } + + func testCanRetrieveXdebugMode() throws { + let value = Command.execute(path: Paths.php, arguments: ["-r", "echo ini_get('xdebug.mode');"]) + XCTAssertEqual(value, "coverage") + } } diff --git a/phpmon/Common/PHP/Extensions/Xdebug.swift b/phpmon/Common/PHP/Extensions/Xdebug.swift new file mode 100644 index 0000000..aeb3538 --- /dev/null +++ b/phpmon/Common/PHP/Extensions/Xdebug.swift @@ -0,0 +1,33 @@ +// +// Xdebug.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 01/05/2022. +// Copyright © 2022 Nico Verbruggen. All rights reserved. +// + +import Foundation + +class Xdebug { + + public static var enabled: Bool { + return !self.mode.isEmpty + } + + public static var mode: String { + return Command.execute(path: Paths.php, arguments: ["-r", "echo ini_get('xdebug.mode');"]) + } + + public static var modes: [String] { + return [ + "off", + "develop", + "coverage", + "debug", + "gcstats", + "profile", + "trace", + ] + } + +} diff --git a/phpmon/Domain/Menu/StatusMenu.swift b/phpmon/Domain/Menu/StatusMenu.swift index 7f18544..224e6d6 100644 --- a/phpmon/Domain/Menu/StatusMenu.swift +++ b/phpmon/Domain/Menu/StatusMenu.swift @@ -89,10 +89,36 @@ class StatusMenu : NSMenu { shortcutKey += 1 } - // Other self.addItem(NSMenuItem.separator()) + + // Xdebug + if Xdebug.enabled { + // TODO: Ensure that the Xdebug mode switcher works + // self.addXdebugMenuItem() + } + + // First Aid & Services self.addFirstAidAndServicesMenuItems() } + + func addXdebugMenuItem() { + let xdebugSwitch = NSMenuItem(title: "mi_xdebug_mode".localized, action: nil, keyEquivalent: "") + let xdebugModesMenu = NSMenu() + let xdebugMode = Xdebug.mode + + for mode in Xdebug.modes { + let item = NSMenuItem(title: mode, action: nil, keyEquivalent: "") + item.state = xdebugMode == mode ? .on : .off + xdebugModesMenu.addItem(item) + } + + for item in xdebugModesMenu.items { + item.target = MainMenu.shared + } + + self.setSubmenu(xdebugModesMenu, for: xdebugSwitch) + self.addItem(xdebugSwitch) + } func addFirstAidAndServicesMenuItems() { let services = NSMenuItem(title: "mi_other".localized, action: nil, keyEquivalent: "") diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 195fc22..481c5a9 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -43,6 +43,8 @@ "mi_other" = "First Aid & Services"; "mi_first_aid" = "First Aid"; +"mi_xdebug_mode" = "Switch Xdebug Mode"; + "mi_composer" = "Composer"; "mi_valet_config" = "Locate Valet Folder (.config/valet)"; "mi_php_config" = "Locate PHP Configuration File (php.ini)";