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

👌 Cleanup HomebrewDiagnostics

This commit is contained in:
2022-01-28 16:42:46 +01:00
parent a0e5102ca7
commit 0d4a144524
6 changed files with 25 additions and 32 deletions

View File

@ -18,17 +18,4 @@ struct HomebrewService: Decodable, Equatable {
let status: String?
let log_path: String?
let error_log_path: String?
public static let serviceToCheck = "nginx"
public static func servicesCanBeLoaded() -> Bool {
let serviceInfo = try? JSONDecoder().decode(
[HomebrewService].self,
from: Shell.pipe(
"sudo \(Paths.brew) services info \(self.serviceToCheck) --json",
requiresPath: true
).data(using: .utf8)!
)
return serviceInfo != nil
}
}

View File

@ -50,7 +50,7 @@ class Startup {
)
performEnvironmentCheck(
!HomebrewService.servicesCanBeLoaded(),
HomebrewDiagnostics.cannotLoadService(),
messageText: "startup.errors.services_json_error.title".localized,
informativeText: "startup.errors.services_json_error.desc".localized,
breaking: true

View File

@ -10,8 +10,10 @@ import Foundation
struct PhpFrameworks {
/// This list should probably be reversed when checked, because some of these
/// will also require either laravel/framework or symfony/symfony.
/**
This list should probably be reversed when checked, because some of these
will also require either `laravel/framework` or `symfony/symfony`.
*/
public static let DependencyList = [
// COMMON FRAMEWORKS

View File

@ -10,19 +10,6 @@ import Foundation
class HomebrewDiagnostics {
enum Errors: String {
case aliasConflict = "alias_conflict"
}
static let shared = HomebrewDiagnostics()
var errors: [HomebrewDiagnostics.Errors] = []
init() {
if determineAliasConflicts() {
errors.append(.aliasConflict)
}
}
/**
It is possible to have the `shivammathur/php` tap installed, and for the core homebrew information to be outdated.
This will then result in two different aliases claiming to point to the same formula (`php`).
@ -30,7 +17,7 @@ class HomebrewDiagnostics {
This check only needs to be performed if the `shivammathur/php` tap is active.
*/
public func determineAliasConflicts() -> Bool
public static func hasAliasConflict() -> Bool
{
let tapAlias = Shell.pipe("\(Paths.brew) info shivammathur/php/php --json")
@ -67,4 +54,21 @@ class HomebrewDiagnostics {
return false
}
}
/**
In order to see if we support the --json syntax, we'll query nginx.
If the JSON response cannot be parsed, Homebrew is probably out of date.
*/
public static func cannotLoadService(_ name: String = "nginx") -> Bool
{
let serviceInfo = try? JSONDecoder().decode(
[HomebrewService].self,
from: Shell.pipe(
"sudo \(Paths.brew) services info \(name) --json",
requiresPath: true
).data(using: .utf8)!
)
return serviceInfo == nil
}
}

View File

@ -30,7 +30,7 @@ extension MainMenu {
private func onEnvironmentPass() {
PhpEnv.detectPhpVersions()
if HomebrewDiagnostics.shared.errors.contains(.aliasConflict) {
if HomebrewDiagnostics.hasAliasConflict() {
DispatchQueue.main.async {
Alert.notify(
message: "alert.php_alias_conflict.title".localized,

View File

@ -241,7 +241,7 @@ You can do this by running `composer global update` in your terminal. After that
/// 6. Cannot retrieve services
"startup.errors.services_json_error.title" = "Cannot determine services status";
"startup.errors.services_json_error.desc" = "PHP Monitor was unable to check if some of the services are up and running.\n\nPHP Monitor usually queries `brew` using the following command to test if the services can be retrieved: `sudo brew services info nginx --json`. PHP Monitor received an invalid response (no JSON).";
"startup.errors.services_json_error.desc" = "PHP Monitor usually queries `brew` using the following command to test if the services can be retrieved: `sudo brew services info nginx --json`.\n\nPHP Monitor could not interpret this response. This can happen if your Homebrew installation is out of date, in which case Homebrew won't return JSON yet.\n\nYou can usually fix this by running `brew update`.";
/// 7. Multiple services active
"startup.errors.services.title" = "Multiple PHP services are active";