From fcaeaf1f6b8f3652a3842df617fd78ed4c1474e4 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Mon, 18 Aug 2025 11:59:02 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20automatic=20fixes=20for=20tap?= =?UTF-8?q?s,=20xdebug=20configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PHP Doctor/Data/WarningManager.swift | 60 +++++++++++++++++++ .../UI/PhpDoctorWindowController.swift | 2 +- phpmon/en.lproj/Localizable.strings | 11 +++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/phpmon/Modules/PHP Doctor/Data/WarningManager.swift b/phpmon/Modules/PHP Doctor/Data/WarningManager.swift index 3681d91d..8d52c495 100644 --- a/phpmon/Modules/PHP Doctor/Data/WarningManager.swift +++ b/phpmon/Modules/PHP Doctor/Data/WarningManager.swift @@ -59,6 +59,66 @@ class WarningManager: ObservableObject { await WarningManager.shared.checkEnvironment() } ), + Warning( + command: { + PhpEnvironments.shared.currentInstall?.extensions.contains { $0.name == "xdebug" } ?? false + && !Xdebug.enabled + }, + name: "Missing configuration file for `xdebug.mode`", + title: "warnings.xdebug_conf_missing.title", + paragraphs: { return [ + "warnings.xdebug_conf_missing.description" + ] }, + url: "https://xdebug.org/docs/install#mode", + fix: { + if let php = PhpEnvironments.shared.currentInstall { + if let xdebug = php.extensions.first(where: { $0.name == "xdebug" }), + let original = try? FileSystem.getStringFromFile(xdebug.file) { + // Append xdebug.mode = off to the file + try? FileSystem.writeAtomicallyToFile( + xdebug.file, + content: original + "\nxdebug.mode = off" + ) + + // Reload extension configuration by updating PHP installation info (reload) + PhpEnvironments.shared.currentInstall = ActivePhpInstallation() + + // Finally, reload warnings + await WarningManager.shared.checkEnvironment() + } + } + } + ), + Warning( + command: { + !BrewDiagnostics.installedTaps.contains("shivammathur/php") + }, + name: "`shivammathur/php` tap is missing", + title: "warnings.php_tap_missing.title", + paragraphs: { return [ + "warnings.php_tap_missing.description" + ] }, + url: "https://github.com/shivammathur/homebrew-php", + fix: { + await Shell.quiet("brew tap shivammathur/php") + await WarningManager.shared.checkEnvironment() + } + ), + Warning( + command: { + !BrewDiagnostics.installedTaps.contains("shivammathur/extensions") + }, + name: "`shivammathur/extensions` tap is missing", + title: "warnings.extensions_tap_missing.title", + paragraphs: { return [ + "warnings.extensions_tap_missing.description" + ] }, + url: "https://github.com/shivammathur/homebrew-extensions", + fix: { + await Shell.quiet("brew tap shivammathur/extensions") + await WarningManager.shared.checkEnvironment() + } + ), Warning( command: { PhpConfigChecker.shared.check() diff --git a/phpmon/Modules/PHP Doctor/UI/PhpDoctorWindowController.swift b/phpmon/Modules/PHP Doctor/UI/PhpDoctorWindowController.swift index 18a350df..03bf450c 100644 --- a/phpmon/Modules/PHP Doctor/UI/PhpDoctorWindowController.swift +++ b/phpmon/Modules/PHP Doctor/UI/PhpDoctorWindowController.swift @@ -23,7 +23,7 @@ class PhpDoctorWindowController: PMWindowController { guard let window = windowController.window else { return } window.title = "" - window.styleMask = [.titled, .closable, .miniaturizable] + window.styleMask = [.titled, .closable, .miniaturizable, .resizable] window.titlebarAppearsTransparent = true window.delegate = delegate ?? windowController window.contentView = NSHostingView(rootView: PhpDoctorView()) diff --git a/phpmon/en.lproj/Localizable.strings b/phpmon/en.lproj/Localizable.strings index e1cc68bb..f2e36223 100644 --- a/phpmon/en.lproj/Localizable.strings +++ b/phpmon/en.lproj/Localizable.strings @@ -824,7 +824,7 @@ COMMON TROUBLESHOOTING TIPS "warnings.description" = "**PHP Doctor** will suggest improvements to your active system configuration."; "warnings.disclaimer" = "You may choose to hide all recommendations from the PHP Monitor menu in Preferences, but it is recommended that you deal with all actionable items."; "warnings.refresh.button" = "Scan Again"; -"warnings.refresh.button.description" = "Press this button once you've fixed an issue. This will cause PHP Monitor to re-evaluate your environment. If it's really fixed, the recommendation should disappear."; +"warnings.refresh.button.description" = "Press this button if you've manually fixed an issue. This will cause PHP Monitor to re-evaluate your environment. (Automatic fixes do not require you to press this button.)"; "warnings.helper_permissions.title" = "PHP Monitor’s helpers are currently unavailable."; "warnings.helper_permissions.description" = "PHP Monitor comes with various helper scripts. Using these scripts allows you to easily invoke a specific version of PHP without switching the linked PHP version."; @@ -841,6 +841,15 @@ COMMON TROUBLESHOOTING TIPS When files like these are missing, you should switch to the PHP version associated with those files: that may resolve the problem. If this doesn't fix the issue, it's recommended to reinstall the appropriate PHP version(s) via Homebrew again, which should restore the configuration files that are missing. Missing configuration files can be the reason why you get '502 Bad Gateway' errors, even after running Fix My Valet (if you are using Valet)."; +"warnings.xdebug_conf_missing.title" = "Xdebug configuration is incomplete"; +"warnings.xdebug_conf_missing.description" = "You have Xdebug installed, but no mode is specified. Would you like for PHP Monitor to update your configuration? You can also fix this manually."; + +"warnings.php_tap_missing.title" = "`shivammathur/php` tap is missing"; +"warnings.php_tap_missing.description" = "This Homebrew tap is required to install older PHP versions via this app's PHP Version Manager."; + +"warnings.extensions_tap_missing.title" = "`shivammathur/extensions` tap is missing"; +"warnings.extensions_tap_missing.description" = "This Homebrew tap is required to install extensions via this app's PHP Extension Manager."; + "warnings.none" = "There are no recommendations available for you right now. You're all good!"; // ONBOARDING