1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-08 04:20:07 +02:00

♻️ Paths now uses static variables instead of methods

This commit is contained in:
2021-01-29 20:39:55 +01:00
parent 2958378411
commit 85ef3ff067
5 changed files with 22 additions and 22 deletions

View File

@ -14,7 +14,7 @@ class Actions {
public static func detectPhpVersions() -> [String] 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") var versions = files.components(separatedBy: "\n")
// Remove all empty strings // Remove all empty strings
@ -83,13 +83,13 @@ class Actions {
public static func openGenericPhpConfigFolder() public static func openGenericPhpConfigFolder()
{ {
let files = [NSURL(fileURLWithPath: "\(Paths.etcPath())/php")]; let files = [NSURL(fileURLWithPath: "\(Paths.etcPath)/php")];
NSWorkspace.shared.activateFileViewerSelecting(files as [URL]) NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
} }
public static func openPhpConfigFolder(version: String) 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]) NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
} }
@ -104,7 +104,7 @@ class Actions {
public static func didFindXdebug(_ version: String) -> Bool public static func didFindXdebug(_ version: String) -> Bool
{ {
return grepContains( return grepContains(
file: "\(Paths.etcPath())/php/\(version)/php.ini", file: "\(Paths.etcPath)/php/\(version)/php.ini",
query: "zend_extension=\"xdebug.so\"" query: "zend_extension=\"xdebug.so\""
) )
} }
@ -112,7 +112,7 @@ class Actions {
public static func didEnableXdebug(_ version: String) -> Bool public static func didEnableXdebug(_ version: String) -> Bool
{ {
return !grepContains( return !grepContains(
file: "\(Paths.etcPath())/php/\(version)/php.ini", file: "\(Paths.etcPath)/php/\(version)/php.ini",
query: "; zend_extension=\"xdebug.so\"" query: "; zend_extension=\"xdebug.so\""
) )
} }
@ -123,12 +123,12 @@ class Actions {
self.didEnableXdebug(version) self.didEnableXdebug(version)
? sed( ? sed(
file: "\(Paths.etcPath())/php/\(version)/php.ini", file: "\(Paths.etcPath)/php/\(version)/php.ini",
original: "zend_extension=\"xdebug.so\"", original: "zend_extension=\"xdebug.so\"",
replacement: "; zend_extension=\"xdebug.so\"" replacement: "; zend_extension=\"xdebug.so\""
) )
: sed( : sed(
file: "\(Paths.etcPath())/php/\(version)/php.ini", file: "\(Paths.etcPath)/php/\(version)/php.ini",
original: "; zend_extension=\"xdebug.so\"", original: "; zend_extension=\"xdebug.so\"",
replacement: "zend_extension=\"xdebug.so\"" replacement: "zend_extension=\"xdebug.so\""
) )
@ -167,7 +167,7 @@ class Actions {
*/ */
private static func brew(_ command: String, sudo: Bool = false) private static func brew(_ command: String, sudo: Bool = false)
{ {
Shell.run("\(sudo ? "sudo " : "")" + "\(Paths.brew()) \(command)") Shell.run("\(sudo ? "sudo " : "")" + "\(Paths.brew) \(command)")
} }
/** /**

View File

@ -24,14 +24,14 @@ class Startup {
self.failureCallback = failure self.failureCallback = failure
self.performEnvironmentCheck( self.performEnvironmentCheck(
!Shell.fileExists("\(Paths.binPath())/php"), !Shell.fileExists("\(Paths.binPath)/php"),
messageText: "startup.errors.php_binary.title".localized, messageText: "startup.errors.php_binary.title".localized,
informativeText: "startup.errors.php_binary_desc".localized, informativeText: "startup.errors.php_binary_desc".localized,
breaking: true breaking: true
) )
self.performEnvironmentCheck( 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, messageText: "startup.errors.php_opt.title".localized,
informativeText: "startup.errors.php_opt.desc".localized, informativeText: "startup.errors.php_opt.desc".localized,
breaking: true breaking: true
@ -45,7 +45,7 @@ class Startup {
) )
self.performEnvironmentCheck( 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, messageText: "startup.errors.sudoers_brew.title".localized,
informativeText: "startup.errors.sudoers_brew.desc".localized, informativeText: "startup.errors.sudoers_brew.desc".localized,
breaking: true breaking: true
@ -58,7 +58,7 @@ class Startup {
breaking: true breaking: true
) )
let services = Shell.pipe("\(Paths.brew()) services list | grep php") let services = Shell.pipe("\(Paths.brew) services list | grep php")
self.performEnvironmentCheck( self.performEnvironmentCheck(
(services.countInstances(of: "started") > 1), (services.countInstances(of: "started") > 1),
messageText: "startup.errors.services.title".localized, 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("PHP Monitor has determined the application has successfully passed all checks.")
print("Determining which version of PHP is aliased to `php` via Homebrew...") 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( App.shared.brewPhpPackage = try! JSONDecoder().decode(
[HomebrewPackage].self, [HomebrewPackage].self,

View File

@ -21,7 +21,7 @@ class PhpInstall {
// MARK: - Initializer // MARK: - Initializer
init() { 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")) { if (version == "" || version.contains("Warning")) {
self.version.short = "💩 BROKEN" self.version.short = "💩 BROKEN"

View File

@ -213,7 +213,7 @@ class MainMenu: NSObject, NSWindowDelegate {
@objc public func openPhpInfo() { @objc public func openPhpInfo() {
self.waitAndExecute({ self.waitAndExecute({
try! "<?php phpinfo();".write(toFile: "/tmp/phpmon_phpinfo.php", atomically: true, encoding: .utf8) try! "<?php phpinfo();".write(toFile: "/tmp/phpmon_phpinfo.php", atomically: true, encoding: .utf8)
Shell.run("\(Paths.binPath())/php-cgi -q /tmp/phpmon_phpinfo.php > /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")!) NSWorkspace.shared.open(URL(string: "file:///private/tmp/phpmon_phpinfo.html")!)
}) })

View File

@ -39,25 +39,25 @@ class Paths {
// - MARK: Binaries // - MARK: Binaries
public static func brew() -> String { public static var brew: String {
return "\(self.binPath())/brew" return "\(self.binPath)/brew"
} }
public static func php() -> String { public static var php: String {
return "\(self.binPath())/php" return "\(self.binPath)/php"
} }
// - MARK: Paths // - MARK: Paths
public static func binPath() -> String { public static var binPath: String {
return "\(self.shared.baseDir.rawValue)/bin" return "\(self.shared.baseDir.rawValue)/bin"
} }
public static func optPath() -> String { public static var optPath: String {
return "\(self.shared.baseDir.rawValue)/opt" return "\(self.shared.baseDir.rawValue)/opt"
} }
public static func etcPath() -> String { public static var etcPath: String {
return "\(self.shared.baseDir.rawValue)/etc" return "\(self.shared.baseDir.rawValue)/etc"
} }
} }