diff --git a/phpmon/Common/Command/CommandProtocol.swift b/phpmon/Common/Command/CommandProtocol.swift index 9784ae8..0fe4a79 100644 --- a/phpmon/Common/Command/CommandProtocol.swift +++ b/phpmon/Common/Command/CommandProtocol.swift @@ -16,7 +16,26 @@ protocol CommandProtocol { - Parameter path: The path of the command or program to invoke. - Parameter arguments: A list of arguments that are passed on. - Parameter trimNewlines: Removes empty new line output. + - Parameter withStandardError: Outputs standard error output to the same string output as well. */ - func execute(path: String, arguments: [String], trimNewlines: Bool) -> String + func execute( + path: String, + arguments: [String], + trimNewlines: Bool, + withStandardError: Bool + ) -> String + + /** + Immediately executes a command. + + - Parameter path: The path of the command or program to invoke. + - Parameter arguments: A list of arguments that are passed on. + - Parameter trimNewlines: Removes empty new line output. + */ + func execute( + path: String, + arguments: [String], + trimNewlines: Bool + ) -> String } diff --git a/phpmon/Common/Command/RealCommand.swift b/phpmon/Common/Command/RealCommand.swift index 36cde64..11be535 100644 --- a/phpmon/Common/Command/RealCommand.swift +++ b/phpmon/Common/Command/RealCommand.swift @@ -9,13 +9,23 @@ import Cocoa public class RealCommand: CommandProtocol { - public func execute(path: String, arguments: [String], trimNewlines: Bool = false) -> String { + public func execute( + path: String, + arguments: [String], + trimNewlines: Bool, + withStandardError: Bool + ) -> String { let task = Process() task.launchPath = path task.arguments = arguments let pipe = Pipe() task.standardOutput = pipe + + if withStandardError { + task.standardError = pipe + } + task.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() @@ -30,4 +40,17 @@ public class RealCommand: CommandProtocol { return output } + public func execute( + path: String, + arguments: [String], + trimNewlines: Bool = false + ) -> String { + self.execute( + path: path, + arguments: arguments, + trimNewlines: trimNewlines, + withStandardError: false + ) + } + } diff --git a/phpmon/Common/PHP/PhpInstallation.swift b/phpmon/Common/PHP/PhpInstallation.swift index 4b19881..0eb0126 100644 --- a/phpmon/Common/PHP/PhpInstallation.swift +++ b/phpmon/Common/PHP/PhpInstallation.swift @@ -12,13 +12,17 @@ class PhpInstallation { var versionNumber: VersionNumber + var isHealthy: Bool = true + /** - In order to determine details about a PHP installation, we’ll simply run `php-config --version` - in the relevant directory. + In order to determine details about a PHP installation, + we’ll simply run `php-config --version` in the relevant directory. */ init(_ version: String) { - let phpConfigExecutablePath = "\(Paths.optPath)/php@\(version)/bin/php-config" + + let phpExecutablePath = "\(Paths.optPath)/php@\(version)/bin/php" + self.versionNumber = VersionNumber.make(from: version)! if FileSystem.fileExists(phpConfigExecutablePath) { @@ -32,6 +36,19 @@ class PhpInstallation { // If so, the app SHOULD crash, so that the users report what's up. self.versionNumber = try! VersionNumber.parse(longVersionString) } - } + if FileSystem.fileExists(phpExecutablePath) { + let testCommand = Command.execute( + path: phpExecutablePath, + arguments: ["-v"], + trimNewlines: false, + withStandardError: true + ).trimmingCharacters(in: .whitespacesAndNewlines) + + if testCommand.contains("Library not loaded") { + self.isHealthy = false + Log.err("The PHP installation of \(self.versionNumber.short) is not healthy!") + } + } + } } diff --git a/phpmon/Common/Testables/TestableCommand.swift b/phpmon/Common/Testables/TestableCommand.swift index b7e8503..a3679db 100644 --- a/phpmon/Common/Testables/TestableCommand.swift +++ b/phpmon/Common/Testables/TestableCommand.swift @@ -19,6 +19,10 @@ class TestableCommand: CommandProtocol { self.execute(path: path, arguments: arguments, trimNewlines: false) } + public func execute(path: String, arguments: [String], trimNewlines: Bool, withStandardError: Bool) -> String { + self.execute(path: path, arguments: arguments, trimNewlines: trimNewlines) + } + public func execute(path: String, arguments: [String], trimNewlines: Bool) -> String { let concatenatedCommand = "\(path) \(arguments.joined(separator: " "))" assert(commands.keys.contains(concatenatedCommand), "Command `\(concatenatedCommand)` not found") diff --git a/phpmon/Domain/Menu/MainMenu+Startup.swift b/phpmon/Domain/Menu/MainMenu+Startup.swift index e38c14c..7515e62 100644 --- a/phpmon/Domain/Menu/MainMenu+Startup.swift +++ b/phpmon/Domain/Menu/MainMenu+Startup.swift @@ -51,10 +51,10 @@ extension MainMenu { // Attempt to find out more info about Valet if Valet.shared.version != nil { Log.info("PHP Monitor has extracted the version number of Valet: \(Valet.shared.version!.text)") - } - // Validate the version (this will enforce which versions of PHP are supported) - Valet.shared.validateVersion() + // Validate the version (this will enforce which versions of PHP are supported) + Valet.shared.validateVersion() + } // Validate the Homebrew version (determines install/upgrade functionality) await Brew.shared.determineVersion() diff --git a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift index c1f2d75..1cd18e2 100644 --- a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift +++ b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift @@ -133,7 +133,7 @@ struct PhpFormulaeView: View { .padding(.horizontal, 5) VStack(alignment: .leading) { Text(formula.displayName).bold() - Text(formula.homebrewFolder) + // Text(formula.homebrewFolder) if formula.isInstalled && formula.hasUpgrade { Text("\(formula.installedVersion!) installed, \(formula.upgradeVersion!) available.") @@ -350,5 +350,3 @@ class FakeBrewFormulaeHandler: HandlesBrewFormulae { ] } } - - diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 6896b70..d7fbb63 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -106,7 +106,7 @@ "phpman.refresh.button.description" = "You can press the refresh button to check if any updates are available to installed PHP versions."; "phpman.has_updates.description" = "One or more updates are available. (Please note that PHP Monitor will always install or update PHP versions in bulk, so you will always upgrade all installations at once.)"; -"phpman.has_updates.button" = "Update All"; +"phpman.has_updates.button" = "Upgrade All"; "phpman.warnings.unsupported.title" = "Your version of Homebrew may cause issues"; "phpman.warnings.unsupported.desc" = "No functionality is disabled, but some commands may not work as expected. You are currently running Homebrew %@.