Skip to content

Commit

Permalink
📝 Minor tweaks, updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoverbruggen committed Jul 15, 2019
1 parent eebfa82 commit 0fc7f2c
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 21 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
# 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

### 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

Expand All @@ -29,4 +41,8 @@ The utility runs the following commands:
- Tell Valet to switch to a specific PHP version
- 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.
Binary file removed docs/phpmon.png
Binary file not shown.
Binary file added docs/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion phpmon/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// MARK: - Initializer

override init() {
self.sharedShell = Shell.shared
self.sharedShell = Shell.user
self.state = App.shared
self.menu = MainMenu.shared
super.init()
Expand Down
10 changes: 5 additions & 5 deletions phpmon/Classes/Commands/Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import AppKit
class Actions {

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")
// Remove all empty strings
versions.removeAll { (string) -> Bool in
Expand All @@ -28,14 +28,14 @@ class Actions {

public static func switchToPhpVersion(version: String, availableVersions: [String]) {
availableVersions.forEach { (version) in
Shell.shared.run("brew unlink php@\(version)")
Shell.user.run("brew unlink php@\(version)")
}
if (availableVersions.contains("7.3")) {
Shell.shared.run("brew link [email protected]")
Shell.user.run("brew link [email protected]")
if (version == Constants.LatestPhpVersion) {
Shell.shared.run( "valet use php")
Shell.user.run( "valet use php")
} else {
Shell.shared.run("valet use php@\(version)")
Shell.user.run("valet use php@\(version)")
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions phpmon/Classes/Commands/Startup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ class Startup {
public static func checkEnvironment()
{
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",
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(
!Shell.shared.pipe("ls /usr/local/opt | grep [email protected]").contains("[email protected]"),
!Shell.user.pipe("ls /usr/local/opt | grep [email protected]").contains("[email protected]"),
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."
)

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",
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(
!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",
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(
!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",
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."
)
Expand Down
2 changes: 1 addition & 1 deletion phpmon/Classes/Helpers/PhpVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PhpVersion {
var long : String = "???"

init() {
let version = Shell.shared
let version = Shell.user
// Get the version directly from PHP
.pipe("php -r 'print phpversion();'")

Expand Down
2 changes: 1 addition & 1 deletion phpmon/Singletons/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ class MainMenu: NSObject, NSWindowDelegate {

func windowWillClose(_ notification: Notification) {
App.shared.windowController = nil
Shell.shared.delegate = nil
Shell.user.delegate = nil
}
}
3 changes: 2 additions & 1 deletion phpmon/Singletons/Shell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ShellHistoryItem {

class Shell {

static let shared = Shell()
// Singleton to access a user shell (with --login)
static let user = Shell()

var history : [ShellHistoryItem] = []

Expand Down
4 changes: 2 additions & 2 deletions phpmon/View Controllers/LogViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LogViewController: NSViewController, ShellDelegate {
public static func show(delegate: NSWindowDelegate? = nil) {
if (App.shared.windowController == nil) {
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)
window.title = "Terminal Output"
window.delegate = delegate
Expand Down Expand Up @@ -53,7 +53,7 @@ class LogViewController: NSViewController, ShellDelegate {

override func viewDidLoad() {
self.textView.isEditable = false
for entry in Shell.shared.history {
for entry in Shell.user.history {
self.appendHistoryItem(entry)
}
}
Expand Down

0 comments on commit 0fc7f2c

Please sign in to comment.