mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
📝 Minor tweaks, updated README
This commit is contained in:
26
README.md
26
README.md
@ -1,16 +1,28 @@
|
|||||||
# phpmon
|
# phpmon
|
||||||
|
|
||||||
<img src="./docs/phpmon.png" width="306px" alt="phpmon screenshot"/>
|
phpmon is a macOS utility that runs on your Mac and displays the active PHP version in your status bar.
|
||||||
|
|
||||||
This version of phpmon was developed on and is for **macOS Mojave** with a working Homebrew installation and Laravel Valet 2.2.
|
<img src="./docs/screenshot.png" width="278px" alt="phpmon screenshot"/>
|
||||||
|
|
||||||
phpmon is a macOS utility that runs on your Mac and displays the active PHP version in your status bar. Handy if you're running multiple versions of PHP with Homebrew and wish to see which version is currently linked & active with Laravel Valet.
|
For me, it comes in handy when running multiple versions of PHP with Homebrew and you wish to be able to see at a glance which version is currently linked & active with Laravel Valet, and switch between versions.
|
||||||
|
|
||||||
|
This version of phpmon was developed for:
|
||||||
|
|
||||||
|
* macOS Mojave (10.14)
|
||||||
|
* PHP 7.x with Homebrew 2.x (with support for PHP 5.6 and PHP 7.0 [as well](https://github.com/eXolnet/homebrew-deprecated))
|
||||||
|
* Laravel Valet 2.2
|
||||||
|
|
||||||
|
## Why I built this
|
||||||
|
|
||||||
|
I wanted to be able to see at a glance which version of PHP was linked, and handle dealing with Laravel Valet in a simple app without having to deal with the terminal every time.
|
||||||
|
|
||||||
|
Initially, I had an Alfred workflow for this. But this does the job as well, while also showing me at all times which version of PHP is linked (which is the main benefit over e.g. an Alfred workflow).
|
||||||
|
|
||||||
## How it works
|
## How it works
|
||||||
|
|
||||||
### Version detection
|
### Version detection
|
||||||
|
|
||||||
This utility runs `php -r 'print phpversion();'` in the background periodically and extracts the version number.
|
This utility runs `php -r 'print phpversion();'` in the background periodically (every 60 seconds) and extracts the version number.
|
||||||
|
|
||||||
### Switching PHP versions
|
### Switching PHP versions
|
||||||
|
|
||||||
@ -29,4 +41,8 @@ The utility runs the following commands:
|
|||||||
- Tell Valet to switch to a specific PHP version
|
- Tell Valet to switch to a specific PHP version
|
||||||
- Link the desired version of PHP
|
- Link the desired version of PHP
|
||||||
|
|
||||||
If you want to know more about how this works, I recommend you check out the source code. This app isn't very complicated after all. In the end, this just (conveniently) executes some shell commands.
|
### Want to know more?
|
||||||
|
|
||||||
|
If you want to know more about how this works, I recommend you check out the source code.
|
||||||
|
|
||||||
|
This app isn't very complicated after all. In the end, this just (conveniently) executes some shell commands.
|
||||||
|
BIN
docs/phpmon.png
BIN
docs/phpmon.png
Binary file not shown.
Before Width: | Height: | Size: 317 KiB |
BIN
docs/screenshot.png
Normal file
BIN
docs/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 314 KiB |
@ -19,7 +19,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
// MARK: - Initializer
|
// MARK: - Initializer
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
self.sharedShell = Shell.shared
|
self.sharedShell = Shell.user
|
||||||
self.state = App.shared
|
self.state = App.shared
|
||||||
self.menu = MainMenu.shared
|
self.menu = MainMenu.shared
|
||||||
super.init()
|
super.init()
|
||||||
|
@ -12,7 +12,7 @@ import AppKit
|
|||||||
class Actions {
|
class Actions {
|
||||||
|
|
||||||
public static func detectPhpVersions() -> [String] {
|
public static func detectPhpVersions() -> [String] {
|
||||||
let files = Shell.shared.pipe("ls /usr/local/opt | grep php@")
|
let files = Shell.user.pipe("ls /usr/local/opt | grep php@")
|
||||||
var versions = files.components(separatedBy: "\n")
|
var versions = files.components(separatedBy: "\n")
|
||||||
// Remove all empty strings
|
// Remove all empty strings
|
||||||
versions.removeAll { (string) -> Bool in
|
versions.removeAll { (string) -> Bool in
|
||||||
@ -28,14 +28,14 @@ class Actions {
|
|||||||
|
|
||||||
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
|
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
|
||||||
availableVersions.forEach { (version) in
|
availableVersions.forEach { (version) in
|
||||||
Shell.shared.run("brew unlink php@\(version)")
|
Shell.user.run("brew unlink php@\(version)")
|
||||||
}
|
}
|
||||||
if (availableVersions.contains("7.3")) {
|
if (availableVersions.contains("7.3")) {
|
||||||
Shell.shared.run("brew link php@7.3")
|
Shell.user.run("brew link php@7.3")
|
||||||
if (version == Constants.LatestPhpVersion) {
|
if (version == Constants.LatestPhpVersion) {
|
||||||
Shell.shared.run( "valet use php")
|
Shell.user.run( "valet use php")
|
||||||
} else {
|
} else {
|
||||||
Shell.shared.run("valet use php@\(version)")
|
Shell.user.run("valet use php@\(version)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,31 +13,31 @@ class Startup {
|
|||||||
public static func checkEnvironment()
|
public static func checkEnvironment()
|
||||||
{
|
{
|
||||||
self.presentAlertOnMainThreadIf(
|
self.presentAlertOnMainThreadIf(
|
||||||
!Shell.shared.pipe("which php").contains("/usr/local/bin/php"),
|
!Shell.user.pipe("which php").contains("/usr/local/bin/php"),
|
||||||
messageText: "PHP is not correctly installed",
|
messageText: "PHP is not correctly installed",
|
||||||
informativeText: "You must install PHP via brew. Try running `which php` in Terminal, it should return `/usr/local/bin/php`. The app will not work correctly until you resolve this issue."
|
informativeText: "You must install PHP via brew. Try running `which php` in Terminal, it should return `/usr/local/bin/php`. The app will not work correctly until you resolve this issue."
|
||||||
)
|
)
|
||||||
|
|
||||||
self.presentAlertOnMainThreadIf(
|
self.presentAlertOnMainThreadIf(
|
||||||
!Shell.shared.pipe("ls /usr/local/opt | grep php@7.3").contains("php@7.3"),
|
!Shell.user.pipe("ls /usr/local/opt | grep php@7.3").contains("php@7.3"),
|
||||||
messageText: "PHP 7.3 is not correctly installed",
|
messageText: "PHP 7.3 is not correctly installed",
|
||||||
informativeText: "PHP 7.3 alias was not found in `/usr/local/opt`. The app will not work correctly until you resolve this issue."
|
informativeText: "PHP 7.3 alias was not found in `/usr/local/opt`. The app will not work correctly until you resolve this issue."
|
||||||
)
|
)
|
||||||
|
|
||||||
self.presentAlertOnMainThreadIf(
|
self.presentAlertOnMainThreadIf(
|
||||||
!Shell.shared.pipe("which valet").contains("/usr/local/bin/valet"),
|
!Shell.user.pipe("which valet").contains("/usr/local/bin/valet"),
|
||||||
messageText: "Laravel Valet is not correctly installed",
|
messageText: "Laravel Valet is not correctly installed",
|
||||||
informativeText: "You must install Valet via brew. Try running `which valet` in Terminal, it should return `/usr/local/bin/valet`. The app will not work correctly until you resolve this issue."
|
informativeText: "You must install Valet via brew. Try running `which valet` in Terminal, it should return `/usr/local/bin/valet`. The app will not work correctly until you resolve this issue."
|
||||||
)
|
)
|
||||||
|
|
||||||
self.presentAlertOnMainThreadIf(
|
self.presentAlertOnMainThreadIf(
|
||||||
!Shell.shared.pipe("cat /private/etc/sudoers.d/brew").contains("/usr/local/bin/brew"),
|
!Shell.user.pipe("cat /private/etc/sudoers.d/brew").contains("/usr/local/bin/brew"),
|
||||||
messageText: "Brew has not been added to sudoers.d",
|
messageText: "Brew has not been added to sudoers.d",
|
||||||
informativeText: "You must run `sudo valet trust` to ensure Valet can start and stop services without having to use sudo every time. The app will not work correctly until you resolve this issue."
|
informativeText: "You must run `sudo valet trust` to ensure Valet can start and stop services without having to use sudo every time. The app will not work correctly until you resolve this issue."
|
||||||
)
|
)
|
||||||
|
|
||||||
self.presentAlertOnMainThreadIf(
|
self.presentAlertOnMainThreadIf(
|
||||||
!Shell.shared.pipe("cat /private/etc/sudoers.d/valet").contains("/usr/local/bin/valet"),
|
!Shell.user.pipe("cat /private/etc/sudoers.d/valet").contains("/usr/local/bin/valet"),
|
||||||
messageText: "Valet has not been added to sudoers.d",
|
messageText: "Valet has not been added to sudoers.d",
|
||||||
informativeText: "You must run `sudo valet trust` to ensure Valet can start and stop services without having to use sudo every time. The app will not work correctly until you resolve this issue."
|
informativeText: "You must run `sudo valet trust` to ensure Valet can start and stop services without having to use sudo every time. The app will not work correctly until you resolve this issue."
|
||||||
)
|
)
|
||||||
|
@ -14,7 +14,7 @@ class PhpVersion {
|
|||||||
var long : String = "???"
|
var long : String = "???"
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
let version = Shell.shared
|
let version = Shell.user
|
||||||
// Get the version directly from PHP
|
// Get the version directly from PHP
|
||||||
.pipe("php -r 'print phpversion();'")
|
.pipe("php -r 'print phpversion();'")
|
||||||
|
|
||||||
|
@ -149,6 +149,6 @@ class MainMenu: NSObject, NSWindowDelegate {
|
|||||||
|
|
||||||
func windowWillClose(_ notification: Notification) {
|
func windowWillClose(_ notification: Notification) {
|
||||||
App.shared.windowController = nil
|
App.shared.windowController = nil
|
||||||
Shell.shared.delegate = nil
|
Shell.user.delegate = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,8 @@ class ShellHistoryItem {
|
|||||||
|
|
||||||
class Shell {
|
class Shell {
|
||||||
|
|
||||||
static let shared = Shell()
|
// Singleton to access a user shell (with --login)
|
||||||
|
static let user = Shell()
|
||||||
|
|
||||||
var history : [ShellHistoryItem] = []
|
var history : [ShellHistoryItem] = []
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class LogViewController: NSViewController, ShellDelegate {
|
|||||||
public static func show(delegate: NSWindowDelegate? = nil) {
|
public static func show(delegate: NSWindowDelegate? = nil) {
|
||||||
if (App.shared.windowController == nil) {
|
if (App.shared.windowController == nil) {
|
||||||
let vc = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "logWindow") as! LogViewController
|
let vc = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "logWindow") as! LogViewController
|
||||||
Shell.shared.delegate = vc
|
Shell.user.delegate = vc
|
||||||
let window = NSWindow(contentViewController: vc)
|
let window = NSWindow(contentViewController: vc)
|
||||||
window.title = "Terminal Output"
|
window.title = "Terminal Output"
|
||||||
window.delegate = delegate
|
window.delegate = delegate
|
||||||
@ -53,7 +53,7 @@ class LogViewController: NSViewController, ShellDelegate {
|
|||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
self.textView.isEditable = false
|
self.textView.isEditable = false
|
||||||
for entry in Shell.shared.history {
|
for entry in Shell.user.history {
|
||||||
self.appendHistoryItem(entry)
|
self.appendHistoryItem(entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user