diff --git a/phpmon-tests/Parsers/PhpExtensionTest.swift b/phpmon-tests/Parsers/PhpExtensionTest.swift index 856cfbf..0e38c5e 100644 --- a/phpmon-tests/Parsers/PhpExtensionTest.swift +++ b/phpmon-tests/Parsers/PhpExtensionTest.swift @@ -69,9 +69,4 @@ class PhpExtensionTest: XCTestCase { XCTAssertEqual(PhpExtension.from(filePath: destination.path).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 index e9bb59d..a340a6a 100644 --- a/phpmon/Common/PHP/Extensions/Xdebug.swift +++ b/phpmon/Common/PHP/Extensions/Xdebug.swift @@ -11,20 +11,23 @@ import Foundation class Xdebug { public static var enabled: Bool { - return !self.mode.isEmpty + return PhpEnv.shared.getConfigFile(forKey: "xdebug.mode") != nil } - public static var mode: String { + public static var activeModes: [String] { guard let file = PhpEnv.shared.getConfigFile(forKey: "xdebug.mode") else { - return "" + return [] } - return file.get(for: "xdebug.mode") ?? "" + guard let value = file.get(for: "xdebug.mode") else { + return [] + } + + return value.components(separatedBy: ",").filter { self.modes.contains($0) } } public static var modes: [String] { return [ - "off", "develop", "coverage", "debug", diff --git a/phpmon/Domain/Integrations/Composer/PhpFrameworks.swift b/phpmon/Domain/Integrations/Composer/PhpFrameworks.swift index 158ebbc..fa72d92 100644 --- a/phpmon/Domain/Integrations/Composer/PhpFrameworks.swift +++ b/phpmon/Domain/Integrations/Composer/PhpFrameworks.swift @@ -38,8 +38,6 @@ struct PhpFrameworks { "zendframework/zendframework": "Zend", "zendframework/zend-mvc": "Zend", "typo3/cms-core": "Typo3" - - // TODO (6.0): Handle these in v6.0 // "magento/*": "Magento", // "concrete5/*": "Concrete5", // "contao/*": "Contao", diff --git a/phpmon/Domain/Menu/HeaderView.swift b/phpmon/Domain/Menu/HeaderView.swift index eb245e1..0f7d23c 100644 --- a/phpmon/Domain/Menu/HeaderView.swift +++ b/phpmon/Domain/Menu/HeaderView.swift @@ -13,12 +13,23 @@ class HeaderView: NSView, XibLoadable { @IBOutlet weak var textField: NSTextField! - static func asMenuItem(text: String) -> NSMenuItem { - let view = Self.createFromXib() - view!.textField.stringValue = text.uppercased() + static func asMenuItem( + text: String, + width: Int? = nil + ) -> NSMenuItem { + let view = Self.createFromXib()! + + view.autoresizingMask = [.width, .height] + + view.textField.stringValue = text.uppercased() + view.textField.sizeToFit() + + view.setFrameSize(CGSize(width: view.textField.frame.width + 40, height: view.frame.height)) + let item = NSMenuItem() item.view = view item.target = self + return item } diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index b8572a1..31dcad5 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -242,6 +242,10 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate } } + @objc func disableAllXdebugModes() { + // TODO + } + @objc func toggleXdebugMode(sender: XdebugMenuItem) { Log.info("Switching Xdebug to mode: \(sender.mode)") diff --git a/phpmon/Domain/Menu/StatusMenu.swift b/phpmon/Domain/Menu/StatusMenu.swift index c2c6e0f..333b14f 100644 --- a/phpmon/Domain/Menu/StatusMenu.swift +++ b/phpmon/Domain/Menu/StatusMenu.swift @@ -151,7 +151,9 @@ class StatusMenu: NSMenu { keyEquivalent: "" ) let xdebugModesMenu = NSMenu() - let xdebugMode = Xdebug.mode + let activeModes = Xdebug.activeModes + + xdebugModesMenu.addItem(HeaderView.asMenuItem(text: "Available Modes")) for mode in Xdebug.modes { let item = XdebugMenuItem( @@ -159,11 +161,19 @@ class StatusMenu: NSMenu { action: #selector(MainMenu.toggleXdebugMode(sender:)), keyEquivalent: "" ) - item.state = xdebugMode == mode ? .on : .off + + item.state = activeModes.contains(mode) ? .on : .off item.mode = mode xdebugModesMenu.addItem(item) } + xdebugModesMenu.addItem(HeaderView.asMenuItem(text: "Actions")) + xdebugModesMenu.addItem( + withTitle: "Disable All", + action: #selector(MainMenu.disableAllXdebugModes), + keyEquivalent: "" + ) + for item in xdebugModesMenu.items { item.target = MainMenu.shared } diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 17f0de2..98b6421 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -43,7 +43,7 @@ "mi_other" = "First Aid & Services"; "mi_first_aid" = "First Aid"; -"mi_xdebug_mode" = "Switch Xdebug Mode"; +"mi_xdebug_mode" = "Manage Xdebug"; "mi_composer" = "Composer"; "mi_valet_config" = "Locate Valet Folder (.config/valet)";