diff --git a/phpmon/Common/PHP/Extensions/Xdebug.swift b/phpmon/Common/PHP/Extensions/Xdebug.swift index e1201105..e9bb59d7 100644 --- a/phpmon/Common/PHP/Extensions/Xdebug.swift +++ b/phpmon/Common/PHP/Extensions/Xdebug.swift @@ -15,7 +15,11 @@ class Xdebug { } public static var mode: String { - return Command.execute(path: Paths.php, arguments: ["-r", "echo ini_get('xdebug.mode');"]) + guard let file = PhpEnv.shared.getConfigFile(forKey: "xdebug.mode") else { + return "" + } + + return file.get(for: "xdebug.mode") ?? "" } public static var modes: [String] { diff --git a/phpmon/Common/PHP/PHP Version/PhpEnv.swift b/phpmon/Common/PHP/PHP Version/PhpEnv.swift index 54c36f99..4dc3e889 100644 --- a/phpmon/Common/PHP/PHP Version/PhpEnv.swift +++ b/phpmon/Common/PHP/PHP Version/PhpEnv.swift @@ -174,4 +174,14 @@ class PhpEnv { return false } + + /** + Returns the configuration file instance that is used for a specific config value. + You can then use the configuration file instance to change values. + */ + public func getConfigFile(forKey key: String) -> PhpConfigurationFile? { + return PhpEnv.phpInstall.iniFiles + .reversed() + .first(where: { $0.has(key: key) }) + } } diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index 69fb17bf..b8572a11 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -244,6 +244,23 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate @objc func toggleXdebugMode(sender: XdebugMenuItem) { Log.info("Switching Xdebug to mode: \(sender.mode)") + + guard let file = PhpEnv.shared.getConfigFile(forKey: "xdebug.mode") else { + Log.info("xdebug.mode could not be found in any .ini file, aborting.") + return + } + + do { + // Replace the xdebug mode + try file.replace(key: "xdebug.mode", value: sender.mode) + // Refresh the menu + Log.perf("Refreshing menu...") + MainMenu.shared.rebuild() + // Restart PHP-FPM + restartPhpFpm() + } catch { + Log.err("There was an issue replacing `xdebug.mode` in \(file.filePath)") + } } @objc func toggleExtension(sender: ExtensionMenuItem) { diff --git a/phpmon/Domain/Menu/StatusMenu.swift b/phpmon/Domain/Menu/StatusMenu.swift index 1647d518..c2c6e0ff 100644 --- a/phpmon/Domain/Menu/StatusMenu.swift +++ b/phpmon/Domain/Menu/StatusMenu.swift @@ -68,7 +68,7 @@ class StatusMenu: NSMenu { self.addItem(NSMenuItem.separator()) - // self.addXdebugMenuItem() + self.addXdebugMenuItem() self.addFirstAidAndServicesMenuItems() } diff --git a/phpmon/Domain/Watcher/App+ConfigWatch.swift b/phpmon/Domain/Watcher/App+ConfigWatch.swift index 6c57a9bb..bde582fb 100644 --- a/phpmon/Domain/Watcher/App+ConfigWatch.swift +++ b/phpmon/Domain/Watcher/App+ConfigWatch.swift @@ -11,16 +11,16 @@ import Foundation extension App { func startWatcher(_ url: URL) { - Log.info("No watcher currently active...") + Log.perf("No watcher currently active...") self.watcher = PhpConfigWatcher(for: url) self.watcher.didChange = { url in - Log.info("Something has changed in: \(url)") + Log.perf("Something has changed in: \(url)") // Check if the watcher has last updated the menu less than 0.75s ago let distance = self.watcher.lastUpdate?.distance(to: Date().timeIntervalSince1970) if distance == nil || distance != nil && distance! > 0.75 { - Log.info("Refreshing menu...") + Log.perf("Refreshing menu...") MainMenu.shared.reloadPhpMonitorMenuInBackground() self.watcher.lastUpdate = Date().timeIntervalSince1970 } @@ -43,7 +43,7 @@ extension App { if self.watcher.url != url || forceReload { self.watcher.disable() self.watcher = nil - Log.info("Watcher has stopped watching files. Starting new one...") + Log.perf("Watcher has stopped watching files. Starting new one...") self.startWatcher(url) } }