1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2026-03-28 06:50:08 +01:00

♻️ The app can build again (again)!

This commit is contained in:
2025-10-16 11:48:16 +02:00
parent 0e2678c3b7
commit 79a23a2af2
28 changed files with 157 additions and 123 deletions

View File

@@ -11,6 +11,10 @@ import ContainerMacro
@ContainerAccess
class Actions {
var formulae: HomebrewFormulae {
return HomebrewFormulae()
}
// MARK: - Services
public func linkPhp() async {
@@ -18,40 +22,40 @@ class Actions {
}
public func restartPhpFpm() async {
await brew("services restart \(HomebrewFormulae.php)", sudo: HomebrewFormulae.php.elevated)
await brew("services restart \(formulae.php)", sudo: formulae.php.elevated)
}
public func restartPhpFpm(version: String) async {
let formula = (version == PhpEnvironments.brewPhpAlias) ? "php" : "php@\(version)"
await brew("services restart \(formula)", sudo: HomebrewFormulae.php.elevated)
await brew("services restart \(formula)", sudo: formulae.php.elevated)
}
public func restartNginx() async {
await brew("services restart \(HomebrewFormulae.nginx)", sudo: HomebrewFormulae.nginx.elevated)
await brew("services restart \(formulae.nginx)", sudo: formulae.nginx.elevated)
}
public func restartDnsMasq() async {
await brew("services restart \(HomebrewFormulae.dnsmasq)", sudo: HomebrewFormulae.dnsmasq.elevated)
await brew("services restart \(formulae.dnsmasq)", sudo: formulae.dnsmasq.elevated)
}
public func stopValetServices() async {
await brew("services stop \(HomebrewFormulae.php)", sudo: HomebrewFormulae.php.elevated)
await brew("services stop \(HomebrewFormulae.nginx)", sudo: HomebrewFormulae.nginx.elevated)
await brew("services stop \(HomebrewFormulae.dnsmasq)", sudo: HomebrewFormulae.dnsmasq.elevated)
await brew("services stop \(formulae.php)", sudo: formulae.php.elevated)
await brew("services stop \(formulae.nginx)", sudo: formulae.nginx.elevated)
await brew("services stop \(formulae.dnsmasq)", sudo: formulae.dnsmasq.elevated)
}
public func fixHomebrewPermissions() throws {
var servicesCommands = [
"\(paths.brew) services stop \(HomebrewFormulae.nginx)",
"\(paths.brew) services stop \(HomebrewFormulae.dnsmasq)"
"\(paths.brew) services stop \(formulae.nginx)",
"\(paths.brew) services stop \(formulae.dnsmasq)"
]
var cellarCommands = [
"chown -R \(paths.whoami):admin \(paths.cellarPath)/\(HomebrewFormulae.nginx)",
"chown -R \(paths.whoami):admin \(paths.cellarPath)/\(HomebrewFormulae.dnsmasq)"
"chown -R \(paths.whoami):admin \(paths.cellarPath)/\(formulae.nginx)",
"chown -R \(paths.whoami):admin \(paths.cellarPath)/\(formulae.dnsmasq)"
]
PhpEnvironments.shared.availablePhpVersions.forEach { version in
App.shared.container.phpEnvs.availablePhpVersions.forEach { version in
let formula = version == PhpEnvironments.brewPhpAlias
? "php"
: "php@\(version)"
@@ -130,8 +134,8 @@ class Actions {
*/
public func fixMyValet() async {
await InternalSwitcher().performSwitch(to: PhpEnvironments.brewPhpAlias)
await brew("services restart \(HomebrewFormulae.dnsmasq)", sudo: HomebrewFormulae.dnsmasq.elevated)
await brew("services restart \(HomebrewFormulae.php)", sudo: HomebrewFormulae.php.elevated)
await brew("services restart \(HomebrewFormulae.nginx)", sudo: HomebrewFormulae.nginx.elevated)
await brew("services restart \(formulae.dnsmasq)", sudo: formulae.dnsmasq.elevated)
await brew("services restart \(formulae.php)", sudo: formulae.php.elevated)
await brew("services restart \(formulae.nginx)", sudo: formulae.nginx.elevated)
}
}

View File

@@ -137,6 +137,10 @@ class PhpEnvironments {
return InternalSwitcher()
}
public func reloadPhpVersions() async {
_ = await self.detectPhpVersions()
}
/**
Detects which versions of PHP are installed.
This step also detects which versions of PHP are incompatible with the current version of Valet.

View File

@@ -93,7 +93,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
}
func initializeSwitcher() {
self.phpEnvironments = PhpEnvironments.shared
self.phpEnvironments = App.shared.container.phpEnvs
}
static func initializeTestingProfile(_ path: String) {

View File

@@ -108,10 +108,12 @@ class ServicesManager: ObservableObject {
}
var formulae: [HomebrewFormula] {
let f = HomebrewFormulae()
var formulae = [
HomebrewFormulae.php,
HomebrewFormulae.nginx,
HomebrewFormulae.dnsmasq
f.php,
f.nginx,
f.dnsmasq
]
let additionalFormulae = (Preferences.custom.services ?? []).map({ item in

View File

@@ -43,7 +43,7 @@ struct BrewPhpExtension: Hashable, Comparable {
}
var hasAlternativeInstall: Bool {
guard let php = PhpEnvironments.shared.cachedPhpInstallations[self.phpVersion] else {
guard let php = App.shared.container.phpEnvs.cachedPhpInstallations[self.phpVersion] else {
return false
}

View File

@@ -72,7 +72,7 @@ class InstallPhpExtensionCommand: BrewCommand {
}
// Check which version of PHP are now installed
await PhpEnvironments.detectPhpVersions()
await container.phpEnvs.reloadPhpVersions()
// Keep track of the currently installed version
await MainMenu.shared.refreshActiveInstallation()

View File

@@ -75,7 +75,7 @@ class FakeValetInteractor: ValetInteractor {
override func isolate(site: ValetSite, version: String) async throws {
await delay(seconds: delayTime)
site.isolatedPhpVersion = PhpEnvironments.shared.cachedPhpInstallations[version]
site.isolatedPhpVersion = App.shared.container.phpEnvs.cachedPhpInstallations[version]
site.evaluateCompatibility()
}

View File

@@ -106,7 +106,7 @@ extension MainMenu {
}
@objc func disableAllXdebugModes() {
guard let file = PhpEnvironments.shared.getConfigFile(forKey: "xdebug.mode") else {
guard let file = App.shared.container.phpEnvs.getConfigFile(forKey: "xdebug.mode") else {
Log.info("xdebug.mode could not be found in any .ini file, aborting.")
return
}
@@ -125,12 +125,12 @@ extension MainMenu {
@objc func toggleXdebugMode(sender: XdebugMenuItem) {
Log.info("Switching Xdebug to mode: \(sender.mode)")
guard let file = PhpEnvironments.shared.getConfigFile(forKey: "xdebug.mode") else {
guard let file = App.shared.container.phpEnvs.getConfigFile(forKey: "xdebug.mode") else {
return Log.info("xdebug.mode could not be found in any .ini file, aborting.")
}
do {
var modes = Xdebug.activeModes
var modes = Xdebug().activeModes
if let index = modes.firstIndex(of: sender.mode) {
modes.remove(at: index)
@@ -227,7 +227,7 @@ extension MainMenu {
}
@objc func openActiveConfigFolder() {
guard let install = PhpEnvironments.phpInstall else {
guard let install = container.phpEnvs.phpInstall else {
// TODO: Can't open the config if no PHP version is active
return
}
@@ -260,7 +260,7 @@ extension MainMenu {
if silently {
MainMenu.shared.shouldSwitchSilently = true
}
if PhpEnvironments.shared.availablePhpVersions.contains(version) {
if App.shared.container.phpEnvs.availablePhpVersions.contains(version) {
Task { MainMenu.shared.switchToPhpVersion(version) }
} else {
Task {
@@ -279,37 +279,37 @@ extension MainMenu {
MainMenu.shared.shouldSwitchSilently = true
}
if !PhpEnvironments.shared.availablePhpVersions.contains(version) {
if !App.shared.container.phpEnvs.availablePhpVersions.contains(version) {
Log.warn("This PHP version is currently unavailable, not switching!")
return
}
PhpEnvironments.shared.isBusy = true
PhpEnvironments.shared.delegate = self
PhpEnvironments.shared.delegate?.switcherDidStartSwitching(to: version)
App.shared.container.phpEnvs.isBusy = true
App.shared.container.phpEnvs.delegate = self
App.shared.container.phpEnvs.delegate?.switcherDidStartSwitching(to: version)
refreshIcon()
rebuild()
await PhpEnvironments.switcher.performSwitch(to: version)
PhpEnvironments.shared.currentInstall = ActivePhpInstallation()
App.shared.container.phpEnvs.currentInstall = ActivePhpInstallation()
App.shared.handlePhpConfigWatcher()
PhpEnvironments.shared.delegate?.switcherDidCompleteSwitch(to: version)
App.shared.container.phpEnvs.delegate?.switcherDidCompleteSwitch(to: version)
}
@objc func switchToPhpVersion(_ version: String) {
PhpEnvironments.shared.isBusy = true
PhpEnvironments.shared.delegate = self
PhpEnvironments.shared.delegate?.switcherDidStartSwitching(to: version)
App.shared.container.phpEnvs.isBusy = true
App.shared.container.phpEnvs.delegate = self
App.shared.container.phpEnvs.delegate?.switcherDidStartSwitching(to: version)
Task(priority: .userInitiated) { [unowned self] in
refreshIcon()
rebuild()
await PhpEnvironments.switcher.performSwitch(to: version)
PhpEnvironments.shared.currentInstall = ActivePhpInstallation()
App.shared.container.phpEnvs.currentInstall = ActivePhpInstallation()
App.shared.handlePhpConfigWatcher()
PhpEnvironments.shared.delegate?.switcherDidCompleteSwitch(to: version)
App.shared.container.phpEnvs.delegate?.switcherDidCompleteSwitch(to: version)
}
}
@@ -324,18 +324,18 @@ extension MainMenu {
*/
func switchToPhp(_ version: String) async {
Task { @MainActor [self] in
PhpEnvironments.shared.isBusy = true
PhpEnvironments.shared.delegate = self
PhpEnvironments.shared.delegate?.switcherDidStartSwitching(to: version)
App.shared.container.phpEnvs.isBusy = true
App.shared.container.phpEnvs.delegate = self
App.shared.container.phpEnvs.delegate?.switcherDidStartSwitching(to: version)
}
refreshIcon()
rebuild()
await PhpEnvironments.switcher.performSwitch(to: version)
PhpEnvironments.shared.currentInstall = ActivePhpInstallation()
App.shared.container.phpEnvs.currentInstall = ActivePhpInstallation()
App.shared.handlePhpConfigWatcher()
PhpEnvironments.shared.delegate?.switcherDidCompleteSwitch(to: version)
App.shared.container.phpEnvs.delegate?.switcherDidCompleteSwitch(to: version)
}
}

View File

@@ -46,7 +46,7 @@ extension MainMenu {
]
) {
if behaviours.contains(.reloadsPhpInstallation) || behaviours.contains(.setsBusyUI) {
PhpEnvironments.shared.isBusy = true
App.shared.container.phpEnvs.isBusy = true
}
Task(priority: .userInitiated) { [unowned self] in
@@ -59,7 +59,7 @@ extension MainMenu {
Task { @MainActor [self, error] in
if behaviours.contains(.reloadsPhpInstallation) {
PhpEnvironments.shared.currentInstall = ActivePhpInstallation()
App.shared.container.phpEnvs.currentInstall = ActivePhpInstallation()
}
if behaviours.contains(.updatesMenuBarContents) {
@@ -72,7 +72,7 @@ extension MainMenu {
}
if behaviours.contains(.setsBusyUI) {
PhpEnvironments.shared.isBusy = false
App.shared.container.phpEnvs.isBusy = false
}
if error != nil {

View File

@@ -13,9 +13,9 @@ import NVAlert
extension MainMenu {
@MainActor @objc func fixMyValet() {
let previousVersion = PhpEnvironments.phpInstall?.version.short
let previousVersion = container.phpEnvs.phpInstall?.version.short
if !PhpEnvironments.shared.availablePhpVersions.contains(PhpEnvironments.brewPhpAlias) {
if !App.shared.container.phpEnvs.availablePhpVersions.contains(PhpEnvironments.brewPhpAlias) {
presentAlertForMissingFormula()
return
}

View File

@@ -31,7 +31,7 @@ extension MainMenu {
*/
private func onEnvironmentPass() async {
// Determine what the `php` formula is aliased to
await PhpEnvironments.shared.determinePhpAlias()
await App.shared.container.phpEnvs.determinePhpAlias()
// Make sure that broken symlinks are removed ASAP
await BrewDiagnostics.shared.checkForOutdatedPhpInstallationSymlinks()
@@ -54,7 +54,7 @@ extension MainMenu {
await Brew.shared.determineVersion()
// Actually detect the PHP versions
await PhpEnvironments.detectPhpVersions()
await container.phpEnvs.reloadPhpVersions()
// Verify third party taps
// The missing tap(s) will be actionable later
@@ -63,9 +63,6 @@ extension MainMenu {
// Check for an alias conflict
await BrewDiagnostics.shared.checkForCaskConflict()
// Attempt to find out if PHP-FPM is broken
PhpEnvironments.prepare()
// Set up the filesystem watcher for the Homebrew binaries
App.shared.prepareHomebrewWatchers()
@@ -108,7 +105,7 @@ extension MainMenu {
Log.info("The services manager knows about \(ServicesManager.shared.services.count) services.")
// We are ready!
PhpEnvironments.shared.isBusy = false
App.shared.container.phpEnvs.isBusy = false
// Finally!
Log.info("PHP Monitor is ready to serve!")

View File

@@ -18,7 +18,7 @@ extension MainMenu {
nonisolated func switcherDidCompleteSwitch(to version: String) {
// Mark as no longer busy
Task { @MainActor in
PhpEnvironments.shared.isBusy = false
container.phpEnvs.isBusy = false
}
Task { // Things to do after reloading domain list data
@@ -31,7 +31,7 @@ extension MainMenu {
refreshIcon()
rebuild()
if Valet.installed && !PhpEnvironments.shared.validate(version) {
if Valet.installed && !container.phpEnvs.validate(version) {
self.suggestFixMyValet(failed: version)
return
}
@@ -135,7 +135,7 @@ extension MainMenu {
preference: .notifyAboutVersionChange
)
guard PhpEnvironments.phpInstall != nil else {
guard container.phpEnvs.phpInstall != nil else {
Log.err("Cannot notify about version change if PHP is unlinked")
return
}

View File

@@ -10,6 +10,9 @@ import NVAlert
@MainActor
class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate {
var container: Container {
return App.shared.container
}
static let shared = MainMenu()
@@ -78,8 +81,8 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
/** Reloads which PHP versions is currently active. */
@objc func refreshActiveInstallation() {
if !PhpEnvironments.shared.isBusy {
PhpEnvironments.shared.currentInstall = ActivePhpInstallation.load()
if !container.phpEnvs.isBusy {
container.phpEnvs.currentInstall = ActivePhpInstallation.load()
refreshIcon()
rebuild()
} else {
@@ -124,7 +127,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
NVAlert().withInformation(
title: "startup.unsupported_versions_explanation.title".localized,
subtitle: "startup.unsupported_versions_explanation.subtitle".localized(
PhpEnvironments.shared.incompatiblePhpVersions
container.phpEnvs.incompatiblePhpVersions
.map({ version in
return "• PHP \(version)"
})
@@ -156,9 +159,8 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
/** Refreshes the icon with the PHP version. */
@objc func refreshIcon() {
Task { @MainActor [self] in
if PhpEnvironments.shared.isBusy {
if container.phpEnvs.isBusy {
Log.perf("Refreshing icon: currently busy")
setStatusBar(image: NSImage.statusBarIcon)
} else {
@@ -170,7 +172,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
// The dynamic icon has been requested
let long = Preferences.preferences[.fullPhpVersionDynamicIcon] as! Bool
guard let install = PhpEnvironments.phpInstall else {
guard let install = container.phpEnvs.phpInstall else {
setStatusBarImage(version: "???")
return
}

View File

@@ -13,7 +13,7 @@ import Cocoa
extension StatusMenu {
@MainActor func addPhpVersionMenuItems() {
if PhpEnvironments.phpInstall == nil {
if container.phpEnvs.phpInstall == nil {
addItem(HeaderView.asMenuItem(text: "⚠️ " + "mi_no_php_linked".localized, minimumWidth: 280))
addItems([
NSMenuItem.separator(),
@@ -23,29 +23,29 @@ extension StatusMenu {
return
}
if PhpEnvironments.phpInstall!.hasErrorState {
if container.phpEnvs.phpInstall!.hasErrorState {
let brokenMenuItems = ["mi_php_broken_1", "mi_php_broken_2", "mi_php_broken_3", "mi_php_broken_4"]
return addItems(brokenMenuItems.map { NSMenuItem(title: $0.localized) })
}
addItem(HeaderView.asMenuItem(
text: "\("mi_php_version".localized) \(PhpEnvironments.phpInstall!.version.long)",
text: "\("mi_php_version".localized) \(container.phpEnvs.phpInstall!.version.long)",
minimumWidth: 280 // this ensures the menu is at least wide enough not to cause clipping
))
}
@MainActor func addPhpActionMenuItems() {
if PhpEnvironments.shared.isBusy {
if App.shared.container.phpEnvs.isBusy {
addItem(NSMenuItem(title: "mi_busy".localized))
return
}
if PhpEnvironments.shared.availablePhpVersions.isEmpty
&& PhpEnvironments.shared.incompatiblePhpVersions.isEmpty {
if App.shared.container.phpEnvs.availablePhpVersions.isEmpty
&& App.shared.container.phpEnvs.incompatiblePhpVersions.isEmpty {
return
}
if PhpEnvironments.shared.currentInstall == nil {
if App.shared.container.phpEnvs.currentInstall == nil {
return
}
@@ -55,7 +55,7 @@ extension StatusMenu {
}
@MainActor func addServicesManagerMenuItem() {
if PhpEnvironments.shared.isBusy {
if App.shared.container.phpEnvs.isBusy {
return
}
@@ -67,10 +67,10 @@ extension StatusMenu {
@MainActor func addSwitchToPhpMenuItems() {
var shortcutKey = 1
for index in (0..<PhpEnvironments.shared.availablePhpVersions.count) {
for index in (0..<App.shared.container.phpEnvs.availablePhpVersions.count) {
// Get the short and long version
let shortVersion = PhpEnvironments.shared.availablePhpVersions[index]
let longVersion = PhpEnvironments.shared.cachedPhpInstallations[shortVersion]!.versionNumber
let shortVersion = App.shared.container.phpEnvs.availablePhpVersions[index]
let longVersion = App.shared.container.phpEnvs.cachedPhpInstallations[shortVersion]!.versionNumber
let long = Preferences.preferences[.fullPhpVersionDynamicIcon] as! Bool
let versionString = long ? longVersion.text : shortVersion
@@ -78,7 +78,7 @@ extension StatusMenu {
let action = #selector(MainMenu.switchToPhpVersion(sender:))
let brew = (shortVersion == PhpEnvironments.brewPhpAlias) ? "php" : "php@\(shortVersion)"
let isActive = (shortVersion == PhpEnvironments.phpInstall?.version.short)
let isActive = (shortVersion == container.phpEnvs.phpInstall?.version.short)
let menuItem = PhpMenuItem(
title: "\("mi_php_switch".localized) \(versionString) (\(brew))",
@@ -92,11 +92,11 @@ extension StatusMenu {
addItem(menuItem)
}
if !PhpEnvironments.shared.incompatiblePhpVersions.isEmpty {
if !App.shared.container.phpEnvs.incompatiblePhpVersions.isEmpty {
addItem(NSMenuItem.separator())
addItem(NSMenuItem(
title: "⚠️ " + "mi_php_unsupported".localized(
"\(PhpEnvironments.shared.incompatiblePhpVersions.count)"
"\(App.shared.container.phpEnvs.incompatiblePhpVersions.count)"
),
action: #selector(MainMenu.showIncompatiblePhpVersionsAlert)
))
@@ -187,7 +187,7 @@ extension StatusMenu {
),
NSMenuItem(
title: "mi_update_global_composer".localized,
action: PhpEnvironments.shared.isBusy
action: App.shared.container.phpEnvs.isBusy
? nil
: #selector(MainMenu.updateGlobalComposerDependencies),
keyEquivalent: "g",
@@ -200,7 +200,7 @@ extension StatusMenu {
// MARK: - Stats
@MainActor func addStatsMenuItem() {
guard let install = PhpEnvironments.phpInstall else {
guard let install = container.phpEnvs.phpInstall else {
Log.info("Not showing stats menu item if no PHP version is linked.")
return
}
@@ -217,7 +217,7 @@ extension StatusMenu {
// MARK: - Extensions
@MainActor func addExtensionsMenuItems() {
guard let install = PhpEnvironments.phpInstall else {
guard let install = container.phpEnvs.phpInstall else {
Log.info("Not showing extensions menu items if no PHP version is linked.")
return
}
@@ -276,7 +276,9 @@ extension StatusMenu {
// MARK: - Xdebug
@MainActor func addXdebugMenuItem() {
if !Xdebug.enabled {
let xdebug = Xdebug()
if !xdebug.enabled {
addItem(NSMenuItem.separator())
return
}
@@ -284,7 +286,7 @@ extension StatusMenu {
addItems([
NSMenuItem(title: "mi_xdebug_mode".localized, submenu: [
HeaderView.asMenuItem(text: "mi_xdebug_available_modes".localized)
] + Xdebug.asMenuItems() + [
] + xdebug.asMenuItems() + [
HeaderView.asMenuItem(text: "mi_xdebug_actions".localized),
NSMenuItem(title: "mi_xdebug_disable_all".localized,
action: #selector(MainMenu.disableAllXdebugModes))

View File

@@ -8,17 +8,21 @@
import Cocoa
class StatusMenu: NSMenu {
var container: Container {
return App.shared.container
}
// swiftlint:disable cyclomatic_complexity
@MainActor func addMenuItems() {
addPhpVersionMenuItems()
addItem(NSMenuItem.separator())
if PhpEnvironments.phpInstall != nil && Preferences.isEnabled(.displayGlobalVersionSwitcher) {
if container.phpEnvs.phpInstall != nil && Preferences.isEnabled(.displayGlobalVersionSwitcher) {
addPhpActionMenuItems()
addItem(NSMenuItem.separator())
}
if PhpEnvironments.phpInstall != nil && Valet.installed && Preferences.isEnabled(.displayServicesManager) {
if container.phpEnvs.phpInstall != nil && Valet.installed && Preferences.isEnabled(.displayServicesManager) {
addServicesManagerMenuItem()
addItem(NSMenuItem.separator())
}
@@ -28,23 +32,23 @@ class StatusMenu: NSMenu {
addItem(NSMenuItem.separator())
}
if PhpEnvironments.phpInstall != nil && Preferences.isEnabled(.displayPhpConfigFinder) {
if container.phpEnvs.phpInstall != nil && Preferences.isEnabled(.displayPhpConfigFinder) {
addConfigurationMenuItems()
addItem(NSMenuItem.separator())
}
if PhpEnvironments.phpInstall != nil && Preferences.isEnabled(.displayComposerToolkit) {
if container.phpEnvs.phpInstall != nil && Preferences.isEnabled(.displayComposerToolkit) {
addComposerMenuItems()
addItem(NSMenuItem.separator())
}
if !PhpEnvironments.shared.isBusy {
if PhpEnvironments.phpInstall != nil && Preferences.isEnabled(.displayLimitsWidget) {
if !App.shared.container.phpEnvs.isBusy {
if container.phpEnvs.phpInstall != nil && Preferences.isEnabled(.displayLimitsWidget) {
addStatsMenuItem()
addItem(NSMenuItem.separator())
}
if PhpEnvironments.phpInstall != nil && Preferences.isEnabled(.displayExtensions) {
if container.phpEnvs.phpInstall != nil && Preferences.isEnabled(.displayExtensions) {
addExtensionsMenuItems()
NSMenuItem.separator()
@@ -53,11 +57,11 @@ class StatusMenu: NSMenu {
addPhpDoctorMenuItem()
if PhpEnvironments.phpInstall != nil && Preferences.isEnabled(.displayPresets) {
if container.phpEnvs.phpInstall != nil && Preferences.isEnabled(.displayPresets) {
addPresetsMenuItem()
}
if PhpEnvironments.phpInstall != nil && Preferences.isEnabled(.displayMisc) {
if container.phpEnvs.phpInstall != nil && Preferences.isEnabled(.displayMisc) {
addFirstAidAndServicesMenuItems()
}
}

View File

@@ -10,11 +10,14 @@ import Foundation
import NVAlert
class PhpGuard {
var currentVersion: String?
var container: Container {
return App.shared.container
}
init() {
guard let linked = PhpEnvironments.phpInstall else {
guard let linked = container.phpEnvs.phpInstall else {
Log.warn("PHP Guard is unable to determine the current PHP version!")
return
}

View File

@@ -10,6 +10,10 @@ import Foundation
import NVAlert
struct Preset: Codable, Equatable {
var container: Container {
return App.shared.container
}
let name: String
let version: String?
let extensions: [String: Bool]
@@ -89,7 +93,7 @@ struct Preset: Codable, Equatable {
applyConfigurationValue(key: conf.key, value: conf.value ?? "")
}
guard let install = PhpEnvironments.phpInstall else {
guard let install = container.phpEnvs.phpInstall else {
Log.info("Cannot toggle extensions if no PHP version is linked.")
return
}
@@ -130,12 +134,12 @@ struct Preset: Codable, Equatable {
// MARK: - Apply Functionality
private func switchToPhpVersionIfValid() async -> Bool {
if PhpEnvironments.shared.currentInstall?.version.short == self.version! {
if App.shared.container.phpEnvs.currentInstall?.version.short == self.version! {
Log.info("The version we are supposed to switch to is already active.")
return true
}
if PhpEnvironments.shared.availablePhpVersions.first(where: { $0 == self.version }) != nil {
if App.shared.container.phpEnvs.availablePhpVersions.first(where: { $0 == self.version }) != nil {
await MainMenu.shared.switchToPhp(self.version!)
return true
} else {
@@ -145,7 +149,7 @@ struct Preset: Codable, Equatable {
subtitle: "alert.php_switch_unavailable.subtitle".localized(version!),
description: "alert.php_switch_unavailable.info".localized(
version!,
PhpEnvironments.shared.availablePhpVersions.joined(separator: ", ")
App.shared.container.phpEnvs.availablePhpVersions.joined(separator: ", ")
)
).withPrimary(
text: "alert.php_switch_unavailable.ok".localized
@@ -156,7 +160,7 @@ struct Preset: Codable, Equatable {
}
private func applyConfigurationValue(key: String, value: String) {
guard let file = PhpEnvironments.shared.getConfigFile(forKey: key) else {
guard let file = App.shared.container.phpEnvs.getConfigFile(forKey: key) else {
return
}
@@ -217,7 +221,7 @@ struct Preset: Codable, Equatable {
return nil
}
guard let install = PhpEnvironments.phpInstall else {
guard let install = container.phpEnvs.phpInstall else {
return nil
}
@@ -234,7 +238,7 @@ struct Preset: Codable, Equatable {
private func diffExtensions() -> [String: Bool] {
var items: [String: Bool] = [:]
guard let install = PhpEnvironments.phpInstall else {
guard let install = container.phpEnvs.phpInstall else {
fatalError("If no PHP version is linked, diffing extensions is not possible.")
}
@@ -256,7 +260,7 @@ struct Preset: Codable, Equatable {
var items: [String: String?] = [:]
for (key, _) in self.configuration {
guard let file = PhpEnvironments.shared.getConfigFile(forKey: key) else {
guard let file = App.shared.container.phpEnvs.getConfigFile(forKey: key) else {
break
}

View File

@@ -9,6 +9,9 @@
import SwiftUI
struct VersionPopoverView: View {
var container: Container {
return App.shared.container
}
@State var site: ValetSite
@@ -120,7 +123,7 @@ struct VersionPopoverView: View {
if site.isolatedPhpVersion != nil {
information += "alert.composer_php_isolated.desc".localized(
site.isolatedPhpVersion!.versionNumber.short,
PhpEnvironments.phpInstall?.version.short ?? "???"
container.phpEnvs.phpInstall?.version.short ?? "???"
)
information += "\n\n"
}

View File

@@ -27,9 +27,9 @@ extension App {
}
public func onHomebrewPhpModification() async {
// let previous = PhpEnvironments.shared.currentInstall?.version.text
// let previous = App.shared.container.phpEnvs.currentInstall?.version.text
Log.info("Something changed in the Homebrew binary directory...")
await PhpEnvironments.detectPhpVersions()
await container.phpEnvs.reloadPhpVersions()
await MainMenu.shared.refreshActiveInstallation()
//
@@ -37,7 +37,7 @@ extension App {
// Check if the new and previous version of PHP are different
// if so, we can show a notification if needed or alert the user
//
// let new = PhpEnvironments.shared.currentInstall?.version.text
// let new = App.shared.container.phpEnvs.currentInstall?.version.text
//
}
}

View File

@@ -11,6 +11,10 @@ import AppKit
import SwiftUI
class DomainListPhpCell: NSTableCellView, DomainListCellProtocol {
var container: Container {
return App.shared.container
}
var site: ValetSite?
@IBOutlet weak var buttonPhpVersion: NSButton!
@@ -60,11 +64,12 @@ class DomainListPhpCell: NSTableCellView, DomainListCellProtocol {
return []
}
guard let install = PhpEnvironments.phpInstall else {
guard let install = container.phpEnvs.phpInstall else {
return []
}
return PhpEnvironments.shared.validVersions(for: site.preferredPhpVersion).filter({ version in
return container.phpEnvs.validVersions(for: site.preferredPhpVersion)
.filter({ version in
version.short != install.version.short
})
}

View File

@@ -9,10 +9,11 @@
import Cocoa
import Carbon
import SwiftUI
import ContainerMacro
@ContainerAccess
class DomainListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
var container: Container {
return App.shared.container
}
// MARK: - Outlets

View File

@@ -20,7 +20,7 @@ class PhpPreference {
}
internal static func persistToIniFile(key: String, value: String) throws {
if let file = PhpEnvironments.shared.getConfigFile(forKey: key) {
if let file = App.shared.container.phpEnvs.getConfigFile(forKey: key) {
return try file.replace(key: key, value: value)
}

View File

@@ -43,8 +43,8 @@ extension WarningManager {
),
Warning(
command: {
PhpEnvironments.shared.currentInstall?.extensions.contains { $0.name == "xdebug" } ?? false
&& !Xdebug.enabled
App.shared.container.phpEnvs.currentInstall?.extensions.contains { $0.name == "xdebug" } ?? false
&& !Xdebug().enabled
},
name: "Missing configuration file for `xdebug.mode`",
title: "warnings.xdebug_conf_missing.title",
@@ -53,7 +53,7 @@ extension WarningManager {
] },
url: "https://xdebug.org/docs/install#mode",
fix: {
if let php = PhpEnvironments.shared.currentInstall {
if let php = App.shared.container.phpEnvs.currentInstall {
if let xdebug = php.extensions.first(where: { $0.name == "xdebug" }),
let original = try? App.shared.container.filesystem.getStringFromFile(xdebug.file) {
// Append xdebug.mode = off to the file
@@ -63,7 +63,7 @@ extension WarningManager {
)
// Reload extension configuration by updating PHP installation info (reload)
PhpEnvironments.shared.currentInstall = ActivePhpInstallation()
App.shared.container.phpEnvs.currentInstall = ActivePhpInstallation()
// Finally, reload warnings
await self.checkEnvironment()

View File

@@ -19,7 +19,7 @@ struct PhpExtensionManagerView: View {
init() {
self.searchText = ""
self.status = BusyStatus.busy()
let version = PhpEnvironments.shared.currentInstall!.version.short
let version = App.shared.container.phpEnvs.currentInstall!.version.short
self.manager = BrewExtensionsObservable(phpVersion: version)
self.status.busy = false
}
@@ -29,7 +29,7 @@ struct PhpExtensionManagerView: View {
return [manager.phpVersion]
}
return PhpEnvironments.shared.availablePhpVersions
return App.shared.container.phpEnvs.availablePhpVersions
}
var filteredExtensions: [BrewPhpExtension] {

View File

@@ -11,7 +11,7 @@ import SwiftUI
extension PhpVersionManagerView {
public func runCommand(_ command: ModifyPhpVersionCommand) async {
if PhpEnvironments.shared.isBusy {
if App.shared.container.phpEnvs.isBusy {
self.presentErrorAlert(
title: "phpman.action_prevented_busy.title".localized,
description: "phpman.action_prevented_busy.desc".localized,
@@ -79,7 +79,7 @@ extension PhpVersionManagerView {
public func confirmUninstall(_ formula: BrewPhpFormula) async {
// Disallow removal of the currently active versipn
if formula.installedVersion == PhpEnvironments.shared.currentInstall?.version.text {
if formula.installedVersion == App.shared.container.phpEnvs.currentInstall?.version.text {
self.presentErrorAlert(
title: "phpman.uninstall_prevented.title".localized,
description: "phpman.uninstall_prevented.desc".localized,
@@ -133,7 +133,7 @@ extension PhpVersionManagerView {
public func setBusyStatus(_ busy: Bool) {
Task { @MainActor in
PhpEnvironments.shared.isBusy = busy
App.shared.container.phpEnvs.isBusy = busy
self.status.busy = busy
}
}

View File

@@ -13,6 +13,9 @@ struct PhpVersionManagerView: View {
@ObservedObject var formulae: BrewFormulaeObservable
@ObservedObject var status: BusyStatus
var handler: HandlesBrewPhpFormulae
var container: Container {
return App.shared.container
}
init(
formulae: BrewFormulaeObservable,
@@ -71,7 +74,7 @@ struct PhpVersionManagerView: View {
}
// Finally, load PHP information
await PhpEnvironments.detectPhpVersions()
await container.phpEnvs.reloadPhpVersions()
await self.handler.refreshPhpVersions(loadOutdated: false)
await self.handler.refreshPhpVersions(loadOutdated: true)
self.status.busy = false

View File

@@ -38,7 +38,7 @@ struct HomebrewUpgradableTest {
// This config file assumes our PHP alias (`php`) is v8.2
PhpEnvironments.brewPhpAlias = "8.2"
let env = PhpEnvironments.shared
let env = App.shared.container.phpEnvs
env.cachedPhpInstallations = [
"8.1": PhpInstallation("8.1.16"),
"8.2": PhpInstallation("8.2.3"),

View File

@@ -11,7 +11,7 @@ import XCTest
class PhpVersionDetectionTest: XCTestCase {
func test_can_detect_valid_php_versions() async throws {
let outcome = await PhpEnvironments.shared.extractPhpVersions(
let outcome = await App.shared.container.phpEnvs.extractPhpVersions(
from: [
"", // empty lines should be omitted
"php@8.0",