mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-09 05:40:07 +01:00
♻️ Separate some of the PHP config logic from the app
This commit is contained in:
@@ -20,7 +20,7 @@ class Actions {
|
||||
// Make sure the aliased version is detected
|
||||
// The user may have `php` installed, but not e.g. `php@8.0`
|
||||
// We should also detect that as a version that is installed
|
||||
let phpAlias = App.shared.brewPhpVersion
|
||||
let phpAlias = PhpSwitcher.shared.brewPhpVersion
|
||||
|
||||
// Avoid inserting a duplicate
|
||||
if (!versionsOnly.contains(phpAlias) && Shell.fileExists("\(Paths.optPath)/php/bin/php")) {
|
||||
@@ -29,7 +29,7 @@ class Actions {
|
||||
|
||||
print("The PHP versions that were detected are: \(versionsOnly)")
|
||||
|
||||
App.shared.availablePhpVersions = versionsOnly
|
||||
PhpSwitcher.shared.availablePhpVersions = versionsOnly
|
||||
Actions.extractPhpLongVersions()
|
||||
|
||||
return versionsOnly
|
||||
@@ -42,11 +42,11 @@ class Actions {
|
||||
public static func extractPhpLongVersions()
|
||||
{
|
||||
var mappedVersions: [String: PhpInstallation] = [:]
|
||||
App.shared.availablePhpVersions.forEach { version in
|
||||
PhpSwitcher.shared.availablePhpVersions.forEach { version in
|
||||
mappedVersions[version] = PhpInstallation(version)
|
||||
}
|
||||
|
||||
App.shared.cachedPhpInstallations = mappedVersions
|
||||
PhpSwitcher.shared.cachedPhpInstallations = mappedVersions
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ class Actions {
|
||||
|
||||
public static func restartPhpFpm()
|
||||
{
|
||||
brew("services restart \(App.phpInstall!.formula)", sudo: true)
|
||||
brew("services restart \(PhpSwitcher.phpInstall.formula)", sudo: true)
|
||||
}
|
||||
|
||||
public static func restartNginx()
|
||||
@@ -97,7 +97,7 @@ class Actions {
|
||||
|
||||
public static func stopAllServices()
|
||||
{
|
||||
brew("services stop \(App.phpInstall!.formula)", sudo: true)
|
||||
brew("services stop \(PhpSwitcher.phpInstall.formula)", sudo: true)
|
||||
brew("services stop nginx", sudo: true)
|
||||
brew("services stop dnsmasq", sudo: true)
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class Actions {
|
||||
group.enter()
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
let formula = (available == App.shared.brewPhpVersion)
|
||||
let formula = (available == PhpSwitcher.shared.brewPhpVersion)
|
||||
? "php" : "php@\(available)"
|
||||
|
||||
brew("unlink \(formula)")
|
||||
@@ -151,7 +151,7 @@ class Actions {
|
||||
print("All versions have been unlinked!")
|
||||
print("Linking the new version!")
|
||||
|
||||
let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
||||
let formula = (version == PhpSwitcher.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
||||
brew("link \(formula) --overwrite --force")
|
||||
brew("services start \(formula)", sudo: true)
|
||||
|
||||
@@ -205,7 +205,7 @@ class Actions {
|
||||
brew("services restart dnsmasq", sudo: true)
|
||||
|
||||
detectPhpVersions().forEach { (version) in
|
||||
let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
||||
let formula = (version == PhpSwitcher.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
||||
brew("unlink php@\(version)")
|
||||
brew("services stop \(formula)")
|
||||
brew("services stop \(formula)", sudo: true)
|
||||
|
||||
@@ -8,13 +8,17 @@
|
||||
import Cocoa
|
||||
import HotKey
|
||||
|
||||
class App {
|
||||
class App: PhpSwitcherDelegate {
|
||||
|
||||
// MARK: Static Vars
|
||||
|
||||
/** The static app instance. Accessible at any time. */
|
||||
static let shared = App()
|
||||
|
||||
init() {
|
||||
PhpSwitcher.shared.delegate = self
|
||||
}
|
||||
|
||||
/** Retrieve the version number from the main info dictionary, Info.plist. */
|
||||
static var version: String {
|
||||
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
|
||||
@@ -22,14 +26,9 @@ class App {
|
||||
return "\(version) (\(build))"
|
||||
}
|
||||
|
||||
/** Information about the currently linked PHP installation. */
|
||||
static var phpInstall: ActivePhpInstallation? {
|
||||
return App.shared.currentInstall
|
||||
}
|
||||
|
||||
/** Whether the app is busy doing something. Used to determine what UI to display. */
|
||||
static var busy: Bool {
|
||||
return App.shared.busy
|
||||
return PhpSwitcher.shared.isBusy
|
||||
}
|
||||
|
||||
// MARK: Variables
|
||||
@@ -43,46 +42,13 @@ class App {
|
||||
/** The window controller of the currently active site list window. */
|
||||
var siteListWindowController: SiteListWC? = nil
|
||||
|
||||
/** Whether the application is busy switching versions. */
|
||||
var busy: Bool = false
|
||||
|
||||
/** The currently active installation of PHP. */
|
||||
var currentInstall: ActivePhpInstallation? = nil {
|
||||
didSet {
|
||||
handlePhpConfigWatcher()
|
||||
}
|
||||
}
|
||||
|
||||
/** All available versions of PHP. */
|
||||
var availablePhpVersions: [String] = []
|
||||
|
||||
/** Cached information about the PHP installations. */
|
||||
var cachedPhpInstallations: [String: PhpInstallation] = [:]
|
||||
|
||||
/** List of detected (installed) applications that PHP Monitor can work with. */
|
||||
var detectedApplications: [Application] = []
|
||||
|
||||
/** Timer that will periodically reload info about the user's PHP installation. */
|
||||
var timer: Timer?
|
||||
|
||||
/** Information we were able to discern from the Homebrew info command (as JSON). */
|
||||
var brewPhpPackage: HomebrewPackage! = nil {
|
||||
didSet {
|
||||
brewPhpVersion = brewPhpPackage!.version
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
We'll technically default to the version in Constants.swift, but the information
|
||||
should always be loaded from Homebrew itself upon startup.
|
||||
*/
|
||||
var brewPhpVersion: String = Constants.LatestStablePhpVersion
|
||||
|
||||
|
||||
// MARK: - Global Hotkey
|
||||
|
||||
/**
|
||||
@@ -112,4 +78,14 @@ class App {
|
||||
The `PhpConfigWatcher` is responsible for watching the `.ini` files and the `.conf.d` folder.
|
||||
*/
|
||||
var watcher: PhpConfigWatcher!
|
||||
|
||||
// MARK: - PhpSwitcherDelegate
|
||||
|
||||
func switcherDidStartSwitching() {
|
||||
}
|
||||
|
||||
func switcherDidCompleteSwitch() {
|
||||
PhpSwitcher.shared.currentInstall = ActivePhpInstallation()
|
||||
handlePhpConfigWatcher()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
*/
|
||||
let sharedShell: Shell
|
||||
|
||||
/**
|
||||
The PhpSwitcher singleton that handles PHP version
|
||||
detection, as well as switching.
|
||||
|
||||
- Note: It is important to initialize the switcher
|
||||
before the `App` singleton, so that the delegate
|
||||
is set correctly.
|
||||
*/
|
||||
let switcher: PhpSwitcher
|
||||
|
||||
/**
|
||||
The App singleton contains information about the state of
|
||||
the application and global variables.
|
||||
@@ -55,6 +65,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
print("Version \(App.version)")
|
||||
print("==================================")
|
||||
self.sharedShell = Shell.user
|
||||
self.switcher = PhpSwitcher.shared
|
||||
self.state = App.shared
|
||||
self.menu = MainMenu.shared
|
||||
self.paths = Paths.shared
|
||||
|
||||
@@ -91,12 +91,12 @@ class Startup {
|
||||
|
||||
let brewPhpAlias = Shell.pipe("\(Paths.brew) info php --json");
|
||||
|
||||
App.shared.brewPhpPackage = try! JSONDecoder().decode(
|
||||
PhpSwitcher.shared.homebrewPackage = try! JSONDecoder().decode(
|
||||
[HomebrewPackage].self,
|
||||
from: brewPhpAlias.data(using: .utf8)!
|
||||
).first!
|
||||
|
||||
print("When on your system, the `php` formula means version \(App.shared.brewPhpVersion)!")
|
||||
print("When on your system, the `php` formula means version \(PhpSwitcher.shared.brewPhpVersion)!")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,12 +46,12 @@ class HomebrewDiagnostics {
|
||||
from: tapAlias.data(using: .utf8)!
|
||||
).first!
|
||||
|
||||
if tapPhp.version != App.shared.brewPhpVersion {
|
||||
if tapPhp.version != PhpSwitcher.shared.brewPhpVersion {
|
||||
print("The `php` formula alias seems to be the different between the tap and core. This could be a problem!")
|
||||
print("Determining whether both of these versions are installed...")
|
||||
|
||||
let bothInstalled = App.shared.availablePhpVersions.contains(tapPhp.version)
|
||||
&& App.shared.availablePhpVersions.contains(App.shared.brewPhpVersion)
|
||||
let bothInstalled = PhpSwitcher.shared.availablePhpVersions.contains(tapPhp.version)
|
||||
&& PhpSwitcher.shared.availablePhpVersions.contains(PhpSwitcher.shared.brewPhpVersion)
|
||||
|
||||
if bothInstalled {
|
||||
print("Both conflicting aliases seem to be installed, warning the user!")
|
||||
|
||||
@@ -57,9 +57,13 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
|
||||
print("Determining broken PHP-FPM...")
|
||||
// Attempt to find out if PHP-FPM is broken
|
||||
let installation = App.phpInstall!
|
||||
let installation = PhpSwitcher.phpInstall
|
||||
installation.notifyAboutBrokenPhpFpm()
|
||||
|
||||
// Set up the config watchers on launch (these are automatically updated via delegate methods if the user switches)
|
||||
print("Setting up watchers...")
|
||||
App.shared.handlePhpConfigWatcher()
|
||||
|
||||
print("Detecting applications...")
|
||||
// Attempt to load list of applications
|
||||
App.shared.detectedApplications = Application.detectPresetApplications()
|
||||
@@ -82,7 +86,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
App.shared.timer = Timer.scheduledTimer(
|
||||
timeInterval: 60,
|
||||
target: self,
|
||||
selector: #selector(updatePhpVersionInStatusBar),
|
||||
selector: #selector(refreshActiveInstallation),
|
||||
userInfo: nil,
|
||||
repeats: true
|
||||
)
|
||||
@@ -181,12 +185,12 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
*/
|
||||
private func waitAndExecute(_ execute: @escaping () -> Void, completion: @escaping () -> Void = {})
|
||||
{
|
||||
App.shared.busy = true
|
||||
PhpSwitcher.shared.isBusy = true
|
||||
setBusyImage()
|
||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||
update()
|
||||
execute()
|
||||
App.shared.busy = false
|
||||
PhpSwitcher.shared.isBusy = false
|
||||
|
||||
DispatchQueue.main.async { [self] in
|
||||
updatePhpVersionInStatusBar()
|
||||
@@ -198,8 +202,12 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
|
||||
// MARK: - User Interface
|
||||
|
||||
@objc func refreshActiveInstallation() {
|
||||
PhpSwitcher.shared.currentInstall = ActivePhpInstallation()
|
||||
updatePhpVersionInStatusBar()
|
||||
}
|
||||
|
||||
@objc func updatePhpVersionInStatusBar() {
|
||||
App.shared.currentInstall = ActivePhpInstallation()
|
||||
refreshIcon()
|
||||
update()
|
||||
}
|
||||
@@ -215,7 +223,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
} else {
|
||||
// The dynamic icon has been requested
|
||||
let long = Preferences.preferences[.fullPhpVersionDynamicIcon] as! Bool
|
||||
setStatusBarImage(version: long ? App.phpInstall!.version.long : App.phpInstall!.version.short)
|
||||
setStatusBarImage(version: long ? PhpSwitcher.phpInstall.version.long : PhpSwitcher.phpInstall.version.short)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,12 +343,12 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
}
|
||||
|
||||
func updateGlobalDependencies(notify: Bool, completion: @escaping (Bool) -> Void) {
|
||||
App.shared.busy = true
|
||||
PhpSwitcher.shared.isBusy = true
|
||||
setBusyImage()
|
||||
self.update()
|
||||
|
||||
let noLongerBusy = {
|
||||
App.shared.busy = false
|
||||
PhpSwitcher.shared.isBusy = false
|
||||
DispatchQueue.main.async { [self] in
|
||||
self.updatePhpVersionInStatusBar()
|
||||
self.update()
|
||||
@@ -411,14 +419,14 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
}
|
||||
|
||||
@objc func openActiveConfigFolder() {
|
||||
if (App.phpInstall!.version.error) {
|
||||
if (PhpSwitcher.phpInstall.version.error) {
|
||||
// php version was not identified
|
||||
Actions.openGenericPhpConfigFolder()
|
||||
return
|
||||
}
|
||||
|
||||
// php version was identified
|
||||
Actions.openPhpConfigFolder(version: App.phpInstall!.version.short)
|
||||
Actions.openPhpConfigFolder(version: PhpSwitcher.phpInstall.version.short)
|
||||
}
|
||||
|
||||
@objc func openGlobalComposerFolder() {
|
||||
@@ -431,7 +439,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
|
||||
@objc func switchToPhpVersion(sender: PhpMenuItem) {
|
||||
setBusyImage()
|
||||
App.shared.busy = true
|
||||
PhpSwitcher.shared.isBusy = true
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||
// Update the PHP version in the status bar
|
||||
@@ -441,8 +449,10 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
update()
|
||||
|
||||
let completion = {
|
||||
PhpSwitcher.shared.delegate?.switcherDidCompleteSwitch()
|
||||
|
||||
// Mark as no longer busy
|
||||
App.shared.busy = false
|
||||
PhpSwitcher.shared.isBusy = false
|
||||
|
||||
// Perform UI updates on main thread
|
||||
DispatchQueue.main.async { [self] in
|
||||
@@ -454,7 +464,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
title: String(format: "notification.version_changed_title".localized, sender.version),
|
||||
subtitle: String(format: "notification.version_changed_desc".localized, sender.version)
|
||||
)
|
||||
App.phpInstall?.notifyAboutBrokenPhpFpm()
|
||||
PhpSwitcher.phpInstall.notifyAboutBrokenPhpFpm()
|
||||
}
|
||||
|
||||
// Run composer updates
|
||||
@@ -482,7 +492,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
// Will cause more issues with Homebrew and is faster
|
||||
Actions.switchToPhpVersion(
|
||||
version: sender.version,
|
||||
availableVersions: App.shared.availablePhpVersions,
|
||||
availableVersions: PhpSwitcher.shared.availablePhpVersions,
|
||||
completed: completion
|
||||
)
|
||||
/* } */
|
||||
|
||||
@@ -9,18 +9,14 @@ import Cocoa
|
||||
|
||||
class StatusMenu : NSMenu {
|
||||
func addPhpVersionMenuItems() {
|
||||
if App.shared.currentInstall == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if App.phpInstall!.version.error {
|
||||
if PhpSwitcher.phpInstall.version.error {
|
||||
for message in ["mi_php_broken_1", "mi_php_broken_2", "mi_php_broken_3", "mi_php_broken_4"] {
|
||||
addItem(NSMenuItem(title: message.localized, action: nil, keyEquivalent: ""))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
let phpVersionText = "\("mi_php_version".localized) \(App.phpInstall!.version.long)"
|
||||
let phpVersionText = "\("mi_php_version".localized) \(PhpSwitcher.phpInstall.version.long)"
|
||||
addItem(HeaderView.asMenuItem(text: phpVersionText))
|
||||
}
|
||||
|
||||
@@ -30,7 +26,7 @@ class StatusMenu : NSMenu {
|
||||
return
|
||||
}
|
||||
|
||||
if App.shared.availablePhpVersions.count == 0 {
|
||||
if PhpSwitcher.shared.availablePhpVersions.count == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -44,14 +40,14 @@ class StatusMenu : NSMenu {
|
||||
|
||||
servicesMenu.addItem(NSMenuItem(title: "mi_help".localized, action: nil, keyEquivalent: ""))
|
||||
|
||||
if !App.shared.availablePhpVersions.contains(App.shared.brewPhpVersion) {
|
||||
if !PhpSwitcher.shared.availablePhpVersions.contains(PhpSwitcher.shared.brewPhpVersion) {
|
||||
servicesMenu.addItem(NSMenuItem(
|
||||
title: "mi_force_load_latest_unavailable".localized(App.shared.brewPhpVersion),
|
||||
title: "mi_force_load_latest_unavailable".localized(PhpSwitcher.shared.brewPhpVersion),
|
||||
action: nil, keyEquivalent: "f"
|
||||
))
|
||||
} else {
|
||||
servicesMenu.addItem(NSMenuItem(
|
||||
title: "mi_force_load_latest".localized(App.shared.brewPhpVersion),
|
||||
title: "mi_force_load_latest".localized(PhpSwitcher.shared.brewPhpVersion),
|
||||
action: #selector(MainMenu.forceRestartLatestPhp), keyEquivalent: "f"))
|
||||
}
|
||||
|
||||
@@ -75,8 +71,6 @@ class StatusMenu : NSMenu {
|
||||
item.target = MainMenu.shared
|
||||
}
|
||||
|
||||
|
||||
|
||||
self.setSubmenu(servicesMenu, for: services)
|
||||
self.addItem(services)
|
||||
}
|
||||
@@ -89,10 +83,6 @@ class StatusMenu : NSMenu {
|
||||
}
|
||||
|
||||
func addPhpConfigurationMenuItems() {
|
||||
if App.shared.currentInstall == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Configuration
|
||||
self.addItem(HeaderView.asMenuItem(text: "mi_configuration".localized))
|
||||
self.addItem(NSMenuItem(title: "mi_php_config".localized, action: #selector(MainMenu.openActiveConfigFolder), keyEquivalent: "c"))
|
||||
@@ -102,13 +92,13 @@ class StatusMenu : NSMenu {
|
||||
self.addItem(NSMenuItem.separator())
|
||||
self.addItem(HeaderView.asMenuItem(text: "mi_composer".localized))
|
||||
self.addItem(NSMenuItem(title: "mi_global_composer".localized, action: #selector(MainMenu.openGlobalComposerFolder), keyEquivalent: "g"))
|
||||
self.addItem(NSMenuItem(title: "mi_update_global_composer".localized, action: App.shared.busy ? nil : #selector(MainMenu.updateComposerDependencies), keyEquivalent: ""))
|
||||
self.addItem(NSMenuItem(title: "mi_update_global_composer".localized, action: PhpSwitcher.shared.isBusy ? nil : #selector(MainMenu.updateComposerDependencies), keyEquivalent: ""))
|
||||
|
||||
if (App.shared.busy) {
|
||||
if (PhpSwitcher.shared.isBusy) {
|
||||
return
|
||||
}
|
||||
|
||||
let stats = App.phpInstall!.limits
|
||||
let stats = PhpSwitcher.phpInstall.limits
|
||||
|
||||
// Stats
|
||||
self.addItem(NSMenuItem.separator())
|
||||
@@ -122,12 +112,12 @@ class StatusMenu : NSMenu {
|
||||
self.addItem(NSMenuItem.separator())
|
||||
self.addItem(HeaderView.asMenuItem(text: "mi_detected_extensions".localized))
|
||||
|
||||
if (App.phpInstall!.extensions.count == 0) {
|
||||
if (PhpSwitcher.phpInstall.extensions.count == 0) {
|
||||
self.addItem(NSMenuItem(title: "mi_no_extensions_detected".localized, action: nil, keyEquivalent: ""))
|
||||
}
|
||||
|
||||
var shortcutKey = 1
|
||||
for phpExtension in App.phpInstall!.extensions {
|
||||
for phpExtension in PhpSwitcher.phpInstall.extensions {
|
||||
self.addExtensionItem(phpExtension, shortcutKey)
|
||||
shortcutKey += 1
|
||||
}
|
||||
@@ -140,20 +130,20 @@ class StatusMenu : NSMenu {
|
||||
|
||||
private func addSwitchToPhpMenuItems() {
|
||||
var shortcutKey = 1
|
||||
for index in (0..<App.shared.availablePhpVersions.count).reversed() {
|
||||
for index in (0..<PhpSwitcher.shared.availablePhpVersions.count).reversed() {
|
||||
|
||||
// Get the short and long version
|
||||
let shortVersion = App.shared.availablePhpVersions[index]
|
||||
let longVersion = App.shared.cachedPhpInstallations[shortVersion]!.longVersion
|
||||
let shortVersion = PhpSwitcher.shared.availablePhpVersions[index]
|
||||
let longVersion = PhpSwitcher.shared.cachedPhpInstallations[shortVersion]!.longVersion
|
||||
|
||||
let long = Preferences.preferences[.fullPhpVersionDynamicIcon] as! Bool
|
||||
let versionString = long ? longVersion : shortVersion
|
||||
|
||||
let action = #selector(MainMenu.switchToPhpVersion(sender:))
|
||||
let brew = (shortVersion == App.shared.brewPhpVersion) ? "php" : "php@\(shortVersion)"
|
||||
let brew = (shortVersion == PhpSwitcher.shared.brewPhpVersion) ? "php" : "php@\(shortVersion)"
|
||||
let menuItem = PhpMenuItem(
|
||||
title: "\("mi_php_switch".localized) \(versionString) (\(brew))",
|
||||
action: (shortVersion == App.phpInstall?.version.short) ? nil : action, keyEquivalent: "\(shortcutKey)"
|
||||
action: (shortVersion == PhpSwitcher.phpInstall.version.short) ? nil : action, keyEquivalent: "\(shortcutKey)"
|
||||
)
|
||||
|
||||
menuItem.version = shortVersion
|
||||
|
||||
@@ -25,7 +25,7 @@ class ActivePhpInstallation {
|
||||
// MARK: - Computed
|
||||
|
||||
var formula: String {
|
||||
return (version.short == App.shared.brewPhpVersion) ? "php" : "php@\(version.short)"
|
||||
return (version.short == PhpSwitcher.shared.brewPhpVersion) ? "php" : "php@\(version.short)"
|
||||
}
|
||||
|
||||
// MARK: - Initializer
|
||||
|
||||
@@ -28,22 +28,19 @@ extension App {
|
||||
}
|
||||
|
||||
func handlePhpConfigWatcher(forceReload: Bool = false) {
|
||||
if self.currentInstall != nil {
|
||||
// Determine the path of the config folder
|
||||
let url = URL(fileURLWithPath: "\(Paths.etcPath)/php/\(self.currentInstall!.version.short)")
|
||||
|
||||
// Watcher needs to be created
|
||||
if self.watcher == nil {
|
||||
startWatcher(url)
|
||||
}
|
||||
|
||||
// Watcher needs to be updated
|
||||
if self.watcher.url != url || forceReload {
|
||||
self.watcher.disable()
|
||||
self.watcher = nil
|
||||
print("Watcher has stopped watching files. Starting new one...")
|
||||
startWatcher(url)
|
||||
}
|
||||
let url = URL(fileURLWithPath: "\(Paths.etcPath)/php/\(PhpSwitcher.phpInstall.version.short)")
|
||||
|
||||
// Watcher needs to be created
|
||||
if self.watcher == nil {
|
||||
startWatcher(url)
|
||||
}
|
||||
|
||||
// Watcher needs to be updated
|
||||
if self.watcher.url != url || forceReload {
|
||||
self.watcher.disable()
|
||||
self.watcher = nil
|
||||
print("Watcher has stopped watching files. Starting new one...")
|
||||
startWatcher(url)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user