diff --git a/phpmon/Domain/Core/App.swift b/phpmon/Domain/Core/App.swift index 033a201..bf096c0 100644 --- a/phpmon/Domain/Core/App.swift +++ b/phpmon/Domain/Core/App.swift @@ -43,7 +43,7 @@ class App { */ var brewPhpPackage: HomebrewPackage? = nil { didSet { - self.brewPhpVersion = self.brewPhpPackage!.version + brewPhpVersion = brewPhpPackage!.version } } diff --git a/phpmon/Domain/Core/PhpExtension.swift b/phpmon/Domain/Core/PhpExtension.swift index 076ffe9..1925bae 100644 --- a/phpmon/Domain/Core/PhpExtension.swift +++ b/phpmon/Domain/Core/PhpExtension.swift @@ -62,11 +62,11 @@ class PhpExtension { */ func toggle() { Actions.sed( - file: self.file, - original: self.line, - replacement: self.enabled ? "; \(self.line)" : self.line.replacingOccurrences(of: "; ", with: "") + file: file, + original: line, + replacement: enabled ? "; \(line)" : line.replacingOccurrences(of: "; ", with: "") ) - self.enabled = !self.enabled + enabled = !enabled } // MARK: - Static Methods diff --git a/phpmon/Domain/Core/PhpInstallation.swift b/phpmon/Domain/Core/PhpInstallation.swift index aaa26c0..3c52a1f 100644 --- a/phpmon/Domain/Core/PhpInstallation.swift +++ b/phpmon/Domain/Core/PhpInstallation.swift @@ -16,28 +16,29 @@ class PhpInstallation { // MARK: - Computed var formula: String { - return (self.version.short == App.shared.brewPhpVersion) ? "php" : "php@\(self.version.short)" + return (version.short == App.shared.brewPhpVersion) ? "php" : "php@\(version.short)" } // MARK: - Initializer init() { // Show information about the current version - self.version = Self.getVersion() + version = Self.getVersion() // If an error occurred, exit early - if (self.version.error) { - self.configuration = Configuration() - self.extensions = [] + if (version.error) { + configuration = Configuration() + extensions = [] return } // Load extension information - let path = URL(fileURLWithPath: "\(Paths.etcPath)/php/\(self.version.short)/php.ini") - self.extensions = PhpExtension.load(from: path) + let path = URL(fileURLWithPath: "\(Paths.etcPath)/php/\(version.short)/php.ini") + + extensions = PhpExtension.load(from: path) // Get configuration values - self.configuration = Configuration( + configuration = Configuration( memory_limit: Self.getByteCount(key: "memory_limit"), upload_max_filesize: Self.getByteCount(key: "upload_max_filesize"), post_max_size: Self.getByteCount(key: "post_max_size") diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index 379365e..ba2ac6f 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -161,7 +161,7 @@ class MainMenu: NSObject, NSWindowDelegate { App.shared.currentInstall = PhpInstallation() DispatchQueue.main.async { [self] in - if (App.shared.busy) { + if (App.busy) { setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!) } else { setStatusBarImage(version: App.phpInstall!.version.short) diff --git a/phpmon/Domain/Menu/StatusMenu.swift b/phpmon/Domain/Menu/StatusMenu.swift index 2192647..7969e62 100644 --- a/phpmon/Domain/Menu/StatusMenu.swift +++ b/phpmon/Domain/Menu/StatusMenu.swift @@ -15,18 +15,18 @@ class StatusMenu : NSMenu { if App.phpInstall!.version.error { for message in ["mi_php_broken_1", "mi_php_broken_2", "mi_php_broken_3", "mi_php_broken_4"] { - self.addItem(NSMenuItem(title: message.localized, action: nil, keyEquivalent: "")) + addItem(NSMenuItem(title: message.localized, action: nil, keyEquivalent: "")) } return } let phpVersionText = "\("mi_php_version".localized) \(App.phpInstall!.version.long)" - self.addItem(HeaderView.asMenuItem(text: phpVersionText)) + addItem(HeaderView.asMenuItem(text: phpVersionText)) } func addPhpActionMenuItems() { if App.busy { - self.addItem(NSMenuItem(title: "mi_busy".localized, action: nil, keyEquivalent: "")) + addItem(NSMenuItem(title: "mi_busy".localized, action: nil, keyEquivalent: "")) return } diff --git a/phpmon/Domain/Terminal/Actions.swift b/phpmon/Domain/Terminal/Actions.swift index a181229..956db32 100644 --- a/phpmon/Domain/Terminal/Actions.swift +++ b/phpmon/Domain/Terminal/Actions.swift @@ -75,6 +75,7 @@ class Actions { } let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)" + brew("link \(formula) --overwrite --force") brew("services start \(formula)", sudo: true) } @@ -110,7 +111,7 @@ class Actions { { brew("services restart dnsmasq", sudo: true) - self.detectPhpVersions().forEach { (version) in + detectPhpVersions().forEach { (version) in let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)" brew("unlink php@\(version)") brew("services stop \(formula)") diff --git a/phpmon/Domain/Terminal/Paths.swift b/phpmon/Domain/Terminal/Paths.swift index f8e636e..2b78567 100644 --- a/phpmon/Domain/Terminal/Paths.swift +++ b/phpmon/Domain/Terminal/Paths.swift @@ -23,41 +23,41 @@ class Paths { if (optBrewFound) { // This is usually the case with Homebrew installed on Apple Silicon - self.baseDir = .opt + baseDir = .opt } else if (usrBrewFound) { // This is usually the case with Homebrew installed on Intel (or Rosetta 2) - self.baseDir = .usr + baseDir = .usr } else { // Falling back to default "legacy" Homebrew location (for Intel) print("Seems like we couldn't determine the Homebrew directory.") print("This usually means we're in trouble... (no Homebrew?)") - self.baseDir = .usr + baseDir = .usr } - print("Homebrew directory: \(self.baseDir)") + print("Homebrew directory: \(baseDir)") } // - MARK: Binaries public static var brew: String { - return "\(self.binPath)/brew" + return "\(binPath)/brew" } public static var php: String { - return "\(self.binPath)/php" + return "\(binPath)/php" } // - MARK: Paths public static var binPath: String { - return "\(self.shared.baseDir.rawValue)/bin" + return "\(shared.baseDir.rawValue)/bin" } public static var optPath: String { - return "\(self.shared.baseDir.rawValue)/opt" + return "\(shared.baseDir.rawValue)/opt" } public static var etcPath: String { - return "\(self.shared.baseDir.rawValue)/etc" + return "\(shared.baseDir.rawValue)/etc" } } diff --git a/phpmon/Domain/Terminal/Shell.swift b/phpmon/Domain/Terminal/Shell.swift index fb82968..d67c836 100644 --- a/phpmon/Domain/Terminal/Shell.swift +++ b/phpmon/Domain/Terminal/Shell.swift @@ -29,7 +29,7 @@ class Shell { .init(majorVersion: 10, minorVersion: 15, patchVersion: 0)) // If macOS Mojave is being used, we'll default to /bin/bash - self.shell = at_least_10_15 ? "/bin/sh" : "/bin/bash" + shell = at_least_10_15 ? "/bin/sh" : "/bin/bash" print(at_least_10_15 ? "Detected recent macOS (> 10.15): defaulting to /bin/sh" : "Detected older macOS (< 10.15): so defaulting to /bin/bash") } @@ -47,7 +47,7 @@ class Shell { */ func run(_ command: String) { // Equivalent of piping to /dev/null; don't do anything with the string - _ = self.pipe(command) + _ = pipe(command) } /** diff --git a/phpmon/Domain/Terminal/Startup.swift b/phpmon/Domain/Terminal/Startup.swift index 4e58ff2..d879a58 100644 --- a/phpmon/Domain/Terminal/Startup.swift +++ b/phpmon/Domain/Terminal/Startup.swift @@ -21,23 +21,23 @@ class Startup { */ func checkEnvironment(success: () -> Void, failure: @escaping () -> Void) { - self.failureCallback = failure + failureCallback = failure - self.performEnvironmentCheck( + performEnvironmentCheck( !Shell.fileExists("\(Paths.binPath)/php"), messageText: "startup.errors.php_binary.title".localized, informativeText: "startup.errors.php_binary_desc".localized, breaking: true ) - self.performEnvironmentCheck( + performEnvironmentCheck( !Shell.pipe("ls \(Paths.optPath) | grep php").contains("php"), messageText: "startup.errors.php_opt.title".localized, informativeText: "startup.errors.php_opt.desc".localized, breaking: true ) - self.performEnvironmentCheck( + performEnvironmentCheck( // Older versions of Valet might be located in `/usr/local/bin` regardless of Homebrew prefix !(Shell.fileExists("/usr/local/bin/valet") || Shell.fileExists("/opt/homebrew/bin/valet")), messageText: "startup.errors.valet_executable.title".localized, @@ -45,14 +45,14 @@ class Startup { breaking: true ) - self.performEnvironmentCheck( + performEnvironmentCheck( !Shell.pipe("cat /private/etc/sudoers.d/brew").contains("\(Paths.binPath)/brew"), messageText: "startup.errors.sudoers_brew.title".localized, informativeText: "startup.errors.sudoers_brew.desc".localized, breaking: true ) - self.performEnvironmentCheck( + performEnvironmentCheck( // Older versions of Valet might be located in `/usr/local/bin` regardless of Homebrew prefix !(Shell.pipe("cat /private/etc/sudoers.d/valet").contains("/usr/local/bin/valet") || Shell.pipe("cat /private/etc/sudoers.d/valet").contains("/opt/homebrew/bin/valet")), @@ -62,15 +62,15 @@ class Startup { ) let services = Shell.pipe("\(Paths.brew) services list | grep php") - self.performEnvironmentCheck( + performEnvironmentCheck( (services.countInstances(of: "started") > 1), messageText: "startup.errors.services.title".localized, informativeText: "startup.errors.services.desc".localized, breaking: false ) - if (!self.failed) { - self.determineBrewAliasVersion() + if (!failed) { + determineBrewAliasVersion() success() } } @@ -110,13 +110,13 @@ class Startup { ) { if (!condition) { return } - self.failed = breaking + failed = breaking - DispatchQueue.main.async { + DispatchQueue.main.async { [self] in // Present the information to the user Alert.notify(message: messageText, info: informativeText) // Only breaking issues will throw the extra retry modal - breaking ? self.failureCallback() : () + breaking ? failureCallback() : () } } }