diff --git a/README.md b/README.md index f862223..3ce4a40 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ _You may need to update your Valet installation to keep everything working if a ## 🚀 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: diff --git a/phpmon/Domain/Core/Actions.swift b/phpmon/Domain/Core/Actions.swift index e2edd93..cd43370 100644 --- a/phpmon/Domain/Core/Actions.swift +++ b/phpmon/Domain/Core/Actions.swift @@ -32,6 +32,27 @@ class Actions { 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. This array of strings is usually retrieved from `grep`. diff --git a/phpmon/Domain/Core/App.swift b/phpmon/Domain/Core/App.swift index 3a48958..e59b351 100644 --- a/phpmon/Domain/Core/App.swift +++ b/phpmon/Domain/Core/App.swift @@ -49,6 +49,11 @@ class App { */ 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. */ diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index 5394c4b..e1e7c31 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -42,6 +42,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { */ private func onEnvironmentPass() { App.shared.availablePhpVersions = Actions.detectPhpVersions() + App.shared.cachedPhpVersionNumbers = Actions.extractPhpLongVersions() updatePhpVersionInStatusBar() let installation = App.phpInstall! diff --git a/phpmon/Domain/Menu/StatusMenu.swift b/phpmon/Domain/Menu/StatusMenu.swift index cebd9a0..b370228 100644 --- a/phpmon/Domain/Menu/StatusMenu.swift +++ b/phpmon/Domain/Menu/StatusMenu.swift @@ -42,15 +42,24 @@ class StatusMenu : NSMenu { private func addSwitchToPhpMenuItems() { var shortcutKey = 1 for index in (0..