mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
👌 Move Valet-specific check to Valet class
This commit is contained in:
@ -135,25 +135,6 @@ class ActivePhpInstallation {
|
||||
return (match == nil) ? "⚠️" : "\(value)B"
|
||||
}
|
||||
|
||||
/**
|
||||
Determine if PHP-FPM is configured correctly.
|
||||
|
||||
For PHP 5.6, we'll check if `valet.sock` is included in the main `php-fpm.conf` file, but for more recent
|
||||
versions of PHP, we can just check for the existence of the `valet-fpm.conf` file. If the check here fails,
|
||||
that means that Valet won't work properly.
|
||||
*/
|
||||
func checkPhpFpmStatus() async -> Bool {
|
||||
if self.version.short == "5.6" {
|
||||
// The main PHP config file should contain `valet.sock` and then we're probably fine?
|
||||
let fileName = "\(Paths.etcPath)/php/5.6/php-fpm.conf"
|
||||
return await Shell.pipe("cat \(fileName)").out
|
||||
.contains("valet.sock")
|
||||
}
|
||||
|
||||
// Make sure to check if valet-fpm.conf exists. If it does, we should be fine :)
|
||||
return FileSystem.fileExists("\(Paths.etcPath)/php/\(self.version.short)/php-fpm.d/valet-fpm.conf")
|
||||
}
|
||||
|
||||
// MARK: - Structs
|
||||
|
||||
/**
|
||||
|
@ -36,9 +36,7 @@ class Startup {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
Log.line()
|
||||
Log.info("Skipping \(group.name) checks!")
|
||||
Log.line()
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +132,7 @@ class Startup {
|
||||
descriptionText: "startup.errors.php_opt.desc".localized
|
||||
)
|
||||
]),
|
||||
EnvironmentCheckGroup(name: "valet", condition: { return Valet.shared.installed }, checks: [
|
||||
EnvironmentCheckGroup(name: "valet", condition: { return Valet.installed }, checks: [
|
||||
// =================================================================================
|
||||
// The Valet binary must exist.
|
||||
// =================================================================================
|
||||
|
@ -83,10 +83,6 @@ class Valet {
|
||||
Notify the user about a non-default TLD being set.
|
||||
*/
|
||||
public static func notifyAboutUnsupportedTLD() {
|
||||
if !Valet.shared.installed {
|
||||
return
|
||||
}
|
||||
|
||||
if Valet.shared.config.tld != "test" && Preferences.isEnabled(.warnAboutNonStandardTLD) {
|
||||
Task { @MainActor in
|
||||
BetterAlert().withInformation(
|
||||
@ -129,9 +125,7 @@ class Valet {
|
||||
handle all PHP versions including isolation, it needs to know about all sites.
|
||||
*/
|
||||
public func startPreloadingSites() async {
|
||||
if Valet.shared.installed {
|
||||
await self.reloadSites()
|
||||
}
|
||||
await self.reloadSites()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,6 +215,30 @@ class Valet {
|
||||
.out.contains("Composer detected issues in your platform")
|
||||
}
|
||||
|
||||
/**
|
||||
Determine if PHP-FPM is configured correctly.
|
||||
|
||||
For PHP 5.6, we'll check if `valet.sock` is included in the main `php-fpm.conf` file, but for more recent
|
||||
versions of PHP, we can just check for the existence of the `valet-fpm.conf` file. If the check here fails,
|
||||
that means that Valet won't work properly.
|
||||
*/
|
||||
func phpFpmConfigurationValid() async -> Bool {
|
||||
guard let version = PhpEnv.shared.currentInstall?.version else {
|
||||
Log.info("Cannot check PHP-FPM status: no version of PHP is active")
|
||||
return true
|
||||
}
|
||||
|
||||
if version.short == "5.6" {
|
||||
// The main PHP config file should contain `valet.sock` and then we're probably fine?
|
||||
let fileName = "\(Paths.etcPath)/php/5.6/php-fpm.conf"
|
||||
return await Shell.pipe("cat \(fileName)").out
|
||||
.contains("valet.sock")
|
||||
}
|
||||
|
||||
// Make sure to check if valet-fpm.conf exists. If it does, we should be fine :)
|
||||
return FileSystem.fileExists("\(Paths.etcPath)/php/\(version.short)/php-fpm.d/valet-fpm.conf")
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a count of how many sites are linked and parked.
|
||||
*/
|
||||
|
@ -66,9 +66,7 @@ extension MainMenu {
|
||||
updatePhpVersionInStatusBar()
|
||||
|
||||
// Attempt to find out if PHP-FPM is broken
|
||||
Log.info("Determining broken PHP-FPM...")
|
||||
let installation = PhpEnv.phpInstall
|
||||
installation?.notifyAboutBrokenPhpFpm()
|
||||
|
||||
// Check for other problems
|
||||
WarningManager.shared.evaluateWarnings()
|
||||
@ -86,14 +84,19 @@ extension MainMenu {
|
||||
// Load the global hotkey
|
||||
App.shared.loadGlobalHotkey()
|
||||
|
||||
// Preload sites
|
||||
await Valet.shared.startPreloadingSites()
|
||||
if Valet.installed {
|
||||
// Preload all sites
|
||||
await Valet.shared.startPreloadingSites()
|
||||
|
||||
// After preloading sites, check for PHP-FPM pool conflicts
|
||||
HomebrewDiagnostics.checkForPhpFpmPoolConflicts()
|
||||
// Check if PHP-FPM is broken
|
||||
await Valet.shared.notifyAboutBrokenPhpFpm()
|
||||
|
||||
// A non-default TLD is not officially supported since Valet 3.2.x
|
||||
Valet.notifyAboutUnsupportedTLD()
|
||||
// After preloading sites, check for PHP-FPM pool conflicts
|
||||
HomebrewDiagnostics.checkForPhpFpmPoolConflicts()
|
||||
|
||||
// A non-default TLD is not officially supported since Valet 3.2.x
|
||||
Valet.notifyAboutUnsupportedTLD()
|
||||
}
|
||||
|
||||
// Find out which services are active
|
||||
Log.info("The services manager knows about \(ServicesManager.shared.services.count) services.")
|
||||
|
@ -125,6 +125,6 @@ extension MainMenu {
|
||||
return
|
||||
}
|
||||
|
||||
Task { install.notifyAboutBrokenPhpFpm() }
|
||||
Task { await Valet.shared.notifyAboutBrokenPhpFpm() }
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
extension ActivePhpInstallation {
|
||||
extension Valet {
|
||||
|
||||
/**
|
||||
It is always possible that the system configuration for PHP-FPM has not been set up for Valet.
|
||||
@ -18,24 +18,20 @@ extension ActivePhpInstallation {
|
||||
- Important: The underlying check is `checkPhpFpmStatus`, which can be run multiple times.
|
||||
This method actively presents a modal if said checks fails, so don't call this method too many times.
|
||||
*/
|
||||
public func notifyAboutBrokenPhpFpm() {
|
||||
Task { // Determine whether FPM status is configured correctly in the background
|
||||
let fpmStatusConfiguredCorrectly = await self.checkPhpFpmStatus()
|
||||
public func notifyAboutBrokenPhpFpm() async {
|
||||
if await Valet.shared.phpFpmConfigurationValid() {
|
||||
return
|
||||
}
|
||||
|
||||
if fpmStatusConfiguredCorrectly {
|
||||
return
|
||||
}
|
||||
|
||||
Task { @MainActor in
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.php_fpm_broken.title".localized,
|
||||
subtitle: "alert.php_fpm_broken.info".localized,
|
||||
description: "alert.php_fpm_broken.description".localized
|
||||
)
|
||||
.withPrimary(text: "generic.ok".localized)
|
||||
.show()
|
||||
}
|
||||
Task { @MainActor in
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.php_fpm_broken.title".localized,
|
||||
subtitle: "alert.php_fpm_broken.info".localized,
|
||||
description: "alert.php_fpm_broken.description".localized
|
||||
)
|
||||
.withPrimary(text: "generic.ok".localized)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user