From 88850e68d45ac7335f57019cef9bd458d7e03a35 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Wed, 21 Jan 2026 13:02:32 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20PhpEnvironments?= =?UTF-8?q?=20and=20Preferences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PHP/PHP Version/PhpEnvironments.swift | 26 ++++++++++++------- phpmon/Domain/Preferences/Preferences.swift | 7 ++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/phpmon/Common/PHP/PHP Version/PhpEnvironments.swift b/phpmon/Common/PHP/PHP Version/PhpEnvironments.swift index ea69507b..f6930f9c 100644 --- a/phpmon/Common/PHP/PHP Version/PhpEnvironments.swift +++ b/phpmon/Common/PHP/PHP Version/PhpEnvironments.swift @@ -143,14 +143,27 @@ class PhpEnvironments { /** The version that the `php` formula via Brew is aliased to on the current system. - + If you're up to date, `php` will be aliased to the latest version, but that might not be the case since not everyone keeps their software up-to-date. - - As such, we take that information from Homebrew. + + In order for our check to be correct, we query Homebrew locally. */ - static var brewPhpAlias: String? + private static let _brewPhpAlias = Locked(nil) + static var brewPhpAlias: String? { + get { _brewPhpAlias.value } + set { _brewPhpAlias.value = newValue } + } + + /** + Information we were able to discern from the Homebrew info command. + */ + private let _homebrewPackage = Locked(nil) + var homebrewPackage: HomebrewPackage! { + get { _homebrewPackage.value } + set { _homebrewPackage.value = newValue } + } /** It's possible for the alias to be newer than the actual installed version of PHP. @@ -193,11 +206,6 @@ class PhpEnvironments { } } - /** - Information we were able to discern from the Homebrew info command. - */ - var homebrewPackage: HomebrewPackage! = nil - // MARK: - Methods /** diff --git a/phpmon/Domain/Preferences/Preferences.swift b/phpmon/Domain/Preferences/Preferences.swift index 240a8c4d..afdcc485 100644 --- a/phpmon/Domain/Preferences/Preferences.swift +++ b/phpmon/Domain/Preferences/Preferences.swift @@ -11,18 +11,23 @@ import Foundation class Preferences { var container: Container + // MARK - Preferences + var customPreferences: CustomPrefs { get { _customPreferences.value } set { _customPreferences.value = newValue } } - private let _customPreferences: Locked var cachedPreferences: [PreferenceName: Any?] { get { _cachedPreferences.value } set { _cachedPreferences.value = newValue } } + + private let _customPreferences: Locked private let _cachedPreferences: Locked<[PreferenceName: Any?]> + // MARK - Initialization + public init(container: Container) { self.container = container Preferences.handleFirstTimeLaunch()