From 85ef3ff0670efdde6be03e65d4b95aa8bbd0886d Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Fri, 29 Jan 2021 20:39:55 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Paths=20now=20uses=20stati?= =?UTF-8?q?c=20variables=20instead=20of=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Classes/Commands/Actions.swift | 16 ++++++++-------- phpmon/Classes/Commands/Startup.swift | 10 +++++----- phpmon/Classes/Core/PhpInstall.swift | 2 +- phpmon/Singletons/MainMenu.swift | 2 +- phpmon/Singletons/Paths.swift | 14 +++++++------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/phpmon/Classes/Commands/Actions.swift b/phpmon/Classes/Commands/Actions.swift index 6a5aa9e..f7ced8f 100644 --- a/phpmon/Classes/Commands/Actions.swift +++ b/phpmon/Classes/Commands/Actions.swift @@ -14,7 +14,7 @@ class Actions { public static func detectPhpVersions() -> [String] { - let files = Shell.pipe("ls \(Paths.optPath()) | grep php@") + let files = Shell.pipe("ls \(Paths.optPath) | grep php@") var versions = files.components(separatedBy: "\n") // Remove all empty strings @@ -83,13 +83,13 @@ class Actions { public static func openGenericPhpConfigFolder() { - let files = [NSURL(fileURLWithPath: "\(Paths.etcPath())/php")]; + let files = [NSURL(fileURLWithPath: "\(Paths.etcPath)/php")]; NSWorkspace.shared.activateFileViewerSelecting(files as [URL]) } public static func openPhpConfigFolder(version: String) { - let files = [NSURL(fileURLWithPath: "\(Paths.etcPath())/php/\(version)/php.ini")]; + let files = [NSURL(fileURLWithPath: "\(Paths.etcPath)/php/\(version)/php.ini")]; NSWorkspace.shared.activateFileViewerSelecting(files as [URL]) } @@ -104,7 +104,7 @@ class Actions { public static func didFindXdebug(_ version: String) -> Bool { return grepContains( - file: "\(Paths.etcPath())/php/\(version)/php.ini", + file: "\(Paths.etcPath)/php/\(version)/php.ini", query: "zend_extension=\"xdebug.so\"" ) } @@ -112,7 +112,7 @@ class Actions { public static func didEnableXdebug(_ version: String) -> Bool { return !grepContains( - file: "\(Paths.etcPath())/php/\(version)/php.ini", + file: "\(Paths.etcPath)/php/\(version)/php.ini", query: "; zend_extension=\"xdebug.so\"" ) } @@ -123,12 +123,12 @@ class Actions { self.didEnableXdebug(version) ? sed( - file: "\(Paths.etcPath())/php/\(version)/php.ini", + file: "\(Paths.etcPath)/php/\(version)/php.ini", original: "zend_extension=\"xdebug.so\"", replacement: "; zend_extension=\"xdebug.so\"" ) : sed( - file: "\(Paths.etcPath())/php/\(version)/php.ini", + file: "\(Paths.etcPath)/php/\(version)/php.ini", original: "; zend_extension=\"xdebug.so\"", replacement: "zend_extension=\"xdebug.so\"" ) @@ -167,7 +167,7 @@ class Actions { */ private static func brew(_ command: String, sudo: Bool = false) { - Shell.run("\(sudo ? "sudo " : "")" + "\(Paths.brew()) \(command)") + Shell.run("\(sudo ? "sudo " : "")" + "\(Paths.brew) \(command)") } /** diff --git a/phpmon/Classes/Commands/Startup.swift b/phpmon/Classes/Commands/Startup.swift index f4a4312..b63ec38 100644 --- a/phpmon/Classes/Commands/Startup.swift +++ b/phpmon/Classes/Commands/Startup.swift @@ -24,14 +24,14 @@ class Startup { self.failureCallback = failure self.performEnvironmentCheck( - !Shell.fileExists("\(Paths.binPath())/php"), + !Shell.fileExists("\(Paths.binPath)/php"), messageText: "startup.errors.php_binary.title".localized, informativeText: "startup.errors.php_binary_desc".localized, breaking: true ) self.performEnvironmentCheck( - !Shell.pipe("ls \(Paths.optPath()) | grep php").contains("php"), + !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 @@ -45,7 +45,7 @@ class Startup { ) self.performEnvironmentCheck( - !Shell.pipe("cat /private/etc/sudoers.d/brew").contains("\(Paths.binPath())/brew"), + !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 @@ -58,7 +58,7 @@ class Startup { breaking: true ) - let services = Shell.pipe("\(Paths.brew()) services list | grep php") + let services = Shell.pipe("\(Paths.brew) services list | grep php") self.performEnvironmentCheck( (services.countInstances(of: "started") > 1), messageText: "startup.errors.services.title".localized, @@ -81,7 +81,7 @@ class Startup { print("PHP Monitor has determined the application has successfully passed all checks.") print("Determining which version of PHP is aliased to `php` via Homebrew...") - let brewPhpAlias = Shell.pipe("\(Paths.brew()) info php --json"); + let brewPhpAlias = Shell.pipe("\(Paths.brew) info php --json"); App.shared.brewPhpPackage = try! JSONDecoder().decode( [HomebrewPackage].self, diff --git a/phpmon/Classes/Core/PhpInstall.swift b/phpmon/Classes/Core/PhpInstall.swift index 2e0b060..16b4f5f 100644 --- a/phpmon/Classes/Core/PhpInstall.swift +++ b/phpmon/Classes/Core/PhpInstall.swift @@ -21,7 +21,7 @@ class PhpInstall { // MARK: - Initializer init() { - let version = Command.execute(path: Paths.php(), arguments: ["-r", "print phpversion();"]) + let version = Command.execute(path: Paths.php, arguments: ["-r", "print phpversion();"]) if (version == "" || version.contains("Warning")) { self.version.short = "💩 BROKEN" diff --git a/phpmon/Singletons/MainMenu.swift b/phpmon/Singletons/MainMenu.swift index 87b7358..d8ea0f6 100644 --- a/phpmon/Singletons/MainMenu.swift +++ b/phpmon/Singletons/MainMenu.swift @@ -213,7 +213,7 @@ class MainMenu: NSObject, NSWindowDelegate { @objc public func openPhpInfo() { self.waitAndExecute({ try! " /tmp/phpmon_phpinfo.html") + Shell.run("\(Paths.binPath)/php-cgi -q /tmp/phpmon_phpinfo.php > /tmp/phpmon_phpinfo.html") }, { NSWorkspace.shared.open(URL(string: "file:///private/tmp/phpmon_phpinfo.html")!) }) diff --git a/phpmon/Singletons/Paths.swift b/phpmon/Singletons/Paths.swift index 9adde20..19629b3 100644 --- a/phpmon/Singletons/Paths.swift +++ b/phpmon/Singletons/Paths.swift @@ -39,25 +39,25 @@ class Paths { // - MARK: Binaries - public static func brew() -> String { - return "\(self.binPath())/brew" + public static var brew: String { + return "\(self.binPath)/brew" } - public static func php() -> String { - return "\(self.binPath())/php" + public static var php: String { + return "\(self.binPath)/php" } // - MARK: Paths - public static func binPath() -> String { + public static var binPath: String { return "\(self.shared.baseDir.rawValue)/bin" } - public static func optPath() -> String { + public static var optPath: String { return "\(self.shared.baseDir.rawValue)/opt" } - public static func etcPath() -> String { + public static var etcPath: String { return "\(self.shared.baseDir.rawValue)/etc" } }