1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

🏗 PHP installation health check

This commit is contained in:
2023-05-06 12:52:10 +02:00
parent 518fb16f23
commit bf610b6c4e
7 changed files with 74 additions and 13 deletions

View File

@ -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
}

View File

@ -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
)
}
}

View File

@ -12,13 +12,17 @@ class PhpInstallation {
var versionNumber: VersionNumber
var isHealthy: Bool = true
/**
In order to determine details about a PHP installation, well simply run `php-config --version`
in the relevant directory.
In order to determine details about a PHP installation,
well 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!")
}
}
}
}

View File

@ -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")

View File

@ -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()

View File

@ -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 {
]
}
}

View File

@ -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 %@.