mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
✨ Also show full PHP version in dropdown (#53)
This commit is contained in:
@ -30,7 +30,7 @@ _You may need to update your Valet installation to keep everything working if a
|
|||||||
|
|
||||||
## 🚀 How to install
|
## 🚀 How to install
|
||||||
|
|
||||||
You can install via Homebrew, or may download the latest [release](https://github.com/nicoverbruggen/phpmon/releases).
|
You can install via Homebrew (recommended), or may download the latest release on GitHub.
|
||||||
|
|
||||||
To install via Homebrew, run:
|
To install via Homebrew, run:
|
||||||
|
|
||||||
|
@ -32,6 +32,27 @@ class Actions {
|
|||||||
return versionsOnly
|
return versionsOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
This method extracts the PHP full version number after finding the php installation folders.
|
||||||
|
To be refactored at some later point, I'd like to cache the `PhpInstallation` objects instead of just the version number at some point.
|
||||||
|
*/
|
||||||
|
public static func extractPhpLongVersions() -> [String: String]
|
||||||
|
{
|
||||||
|
var mappedVersions: [String: String] = [:]
|
||||||
|
App.shared.availablePhpVersions.forEach { version in
|
||||||
|
let phpConfigExecutablePath = "\(Paths.optPath)/php@\(version)/bin/php-config"
|
||||||
|
var longVersion = version
|
||||||
|
if Shell.fileExists(phpConfigExecutablePath) {
|
||||||
|
longVersion = Command.execute(
|
||||||
|
path: phpConfigExecutablePath,
|
||||||
|
arguments: ["--version"]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
mappedVersions[version] = longVersion
|
||||||
|
}
|
||||||
|
return mappedVersions
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Extracts valid PHP versions from an array of strings.
|
Extracts valid PHP versions from an array of strings.
|
||||||
This array of strings is usually retrieved from `grep`.
|
This array of strings is usually retrieved from `grep`.
|
||||||
|
@ -49,6 +49,11 @@ class App {
|
|||||||
*/
|
*/
|
||||||
var availablePhpVersions : [String] = []
|
var availablePhpVersions : [String] = []
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cached information about the PHP installations; contains only the full version number at this point.
|
||||||
|
*/
|
||||||
|
var cachedPhpVersionNumbers : [String: String] = [:]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The timer that will periodically fetch the PHP version that is currently active.
|
The timer that will periodically fetch the PHP version that is currently active.
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +42,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
|||||||
*/
|
*/
|
||||||
private func onEnvironmentPass() {
|
private func onEnvironmentPass() {
|
||||||
App.shared.availablePhpVersions = Actions.detectPhpVersions()
|
App.shared.availablePhpVersions = Actions.detectPhpVersions()
|
||||||
|
App.shared.cachedPhpVersionNumbers = Actions.extractPhpLongVersions()
|
||||||
updatePhpVersionInStatusBar()
|
updatePhpVersionInStatusBar()
|
||||||
|
|
||||||
let installation = App.phpInstall!
|
let installation = App.phpInstall!
|
||||||
|
@ -42,15 +42,24 @@ class StatusMenu : NSMenu {
|
|||||||
private func addSwitchToPhpMenuItems() {
|
private func addSwitchToPhpMenuItems() {
|
||||||
var shortcutKey = 1
|
var shortcutKey = 1
|
||||||
for index in (0..<App.shared.availablePhpVersions.count).reversed() {
|
for index in (0..<App.shared.availablePhpVersions.count).reversed() {
|
||||||
let version = App.shared.availablePhpVersions[index]
|
|
||||||
|
// Get the short and long version
|
||||||
|
let shortVersion = App.shared.availablePhpVersions[index]
|
||||||
|
let longVersion = App.shared.cachedPhpVersionNumbers[shortVersion]!
|
||||||
|
|
||||||
|
let long = Preferences.preferences[.fullPhpVersionDynamicIcon] as! Bool
|
||||||
|
let versionString = long ? longVersion : shortVersion
|
||||||
|
|
||||||
let action = #selector(MainMenu.switchToPhpVersion(sender:))
|
let action = #selector(MainMenu.switchToPhpVersion(sender:))
|
||||||
let brew = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
let brew = (shortVersion == App.shared.brewPhpVersion) ? "php" : "php@\(shortVersion)"
|
||||||
let menuItem = PhpMenuItem(
|
let menuItem = PhpMenuItem(
|
||||||
title: "\("mi_php_switch".localized) \(version) (\(brew))",
|
title: "\("mi_php_switch".localized) \(versionString) (\(brew))",
|
||||||
action: (version == App.phpInstall?.version.short) ? nil : action, keyEquivalent: "\(shortcutKey)"
|
action: (shortVersion == App.phpInstall?.version.short) ? nil : action, keyEquivalent: "\(shortcutKey)"
|
||||||
)
|
)
|
||||||
menuItem.version = version
|
|
||||||
|
menuItem.version = shortVersion
|
||||||
shortcutKey = shortcutKey + 1
|
shortcutKey = shortcutKey + 1
|
||||||
|
|
||||||
self.addItem(menuItem)
|
self.addItem(menuItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,7 @@ class PrefsVC: NSViewController {
|
|||||||
@IBAction func toggledFullPhpVersion(_ sender: Any) {
|
@IBAction func toggledFullPhpVersion(_ sender: Any) {
|
||||||
Preferences.update(.fullPhpVersionDynamicIcon, value: buttonDisplayFullPhpVersion.state == .on)
|
Preferences.update(.fullPhpVersionDynamicIcon, value: buttonDisplayFullPhpVersion.state == .on)
|
||||||
MainMenu.shared.refreshIcon()
|
MainMenu.shared.refreshIcon()
|
||||||
|
MainMenu.shared.update()
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func toggledAutoRestartServices(_ sender: Any) {
|
@IBAction func toggledAutoRestartServices(_ sender: Any) {
|
||||||
|
Reference in New Issue
Block a user