diff --git a/phpmon/Common/Core/Paths.swift b/phpmon/Common/Core/Paths.swift index 9176650..4c4dfe9 100644 --- a/phpmon/Common/Core/Paths.swift +++ b/phpmon/Common/Core/Paths.swift @@ -15,14 +15,18 @@ public class Paths { public static let shared = Paths() - internal var baseDir : Paths.HomebrewDir + internal var baseDir: Paths.HomebrewDir - private var userName : String + private var userName: String init() { baseDir = App.architecture != "x86_64" ? .opt : .usr userName = String(Shell.pipe("whoami").split(separator: "\n")[0]) } + + public func detectBinaryPaths() { + detectComposerBinary() + } // - MARK: Binaries @@ -42,6 +46,11 @@ public class Paths { return "\(binPath)/php-config" } + // - MARK: Detected Binaries + + /** The path to the Composer binary. Can be in multiple locations, so is detected instead. */ + public static var composer: String? = nil + // - MARK: Paths public static var whoami: String { @@ -64,6 +73,21 @@ public class Paths { return "\(shared.baseDir.rawValue)/etc" } + // MARK: - Flexible Binaries + // (these can be in multiple locations, so we scan common places because) + // (PHP Monitor will not use the user's own PATH) + + private func detectComposerBinary() { + if Filesystem.fileExists("/usr/local/bin/composer") { + Paths.composer = "/usr/local/bin/composer" + } else if Filesystem.fileExists("/opt/homebrew/bin/composer") { + Paths.composer = "/opt/homebrew/bin/composer" + } else { + Paths.composer = nil + Log.warn("Composer was not found.") + } + } + // MARK: - Enum public enum HomebrewDir: String { diff --git a/phpmon/Domain/Integrations/Composer/ComposerWindow.swift b/phpmon/Domain/Integrations/Composer/ComposerWindow.swift index c0db2fc..765a80d 100644 --- a/phpmon/Domain/Integrations/Composer/ComposerWindow.swift +++ b/phpmon/Domain/Integrations/Composer/ComposerWindow.swift @@ -23,8 +23,9 @@ class ComposerWindow { self.shouldNotify = notify self.completion = completion - if !Filesystem.fileExists("/usr/local/bin/composer") { - presentMissingSymlinkAlert() + Paths.shared.detectBinaryPaths() + if Paths.composer == nil { + presentMissingAlert() return } @@ -41,11 +42,11 @@ class ComposerWindow { DispatchQueue.global(qos: .userInitiated).async { [self] in let task = Shell.user.createTask( - for: "/usr/local/bin/composer global update", requiresPath: true + for: "\(Paths.composer!) global update", requiresPath: true ) DispatchQueue.main.async { - self.window?.addToConsole("/usr/local/bin/composer global update\n") + self.window?.addToConsole("\(Paths.composer!) global update\n") } task.listen( @@ -114,11 +115,12 @@ class ComposerWindow { // MARK: Alert - private func presentMissingSymlinkAlert() { + private func presentMissingAlert() { BetterAlert() .withInformation( title: "alert.composer_missing.title".localized, - subtitle: "alert.composer_missing.info".localized + subtitle: "alert.composer_missing.subtitle".localized, + description: "alert.composer_missing.desc".localized ) .withPrimary(text: "OK") .show() diff --git a/phpmon/Domain/Menu/MainMenu+Startup.swift b/phpmon/Domain/Menu/MainMenu+Startup.swift index 98e4684..5250552 100644 --- a/phpmon/Domain/Menu/MainMenu+Startup.swift +++ b/phpmon/Domain/Menu/MainMenu+Startup.swift @@ -76,6 +76,8 @@ extension MainMenu { Log.info("PHP Monitor has extracted the version number of Valet: \(Valet.shared.version!)") } + Paths.shared.detectBinaryPaths() + Valet.shared.loadConfiguration() Valet.shared.validateVersion() Valet.shared.startPreloadingSites() diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index c55a0d4..4242695 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -182,7 +182,13 @@ // Composer Update "alert.composer_missing.title" = "Composer not found!"; -"alert.composer_missing.info" = "Make sure you have Composer available in `/usr/local/bin/composer`. If Composer is located somewhere else, please create a symlink, like so (make sure to use the correct path):\n\n`ln -s /path/to/composer /usr/local/bin`."; +"alert.composer_missing.subtitle" = "PHP Monitor could not find Composer. Make sure that Composer is installed and try again."; +"alert.composer_missing.desc" = "PHP Monitor assumes that Composer is located in either: + +• `/usr/local/bin/composer` +• `/opt/homebrew/bin/composer` + +Make sure you have it installed in one of these locations, or make a symlink if you have Composer installed somewhere else."; "alert.composer_progress.title" = "Updating global dependencies..."; "alert.composer_progress.info" = "You can see the progress in the terminal output below.";