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

Compare commits

...

54 Commits
v2.0 ... v2.6

Author SHA1 Message Date
d3615138dd 🚀 Version 2.6
* develop:
  📝 Updated quick troubleshooting
  📝 Updated documentation
  📝 Updated SECURITY
  📝 Updated README
   New build number, updated shortcut keys
  🌐 Add info about `valet install` when running force reload
   Fix my PHP should also restart dnsmasq
   Add menu item to restart dnsmasq
  🔧 Bump build number
  ♻️ Cleanup, updated README (#20)
  ♻️ Refactoring, version bump for M1 support (#20)
   Add support for Homebrew in /opt/homebrew (#20)
  👌 Clean up switchToPhpVersion() and fixMyPhp()
  👌 Avoid using sender.tag
  👌 Improved pipe() method
  🌐 Localized startup environment checks
  🐛 Perform the phpinfo.html on another thread and show busy
  📝 Updated instructions
2021-01-06 17:51:29 +01:00
dd27b91527 📝 Updated quick troubleshooting 2021-01-06 17:49:26 +01:00
bc093cc945 📝 Updated documentation 2021-01-06 17:42:09 +01:00
fd46ce6b35 📝 Updated SECURITY 2021-01-06 17:29:24 +01:00
e35acadeaf 📝 Updated README 2021-01-06 17:18:59 +01:00
7b8aab85d6 New build number, updated shortcut keys
- Cmd-F now [F]orce reloads
- Cmd-S now restarts all [S]ervices
- Cmd-P now restarts the [P]hp service
- Cmd-D now restarts the [D]nsmasq service
2021-01-01 23:55:37 +01:00
ec59715b3d 🌐 Add info about valet install when running force reload 2021-01-01 23:49:51 +01:00
6f21913ae2 Fix my PHP should also restart dnsmasq 2021-01-01 23:48:12 +01:00
b53fbe471b Add menu item to restart dnsmasq 2021-01-01 23:19:31 +01:00
209f3e889d 🔧 Bump build number 2021-01-01 23:06:24 +01:00
5825e8d0b0 ♻️ Cleanup, updated README (#20) 2021-01-01 23:05:16 +01:00
4ea11c5f59 ♻️ Refactoring, version bump for M1 support (#20) 2021-01-01 22:58:27 +01:00
94f086881a Add support for Homebrew in /opt/homebrew (#20) 2021-01-01 22:54:03 +01:00
e73474e30c 👌 Clean up switchToPhpVersion() and fixMyPhp() 2020-12-19 18:38:00 +01:00
c7a0e25336 👌 Avoid using sender.tag 2020-12-13 19:32:43 +01:00
e353fb7524 👌 Improved pipe() method 2020-12-13 19:16:51 +01:00
458868d051 🌐 Localized startup environment checks 2020-12-08 23:18:52 +01:00
932fafc728 🐛 Perform the phpinfo.html on another thread and show busy 2020-11-27 17:01:30 +01:00
b70c4f690a 📝 Updated instructions 2020-11-27 16:40:37 +01:00
4147cc7b4b 🚀 Version 2.5 2020-11-27 16:32:42 +01:00
72b309a716 📝 Be more explicit in main README 2020-11-27 16:31:54 +01:00
12c2716715 📝 Add information about running valet install 2020-11-27 16:29:02 +01:00
4d4019204b 📝 Updated README with new screenshot 2020-11-27 16:24:06 +01:00
157033a3b3 🚀 Version 2.5 (RC) 2020-11-27 11:32:26 +01:00
717cddacdd 🐛 Fix issue with php install now showing up 2020-11-27 11:29:40 +01:00
f13ed5dd90 Add option to open output of phpinfo() in browser 2020-11-27 01:33:06 +01:00
a8f823cd04 📝 Update README.md, ADDITIONAL.md 2020-11-26 18:59:49 +01:00
51fd22f595 Cleanup storyboard, add Brew package name to switcher 2020-11-26 18:53:15 +01:00
bf6ebff3bf Detect what version of PHP the php package is linked to 2020-11-26 17:58:34 +01:00
1887b19329 🚧 WIP: Get JSON about current PHP version 2020-11-26 17:02:24 +01:00
a53972404c 🚀 Version 2.4
* develop:
  📝 Updated SECURITY to reflect new support status
  🔧 Updated build settings
  🔧 Add PHP 8.0 to list of detected PHP versions
  📝 Universal application
2020-11-14 15:23:19 +01:00
64a605235a 📝 Updated SECURITY to reflect new support status 2020-11-14 02:33:46 +01:00
a194ecdebe 🔧 Updated build settings 2020-11-14 02:20:26 +01:00
03158a568c 🔧 Add PHP 8.0 to list of detected PHP versions 2020-11-14 02:19:42 +01:00
bdc6be7384 📝 Universal application 2020-11-14 02:19:28 +01:00
4908dba57e 📝 Update support information 2020-08-16 16:45:42 +02:00
0f0aa176b6 📝 Update README 2020-08-16 16:43:08 +02:00
485729f9a5 🚀 Version 2.3
Merge branch 'develop' into main

* develop:
  📝 Updated README, SECURITY docs
  🍱 Updated screenshot to Big Sur
  ♻️ Cleanup
  🚧 WIP: Notify the user about PHP switch completion (#15)
2020-08-16 16:27:38 +02:00
5eb36a9bdf 📝 Updated README, SECURITY docs 2020-07-20 17:28:59 +02:00
86113d2067 🍱 Updated screenshot to Big Sur 2020-07-19 13:17:55 +02:00
70c04d4dc7 ♻️ Cleanup
- Bump version number to 2.3
- Disable Metal validation in project configuration
- Added comments to various files to clarify code
- Moved various strings to Localizable.strings
- Removed references to old view controller for command log
- No longer log previously ran commands
2020-07-16 23:16:39 +02:00
5d69b423c1 🚧 WIP: Notify the user about PHP switch completion (#15) 2020-07-16 22:25:51 +02:00
1617b57b1e 🚀 Version 2.2
Merge branch 'develop'

* develop:
  📝 Update README
  📝 Amend modal copy
  🐛 Improved startup procedure
  🚧 Add Internet Access Policy
   Add shared scheme
2020-07-16 19:37:21 +02:00
33825e7b66 📝 Update README 2020-07-16 19:34:38 +02:00
464b7106b2 📝 Amend modal copy 2020-07-16 19:29:01 +02:00
0cf85f9958 🐛 Improved startup procedure
- First issue encountered will notify the user
- User has the option to Retry or Terminate the app
- Retry will go through launch checks again
- Some issues are marked as non-breaking, meaning the user will be
  notified, but the app will just start as usual
2020-07-16 19:26:29 +02:00
00cf2bc360 🚧 Add Internet Access Policy 2020-07-11 11:18:31 +02:00
dbb5329908 Add shared scheme 2020-07-11 10:54:05 +02:00
9fd8e7042a 🚀 Version 2.1
Merge branch 'develop'

* develop:
  📝 Add installation instructions
  📝 Added docs for release procedure
  📝 Updated README
  🔧 Hardened runtime (required for notarization)
  🍱 Updated icon for macOS 11 style, updated alert
2020-07-11 10:41:11 +02:00
cb62a20f2a 📝 Add installation instructions 2020-07-11 10:40:02 +02:00
bb1742a390 📝 Added docs for release procedure 2020-07-11 10:05:47 +02:00
6db43beddf 📝 Updated README 2020-07-11 01:07:51 +02:00
7e2c7cdd59 🔧 Hardened runtime (required for notarization) 2020-07-11 01:00:31 +02:00
e76dd0daeb 🍱 Updated icon for macOS 11 style, updated alert 2020-07-11 00:49:32 +02:00
40 changed files with 1025 additions and 359 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ phpmon.xcodeproj/project.xcworkspace
phpmon.xcodeproj/xcuserdata phpmon.xcodeproj/xcuserdata
PHP Monitor.xcodeproj/project.xcworkspace PHP Monitor.xcodeproj/project.xcworkspace
PHP Monitor.xcodeproj/xcuserdata PHP Monitor.xcodeproj/xcuserdata
.DS_Store

View File

@ -7,6 +7,9 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
C405A4D024B9B9140062FAFA /* InternetAccessPolicy.strings in Resources */ = {isa = PBXBuildFile; fileRef = C405A4CE24B9B9130062FAFA /* InternetAccessPolicy.strings */; };
C405A4D124B9B9140062FAFA /* InternetAccessPolicy.plist in Resources */ = {isa = PBXBuildFile; fileRef = C405A4CF24B9B9140062FAFA /* InternetAccessPolicy.plist */; };
C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */; };
C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */; }; C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */; };
C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3A22B0098000E7CF16 /* Assets.xcassets */; }; C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3A22B0098000E7CF16 /* Assets.xcassets */; };
C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3C22B0098000E7CF16 /* Main.storyboard */; }; C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3C22B0098000E7CF16 /* Main.storyboard */; };
@ -18,15 +21,21 @@
C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46FA23E246C358E00944F05 /* StringExtension.swift */; }; C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46FA23E246C358E00944F05 /* StringExtension.swift */; };
C473319F2470923A009A0597 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C473319E2470923A009A0597 /* Localizable.strings */; }; C473319F2470923A009A0597 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C473319E2470923A009A0597 /* Localizable.strings */; };
C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47331A1247093B7009A0597 /* StatusMenu.swift */; }; C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47331A1247093B7009A0597 /* StatusMenu.swift */; };
C474B00624C0E98C00066A22 /* LocalNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = C474B00524C0E98C00066A22 /* LocalNotification.swift */; };
C476FF9822B0DD830098105B /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = C476FF9722B0DD830098105B /* Alert.swift */; }; C476FF9822B0DD830098105B /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = C476FF9722B0DD830098105B /* Alert.swift */; };
C4811D2422D70A4700B5F6B3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2322D70A4700B5F6B3 /* App.swift */; }; C4811D2422D70A4700B5F6B3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2322D70A4700B5F6B3 /* App.swift */; };
C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; }; C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; };
C486EFFC2586931100A02B2C /* PhpMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C486EFFB2586931100A02B2C /* PhpMenuItem.swift */; };
C49EAB46259FC305007F6C3B /* Paths.swift in Sources */ = {isa = PBXBuildFile; fileRef = C49EAB45259FC305007F6C3B /* Paths.swift */; };
C4D8016622B1584700C6DA1B /* Startup.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D8016522B1584700C6DA1B /* Startup.swift */; }; C4D8016622B1584700C6DA1B /* Startup.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D8016522B1584700C6DA1B /* Startup.swift */; };
C4EE188422D3386B00E126E5 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4EE188322D3386B00E126E5 /* Constants.swift */; }; C4EE188422D3386B00E126E5 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4EE188322D3386B00E126E5 /* Constants.swift */; };
C4F8C0A422D4F12C002EFE61 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8C0A322D4F12C002EFE61 /* DateExtension.swift */; }; C4F8C0A422D4F12C002EFE61 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8C0A322D4F12C002EFE61 /* DateExtension.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
C405A4CE24B9B9130062FAFA /* InternetAccessPolicy.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = InternetAccessPolicy.strings; sourceTree = "<group>"; };
C405A4CF24B9B9140062FAFA /* InternetAccessPolicy.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = InternetAccessPolicy.plist; sourceTree = "<group>"; };
C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomebrewPackage.swift; sourceTree = "<group>"; };
C41C1B3322B0097F00E7CF16 /* PHP Monitor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PHP Monitor.app"; sourceTree = BUILT_PRODUCTS_DIR; }; C41C1B3322B0097F00E7CF16 /* PHP Monitor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PHP Monitor.app"; sourceTree = BUILT_PRODUCTS_DIR; };
C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C41C1B3A22B0098000E7CF16 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; C41C1B3A22B0098000E7CF16 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -41,10 +50,15 @@
C46FA23E246C358E00944F05 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; }; C46FA23E246C358E00944F05 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
C473319E2470923A009A0597 /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; }; C473319E2470923A009A0597 /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
C47331A1247093B7009A0597 /* StatusMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusMenu.swift; sourceTree = "<group>"; }; C47331A1247093B7009A0597 /* StatusMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusMenu.swift; sourceTree = "<group>"; };
C474B00524C0E98C00066A22 /* LocalNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalNotification.swift; sourceTree = "<group>"; };
C476FF9722B0DD830098105B /* Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alert.swift; sourceTree = "<group>"; }; C476FF9722B0DD830098105B /* Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alert.swift; sourceTree = "<group>"; };
C4811D2322D70A4700B5F6B3 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; }; C4811D2322D70A4700B5F6B3 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = "<group>"; }; C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = "<group>"; };
C486EFFB2586931100A02B2C /* PhpMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpMenuItem.swift; sourceTree = "<group>"; };
C49EAB45259FC305007F6C3B /* Paths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Paths.swift; sourceTree = "<group>"; };
C4D8016522B1584700C6DA1B /* Startup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Startup.swift; sourceTree = "<group>"; }; C4D8016522B1584700C6DA1B /* Startup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Startup.swift; sourceTree = "<group>"; };
C4E713562570150F00007428 /* SECURITY.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = SECURITY.md; sourceTree = "<group>"; };
C4E713572570151400007428 /* docs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = docs; sourceTree = "<group>"; };
C4EE188322D3386B00E126E5 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; }; C4EE188322D3386B00E126E5 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
C4F8C0A322D4F12C002EFE61 /* DateExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateExtension.swift; sourceTree = "<group>"; }; C4F8C0A322D4F12C002EFE61 /* DateExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateExtension.swift; sourceTree = "<group>"; };
C4F8C0A522D4FA41002EFE61 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; }; C4F8C0A522D4FA41002EFE61 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
@ -61,10 +75,21 @@
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
C405A4CD24B9B9070062FAFA /* IAP */ = {
isa = PBXGroup;
children = (
C405A4CF24B9B9140062FAFA /* InternetAccessPolicy.plist */,
C405A4CE24B9B9130062FAFA /* InternetAccessPolicy.strings */,
);
path = IAP;
sourceTree = "<group>";
};
C41C1B2A22B0097F00E7CF16 = { C41C1B2A22B0097F00E7CF16 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C4F8C0A522D4FA41002EFE61 /* README.md */, C4F8C0A522D4FA41002EFE61 /* README.md */,
C4E713562570150F00007428 /* SECURITY.md */,
C4E713572570151400007428 /* docs */,
C41C1B3522B0097F00E7CF16 /* phpmon */, C41C1B3522B0097F00E7CF16 /* phpmon */,
C41C1B3422B0097F00E7CF16 /* Products */, C41C1B3422B0097F00E7CF16 /* Products */,
); );
@ -91,6 +116,7 @@
C41C1B4022B0098000E7CF16 /* phpmon.entitlements */, C41C1B4022B0098000E7CF16 /* phpmon.entitlements */,
C41C1B3A22B0098000E7CF16 /* Assets.xcassets */, C41C1B3A22B0098000E7CF16 /* Assets.xcassets */,
C473319E2470923A009A0597 /* Localizable.strings */, C473319E2470923A009A0597 /* Localizable.strings */,
C405A4CD24B9B9070062FAFA /* IAP */,
); );
path = phpmon; path = phpmon;
sourceTree = "<group>"; sourceTree = "<group>";
@ -117,6 +143,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C47331A1247093B7009A0597 /* StatusMenu.swift */, C47331A1247093B7009A0597 /* StatusMenu.swift */,
C486EFFB2586931100A02B2C /* PhpMenuItem.swift */,
); );
path = Menu; path = Menu;
sourceTree = "<group>"; sourceTree = "<group>";
@ -124,6 +151,7 @@
C4811D2622D70CEF00B5F6B3 /* Singletons */ = { C4811D2622D70CEF00B5F6B3 /* Singletons */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C49EAB45259FC305007F6C3B /* Paths.swift */,
C41C1B4622B009A400E7CF16 /* Shell.swift */, C41C1B4622B009A400E7CF16 /* Shell.swift */,
C42295DC2358D02000E263B2 /* Command.swift */, C42295DC2358D02000E263B2 /* Command.swift */,
C4811D2322D70A4700B5F6B3 /* App.swift */, C4811D2322D70A4700B5F6B3 /* App.swift */,
@ -147,6 +175,8 @@
C476FF9722B0DD830098105B /* Alert.swift */, C476FF9722B0DD830098105B /* Alert.swift */,
C41C1B4A22B019FF00E7CF16 /* PhpVersion.swift */, C41C1B4A22B019FF00E7CF16 /* PhpVersion.swift */,
C41C1B4822B00A9800E7CF16 /* MenuBarImageGenerator.swift */, C41C1B4822B00A9800E7CF16 /* MenuBarImageGenerator.swift */,
C474B00524C0E98C00066A22 /* LocalNotification.swift */,
C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */,
); );
path = Helpers; path = Helpers;
sourceTree = "<group>"; sourceTree = "<group>";
@ -187,7 +217,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 1020; LastSwiftUpdateCheck = 1020;
LastUpgradeCheck = 1110; LastUpgradeCheck = 1220;
ORGANIZATIONNAME = "Nico Verbruggen"; ORGANIZATIONNAME = "Nico Verbruggen";
TargetAttributes = { TargetAttributes = {
C41C1B3222B0097F00E7CF16 = { C41C1B3222B0097F00E7CF16 = {
@ -220,7 +250,9 @@
files = ( files = (
C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */, C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */,
C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */, C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */,
C405A4D124B9B9140062FAFA /* InternetAccessPolicy.plist in Resources */,
C473319F2470923A009A0597 /* Localizable.strings in Resources */, C473319F2470923A009A0597 /* Localizable.strings in Resources */,
C405A4D024B9B9140062FAFA /* InternetAccessPolicy.strings in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -239,9 +271,13 @@
C4811D2422D70A4700B5F6B3 /* App.swift in Sources */, C4811D2422D70A4700B5F6B3 /* App.swift in Sources */,
C41C1B4922B00A9800E7CF16 /* MenuBarImageGenerator.swift in Sources */, C41C1B4922B00A9800E7CF16 /* MenuBarImageGenerator.swift in Sources */,
C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */, C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */,
C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */,
C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */, C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */,
C41C1B4B22B019FF00E7CF16 /* PhpVersion.swift in Sources */, C41C1B4B22B019FF00E7CF16 /* PhpVersion.swift in Sources */,
C486EFFC2586931100A02B2C /* PhpMenuItem.swift in Sources */,
C49EAB46259FC305007F6C3B /* Paths.swift in Sources */,
C476FF9822B0DD830098105B /* Alert.swift in Sources */, C476FF9822B0DD830098105B /* Alert.swift in Sources */,
C474B00624C0E98C00066A22 /* LocalNotification.swift in Sources */,
C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */, C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */,
C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */, C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */,
C4EE188422D3386B00E126E5 /* Constants.swift in Sources */, C4EE188422D3386B00E126E5 /* Constants.swift in Sources */,
@ -288,6 +324,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES;
@ -349,6 +386,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES;
@ -382,19 +420,21 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = phpmon/phpmon.entitlements; CODE_SIGN_ENTITLEMENTS = phpmon/phpmon.entitlements;
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 22; CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = 8M54J5J787;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = phpmon/Info.plist; INFOPLIST_FILE = phpmon/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MARKETING_VERSION = 2.0; MARKETING_VERSION = 2.6;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
}; };
name = Debug; name = Debug;
@ -404,19 +444,21 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = phpmon/phpmon.entitlements; CODE_SIGN_ENTITLEMENTS = phpmon/phpmon.entitlements;
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 22; CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = 8M54J5J787;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = phpmon/Info.plist; INFOPLIST_FILE = phpmon/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MARKETING_VERSION = 2.0; MARKETING_VERSION = 2.6;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
}; };
name = Release; name = Release;

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1220"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C41C1B3222B0097F00E7CF16"
BuildableName = "PHP Monitor.app"
BlueprintName = "PHP Monitor"
ReferencedContainer = "container:PHP Monitor.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C41C1B3222B0097F00E7CF16"
BuildableName = "PHP Monitor.app"
BlueprintName = "PHP Monitor"
ReferencedContainer = "container:PHP Monitor.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C41C1B3222B0097F00E7CF16"
BuildableName = "PHP Monitor.app"
BlueprintName = "PHP Monitor"
ReferencedContainer = "container:PHP Monitor.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

121
README.md
View File

@ -1,30 +1,46 @@
# PHP Monitor # PHP Monitor
<img src="./phpmon/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png" alt="phpmon icon" width="128px" />
PHP Monitor (or phpmon) is a lightweight macOS utility app that runs on your Mac and displays the active PHP version in your status bar. PHP Monitor (or phpmon) is a lightweight macOS utility app that runs on your Mac and displays the active PHP version in your status bar.
It also gives you quick access to various useful functionality (like switching PHP versions, restarting services, accessing configuration files, and more). <img src="./docs/screenshot.png" width="370px" alt="phpmon screenshot (menu bar app)"/>
<img src="./docs/screenshot.png" width="278px" alt="phpmon screenshot"/> It's also super convenient to switch between different versions of PHP. You'll even get notifications (only if you choose to opt-in, of course)!
For me, it comes in handy when running multiple versions of PHP with Homebrew. If you wish to be able to see at a glance which version is currently linked & active with Laravel Valet, PHP Monitor is your new best friend. <img src="./docs/notification.png" width="370px" alt="phpmon screenshot (notification)"/>
It's also super convenient to and switch between versions. It also gives you quick access to various useful functionality (like accessing configuration files, restarting services, and more).
## System requirements ## 🖥 System requirements
* macOS 10.15 Catalina PHP Monitor is a universal application that runs on Apple Silicon **and** Intel-based Macs.
* PHP 7.4 installed with Homebrew 2.x
* Laravel Valet 2.x
_Please note that future versions of PHP will not work automatically, minor changes are required to add support for newer versions of PHP._ * macOS 10.15 Catalina or higher (works on macOS 11 Big Sur)
* Homebrew is installed in `/usr/local/homebrew` or `/opt/homebrew` (the default)
* The brew formula `php` has to be installed (which version is detected)
* Laravel Valet 2.13 or higher
## Why I built this _Please note that future versions of PHP will not work automatically, minor changes are usually required to add support for newer versions of PHP. You may need to update your Valet installation to keep everything working if a major version update of PHP has been released._
## 🚀 How to install
You can install via Homebrew, or may download the latest [release][1].
To install via Homebrew, run:
brew tap nicoverbruggen/homebrew-cask
brew cask install phpmon
_The app is signed and notarized, meaning all you have to do is approve its first launch._
## 👨‍💻 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. 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). 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
@ -36,14 +52,14 @@ This utility will detect which PHP versions you have installed via Homebrew, and
This means: This means:
- You have at least the latest version of PHP installed (`php@7.4`) - You have at least the latest version of PHP installed (`php`)
- You have installed Laravel Valet (`which valet` returns `/usr/local/bin/valet`) - You have installed Laravel Valet (`which valet` returns `/usr/local/bin/valet`)
- You ran `valet trust`, which means Valet commands can be run without using sudo - You ran `valet trust`, which means Valet commands can be run without using sudo
The utility runs the following commands: The utility runs the following commands:
- Unlink all detected PHP versions - Unlink all detected PHP versions
- Switch to PHP 7.4 (this is done in order to ensure that Valet works, even when attempting to use PHP 5.6) - Switch to whatever version of PHP `php` is at (this is done to ensure that Valet works, even when attempting to use PHP 5.6)
- Stop all php-fpm service instances - Stop all php-fpm service instances
- Link the desired version of PHP - Link the desired version of PHP
- Start the correct php-fpm service for the desired PHP version - Start the correct php-fpm service for the desired PHP version
@ -54,16 +70,14 @@ If you want to know more about how this works, I recommend you check out the sou
This app isn't very complicated after all. In the end, this just (conveniently) executes some shell commands. This app isn't very complicated after all. In the end, this just (conveniently) executes some shell commands.
## Troubleshooting ## 🤬 Troubleshooting
**If you are having issues, the first thing you should be doing is installing the latest version of PHP Monitor. This can resolve a variety of issues.** **If you are having issues, the first thing you should be doing is installing the latest version of PHP Monitor _and_ Laravel Valet. This can resolve a variety of issues. To upgrade Valet, run `composer global update`. Don't forget to run `valet install` after upgrading.**
### Reasons for alerts at startup
PHP Monitor performs some integrity checks to ensure a good experience when using the app. You'll get a message telling you that PHP Monitor won't work correctly in the following scenarios: PHP Monitor performs some integrity checks to ensure a good experience when using the app. You'll get a message telling you that PHP Monitor won't work correctly in the following scenarios:
- The PHP binary is not located in `/usr/local/bin/php` - The PHP binary is not located in `/usr/local/bin/php` (or `/opt/homebrew/bin/php`)
- PHP 7.4 is missing in `/usr/local/opt` - PHP is missing in `/usr/local/opt` (or `/opt/homebrew/opt`)
- Laravel Valet is missing in `/usr/local/bin/valet` - Laravel Valet is missing in `/usr/local/bin/valet`
- Brew has not been added to sudoers in `/private/etc/sudoers.d/brew` - Brew has not been added to sudoers in `/private/etc/sudoers.d/brew`
- Valet has not been added to sudoers in `/private/etc/sudoers.d/valet` - Valet has not been added to sudoers in `/private/etc/sudoers.d/valet`
@ -71,65 +85,40 @@ PHP Monitor performs some integrity checks to ensure a good experience when usin
Follow instructions as specified in the alert in order to resolve any issues. Follow instructions as specified in the alert in order to resolve any issues.
### Additional troubleshooting ## 🏎 Quick Troubleshooting
#### Q: I want PHP Monitor to start up when I boot my Mac! ### PHP Monitor tells me `php` is not installed
You can do this by dragging *PHP Monitor.app* into the **Login Items** section in **System Preferences > Users & Groups** for your account. Try installing again using `brew install php`.
Super convenient! This should resolve the issue! If that does not fix the issue, run `brew link php --force`. (Afterwards, you may need to restart your terminal to make sure the new linked version is detected.)
#### Q: PHP Monitor says that the latest version of PHP is not installed, but it is! brew install php
brew link php --force
### Valet sites won't load (502 Bad Gateway)
Try installing again using `brew install php@7.4`. If you're visiting your `.test` domain, and you're getting a 502 (Bad Gateway) after switching to a different PHP version, you're dealing with a common issue.
This should resolve the issue. This problem is usually resolved by upgrading Valet and running `valet install` again.
#### Q: PHP Monitor reports another version compared to phpinfo on my local website, what is going on? composer global update
valet install
_Beginning with version 2.0 you'll get alerts about this at startup._ ## 📝 Additional Info
If you're still seeing another version of PHP in your scripts running on your local webserver (nginx) — e.g. when running `phpinfo()` — I recommend you shut down all PHP services that are currently active. You can find out what services are active by running: Please consult the [additional file][2] that contains more information. It may have answers to additional questions and more information to troubleshoot your problem.
sudo brew services list | grep php ## ⭐️ Star me!
This will present to you a list of services, like so (depending on the installed versions of PHP): If this software has been useful to you, I ask that you **please star the repository**, so I know that the software is being used.
``` I did not include any tracking or analytics software, so if you encounter issues, let me know [via an issue](https://github.com/nicoverbruggen/phpmon/issues/new).
php started root /Library/LaunchDaemons/homebrew.mxcl.php.plist
php@5.6 stopped
php@7.0 stopped
php@7.1 stopped
php@7.2 stopped
php@7.3 stopped
```
You'll want to make sure that **only one service is running** and that it is running **as `root`**. You can terminate a service by running: ## 💵 Support me?
sudo brew services stop {service_name} I develop this application in my spare time, after work. If you find the application useful and you have a bit of money to spare, feel free to send me [a tip via PayPal][3].
So in order to disable PHP 7.3, you'd need to run: [1]: https://github.com/nicoverbruggen/phpmon/releases
[2]: docs/ADDITIONAL.md
sudo brew services stop php@7.3 [3]: https://paypal.me/nicoverbruggen
If you notice that PHP FPM is running as your own user account, you can turn off the service by running:
brew services stop php@7.3
The easiest way to make sure that PHP Monitor works again is to run the following commands:
sudo brew services stop php
sudo brew services stop php@7.3
sudo brew services stop php@7.2
sudo brew services stop php@7.1
sudo brew services stop php@7.0
sudo brew services stop php@5.6
sudo brew services stop nginx
Then, in PHP Monitor, select "Restart php-fpm service", which should start the service.
Alternatively, you can run `sudo brew services start php@7.4` where `7.4` is your preferred version of PHP (for the latest version of PHP, you may omit `@7.4` like in the example above).
---
If this software has been useful to you, star the repository so I know that the software is being used. I did not include any tracking or analytics software, so if you encounter issues, let me know via an issue.

21
SECURITY.md Normal file
View File

@ -0,0 +1,21 @@
# Security Policy
## Supported versions
Generally speaking, only the latest version of **PHP Monitor** is supported:
| Version | Apple Silicon | Supported | Supported macOS | Deployment Target |
| ------- | ------------- | ------------------ | ----- | ----- |
| 2.6 | ✅ Universal binary, full support | ✅ | Big Sur (11.0) | macOS 10.14+ |
The following versions are no longer supported:
| Version | Apple Silicon | Supported | Supported macOS | Deployment Target |
| ------- | ------------- | ------------------ | ----- | ----- |
| 2.5 | ✴️ Universal binary<br/>`/usr/local/homebrew` installations only) | ❌ | Big Sur (11.0)<br/>Catalina (10.15) | macOS 10.14+ |
| 2.4 | ✴️ Universal binary<br/>`/usr/local/homebrew` installations only) | ❌ | Big Sur (11.0)<br/>Catalina (10.15) | macOS 10.14+ |
| < 2.4 | (Intel binary<br/>`/usr/local/homebrew` installations only) | ❌ | Catalina (10.15) | macOS 10.14+ |
## Reporting a vulnerability
Contact me (Nico Verbruggen) at the email address used for the commits in the repository. Please include "PHP Monitor" in the subject.

Binary file not shown.

124
docs/ADDITIONAL.md Normal file
View File

@ -0,0 +1,124 @@
### Quick Setup
If you want to set up your computer for the very first time with PHP Monitor, here's how I do it:
Install [Homebrew](https://brew.sh) first.
Install PHP, composer, add to path:
brew install php
brew install composer
nano .zshrc
Make sure the following line is not in the comments:
# on an Intel Mac
export PATH=$HOME/bin:/usr/local/bin:$PATH
If you're on an Apple Silicon-based Mac, you'll need to add:
# on an M1 Mac
export PATH=$HOME/bin:/opt/homebrew/bin:$PATH
and add the following to your .zshrc:
export PATH=$HOME/bin:~/.composer/vendor/bin:$PATH
Make sure PHP is linked correctly:
which php
should return: `/usr/local/bin/php` (or `/opt/homebrew/bin/php`)
composer global require laravel/valet
valet install
This should install `dnsmasq` and set up Valet. Great, almost there!
valet trust
Finally, run PHP Monitor. Since the app is notarized and signed with a developer ID, it should work.
### FAQ
#### Q: Does this support Apple Silicon?
Yes. This is a universal app.
The following installation paths are supported:
* `/usr/local/homebrew` (default on Intel Macs)
* `/opt/homebrew` (default on Apple Silicon Macs)
#### Q: Is PHP 8.0 supported?
Yes.
#### Q: This app is doing network requests? Why?
It's Homebrew. I can't prevent `brew` from doing things via the network when I invoke it.
PHP Monitor itself doesn't do any network requests. Feel free to check the source code or intercept the traffic, if you don't believe me.
#### Q: I want PHP Monitor to start up when I boot my Mac!
You can do this by dragging *PHP Monitor.app* into the **Login Items** section in **System Preferences > Users & Groups** for your account.
Super convenient!
### Q: PHP Monitor says that the latest version of PHP is not installed, but it is!
Try installing again using `brew install php`.
This should resolve the issue! If that does not fix the issue, run `brew link php --force`. (Afterwards, you may need to restart your terminal to make sure the new linked version is detected.)
### Q: PHP Monitor says the correct version is loaded, but my Valet sites don't work!
Your sites aren't showing up, or you are seeing a 502? It's a common issue.
You may need to run `valet install`, preferably after updating `valet` by running `composer global update`.
#### Q: PHP Monitor reports another version compared to phpinfo on my local website, what is going on?
_Beginning with version 2.0 you'll get alerts about this at startup._
If you're still seeing another version of PHP in your scripts running on your local webserver (nginx) — e.g. when running `phpinfo()` — I recommend you shut down all PHP services that are currently active. You can find out what services are active by running:
sudo brew services list | grep php
This will present to you a list of services, like so (depending on the installed versions of PHP):
```
php started root /Library/LaunchDaemons/homebrew.mxcl.php.plist
php@5.6 stopped
php@7.0 stopped
php@7.1 stopped
php@7.2 stopped
php@7.3 stopped
```
You'll want to make sure that **only one service is running** and that it is running **as `root`**. You can terminate a service by running:
sudo brew services stop {service_name}
So in order to disable PHP 7.3, you'd need to run:
sudo brew services stop php@7.3
If you notice that PHP FPM is running as your own user account, you can turn off the service by running:
brew services stop php@7.3
The easiest way to make sure that PHP Monitor works again is to run the following commands:
sudo brew services stop php
sudo brew services stop php@7.3
sudo brew services stop php@7.2
sudo brew services stop php@7.1
sudo brew services stop php@7.0
sudo brew services stop php@5.6
sudo brew services stop nginx
Then, in PHP Monitor, select "Restart php-fpm service", which should start the service.
Alternatively, you can run `sudo brew services start php@7.4` where `7.4` is your preferred version of PHP (for the latest version of PHP, you may omit `@7.4` like in the example above).

13
docs/RELEASE.md Normal file
View File

@ -0,0 +1,13 @@
# Release Procedure
1. Merge into `main`
2. Create tag
3. Add changes to changelog
4. Archive
5. Notarize and prepare for own distribution
6. After notarization, export .app
7. Create zipped version
8. Calculate SHA256: `openssl dgst -sha256 phpmon.zip`
9. Upload to GitHub and add to tagged release
10. Update Cask with new version + hash
11. Check new version can be installed via Cask

BIN
docs/notification.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 615 KiB

After

Width:  |  Height:  |  Size: 162 KiB

View File

@ -7,33 +7,75 @@
// //
import Cocoa import Cocoa
import UserNotifications
@NSApplicationMain @NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate { class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
// MARK: - Variables // MARK: - Variables
/**
The Shell singleton that keeps track of the history of all
(invoked by PHP Monitor) shell commands. It is used to
invoke all commands in this application.
*/
let sharedShell : Shell let sharedShell : Shell
/**
The App singleton contains information about the state of
the application and global variables.
*/
let state : App let state : App
/**
The MainMenu singleton is responsible for rendering the
menu bar item and its menu, as well as its actions.
*/
let menu : MainMenu let menu : MainMenu
/**
The paths singleton that determines where Homebrew is installed,
and where to look for binaries.
*/
let paths : Paths
// MARK: - Initializer // MARK: - Initializer
/**
When the application initializes, create all singletons.
*/
override init() { override init() {
self.sharedShell = Shell.user self.sharedShell = Shell.user
self.state = App.shared self.state = App.shared
self.menu = MainMenu.shared self.menu = MainMenu.shared
self.paths = Paths.shared
super.init() super.init()
} }
// MARK: - Lifecycle // MARK: - Lifecycle
/**
When the application has finished launching, we'll want to set up
the user notification center delegate, and kickoff the menu
startup procedure.
*/
func applicationDidFinishLaunching(_ aNotification: Notification) { func applicationDidFinishLaunching(_ aNotification: Notification) {
NSUserNotificationCenter.default.delegate = self
self.menu.startup() self.menu.startup()
} }
func applicationWillTerminate(_ aNotification: Notification) { // MARK: - NSUserNotificationCenterDelegate
self.state.windowController = nil
/**
When a notification is sent, the delegate of the notification center
is asked whether the notification should be presented or not. Since
the user can now disable notifications per application since macOS
Catalina, any and all notifications should be displayed.
*/
func userNotificationCenter(
_ center: NSUserNotificationCenter,
shouldPresent notification: NSUserNotification
) -> Bool {
return true
} }
} }

View File

@ -1,68 +1,68 @@
{ {
"images" : [ "images" : [
{ {
"size" : "16x16",
"idiom" : "mac",
"filename" : "icon_16x16.png", "filename" : "icon_16x16.png",
"scale" : "1x" "idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
}, },
{ {
"size" : "16x16",
"idiom" : "mac",
"filename" : "icon_16x16@2x.png", "filename" : "icon_16x16@2x.png",
"scale" : "2x" "idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
}, },
{ {
"size" : "32x32",
"idiom" : "mac",
"filename" : "icon_32x32.png", "filename" : "icon_32x32.png",
"scale" : "1x" "idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
}, },
{ {
"size" : "32x32",
"idiom" : "mac",
"filename" : "icon_32x32@2x.png", "filename" : "icon_32x32@2x.png",
"scale" : "2x" "idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
}, },
{ {
"size" : "128x128",
"idiom" : "mac",
"filename" : "icon_128x128.png", "filename" : "icon_128x128.png",
"scale" : "1x" "idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
}, },
{ {
"size" : "128x128",
"idiom" : "mac",
"filename" : "icon_128x128@2x.png", "filename" : "icon_128x128@2x.png",
"scale" : "2x" "idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
}, },
{ {
"size" : "256x256",
"idiom" : "mac",
"filename" : "icon_256x256.png", "filename" : "icon_256x256.png",
"scale" : "1x" "idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
}, },
{ {
"size" : "256x256",
"idiom" : "mac",
"filename" : "icon_256x256@2x.png", "filename" : "icon_256x256@2x.png",
"scale" : "2x" "idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
}, },
{ {
"size" : "512x512",
"idiom" : "mac",
"filename" : "icon_512x512.png", "filename" : "icon_512x512.png",
"scale" : "1x" "idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
}, },
{ {
"size" : "512x512",
"idiom" : "mac",
"filename" : "icon_512x512@2x.png", "filename" : "icon_512x512@2x.png",
"scale" : "2x" "idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
} }
], ],
"info" : { "info" : {
"version" : 1, "author" : "xcode",
"author" : "xcode" "version" : 1
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 647 B

After

Width:  |  Height:  |  Size: 714 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 422 KiB

After

Width:  |  Height:  |  Size: 315 KiB

View File

@ -12,66 +12,78 @@ import AppKit
class Actions { class Actions {
public static func detectPhpVersions() -> [String] { public static func detectPhpVersions() -> [String] {
let files = Shell.user.pipe("ls /usr/local/opt | grep php@") let files = Shell.user.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
versions.removeAll { (string) -> Bool in versions.removeAll { (string) -> Bool in
return (string == "") return (string == "")
} }
// Get a list of versions only // Get a list of versions only
var versionsOnly : [String] = [] var versionsOnly : [String] = []
versions.forEach { (string) in versions.forEach { (string) in
versionsOnly.append(string.components(separatedBy: "php@")[1]) versionsOnly.append(string.components(separatedBy: "php@")[1])
} }
// Make sure the aliased version is detected
// The user may have `php` installed, but not e.g. `php@8.0`
// We should also detect that as a version that is installed
let phpAlias = App.shared.brewPhpVersion
if (!versionsOnly.contains(phpAlias)) {
versionsOnly.append(phpAlias);
}
return versionsOnly return versionsOnly
} }
public static func restartPhpFpm() { public static func restartPhpFpm() {
let version = App.shared.currentVersion!.short let version = App.shared.currentVersion!.short
if (version == Constants.LatestPhpVersion) { if (version == App.shared.brewPhpVersion) {
Shell.user.run("sudo brew services restart php") Shell.user.run("sudo \(Paths.brew()) services restart php")
} else { } else {
Shell.user.run("sudo brew services restart php@\(version)") Shell.user.run("sudo \(Paths.brew()) services restart php@\(version)")
} }
} }
public static func restartNginx() public static func restartNginx()
{ {
Shell.user.run("sudo brew services restart nginx") Shell.user.run("sudo \(Paths.brew()) services restart nginx")
} }
public static func restartDnsMasq()
{
Shell.user.run("sudo \(Paths.brew()) services restart dnsmasq")
}
/**
Switching to a new PHP version involves:
- unlinking the current version
- stopping the active services
- linking the new desired version
Please note that depending on which version is installed,
the version that is switched to may or may not be identical to `php` (without @version).
*/
public static func switchToPhpVersion(version: String, availableVersions: [String]) { public static func switchToPhpVersion(version: String, availableVersions: [String]) {
availableVersions.forEach { (version) in availableVersions.forEach { (available) in
// Unlink the current version let formula = (available == App.shared.brewPhpVersion) ? "php" : "php@\(available)"
Shell.user.run("brew unlink php@\(version)") Shell.user.run("\(Paths.brew()) unlink \(formula)")
// Stop the services Shell.user.run("sudo \(Paths.brew()) services stop \(formula)")
if (version == Constants.LatestPhpVersion) {
Shell.user.run("sudo brew services stop php")
} else {
Shell.user.run("sudo brew services stop php@\(version)")
}
}
if (availableVersions.contains(Constants.LatestPhpVersion)) {
// Use the latest version as a default
Shell.user.run("brew link php@\(Constants.LatestPhpVersion) --overwrite --force")
if (version == Constants.LatestPhpVersion) {
// If said version was also requested, all we need to do is start the service
Shell.user.run("sudo brew services start php")
} else {
// Otherwise, link the correct php version + start the correct service
Shell.user.run("brew link php@\(version) --overwrite --force")
Shell.user.run("sudo brew services start php@\(version)")
}
} }
let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
Shell.user.run("\(Paths.brew()) link \(formula) --overwrite --force")
Shell.user.run("sudo \(Paths.brew()) services start \(formula)")
} }
public static func openGenericPhpConfigFolder() { public static func openGenericPhpConfigFolder() {
let files = [NSURL(fileURLWithPath: "/usr/local/etc/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: "/usr/local/etc/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])
} }
@ -82,7 +94,7 @@ class Actions {
public static func didFindXdebug(_ version: String) -> Bool { public static func didFindXdebug(_ version: String) -> Bool {
let command = """ let command = """
grep -q 'zend_extension="xdebug.so"' /usr/local/etc/php/\(version)/php.ini; [ $? -eq 0 ] && echo "YES" || echo "NO" grep -q 'zend_extension="xdebug.so"' \(Paths.etcPath())/php/\(version)/php.ini; [ $? -eq 0 ] && echo "YES" || echo "NO"
""" """
let output = Shell.user.pipe(command).trimmingCharacters(in: .whitespacesAndNewlines) let output = Shell.user.pipe(command).trimmingCharacters(in: .whitespacesAndNewlines)
return (output == "YES") return (output == "YES")
@ -90,7 +102,7 @@ class Actions {
public static func didEnableXdebug(_ version: String) -> Bool { public static func didEnableXdebug(_ version: String) -> Bool {
let command = """ let command = """
grep -q '; zend_extension="xdebug.so"' /usr/local/etc/php/\(version)/php.ini; [ $? -eq 0 ] && echo "YES" || echo "NO" grep -q '; zend_extension="xdebug.so"' \(Paths.etcPath())/php/\(version)/php.ini; [ $? -eq 0 ] && echo "YES" || echo "NO"
""" """
let output = Shell.user.pipe(command).trimmingCharacters(in: .whitespacesAndNewlines) let output = Shell.user.pipe(command).trimmingCharacters(in: .whitespacesAndNewlines)
return (output == "NO") return (output == "NO")
@ -99,34 +111,40 @@ class Actions {
public static func toggleXdebug() { public static func toggleXdebug() {
let version = App.shared.currentVersion?.short let version = App.shared.currentVersion?.short
var command = """ var command = """
sed -i '' 's/; zend_extension="xdebug.so"/zend_extension="xdebug.so"/g' /usr/local/etc/php/\(version!)/php.ini sed -i '' 's/; zend_extension="xdebug.so"/zend_extension="xdebug.so"/g' \(Paths.etcPath())/php/\(version!)/php.ini
""" """
if (self.didEnableXdebug(version!)) { if (self.didEnableXdebug(version!)) {
command = """ command = """
sed -i '' 's/zend_extension="xdebug.so"/; zend_extension="xdebug.so"/g' /usr/local/etc/php/\(version!)/php.ini sed -i '' 's/zend_extension="xdebug.so"/; zend_extension="xdebug.so"/g' \(Paths.etcPath())/php/\(version!)/php.ini
""" """
} }
Shell.user.run(command) Shell.user.run(command)
} }
// unlink all the crap and link the latest version /**
// this also restarts all services Detects all currently available PHP versions, and unlinks each and every one of them.
After this, the brew services are also stopped, the latest PHP version is linked, and php + nginx are restarted.
If this does not solve the issue, the user may need to install additional extensions and/or run `composer global update`.
*/
public static func fixMyPhp() { public static func fixMyPhp() {
Shell.user.run("sudo \(Paths.brew()) services stop dnsmasq")
Shell.user.run("sudo \(Paths.brew()) services start dnsmasq")
let versions = self.detectPhpVersions() let versions = self.detectPhpVersions()
versions.forEach { (version) in versions.forEach { (version) in
Shell.user.run("brew unlink php@\(version)") Shell.user.run("\(Paths.brew()) unlink php@\(version)")
if (version == Constants.LatestPhpVersion) { if (version == App.shared.brewPhpVersion) {
Shell.user.run("brew services stop php") Shell.user.run("\(Paths.brew()) services stop php")
Shell.user.run("sudo brew services stop php") Shell.user.run("sudo \(Paths.brew()) services stop php")
} else { } else {
Shell.user.run("brew services stop php@\(version)") Shell.user.run("\(Paths.brew()) services stop php@\(version)")
Shell.user.run("sudo brew services stop php@\(version)") Shell.user.run("sudo \(Paths.brew()) services stop php@\(version)")
} }
} }
Shell.user.run("brew services stop php") Shell.user.run("\(Paths.brew()) services stop php")
Shell.user.run("brew services stop nginx") Shell.user.run("\(Paths.brew()) services stop nginx")
Shell.user.run("brew link php") Shell.user.run("\(Paths.brew()) link php")
Shell.user.run("sudo brew services restart php") Shell.user.run("sudo \(Paths.brew()) services restart dnsmasq")
Shell.user.run("sudo brew services restart nginx") Shell.user.run("sudo \(Paths.brew()) services restart php")
Shell.user.run("sudo \(Paths.brew()) services restart nginx")
} }
} }

View File

@ -10,62 +10,118 @@ import Foundation
class Startup { class Startup {
public static func checkEnvironment() public var failed : Bool = false
public var failureCallback = {}
/**
Checks the user's environment and checks if PHP Monitor can be used properly.
This checks if PHP is installed, Valet is running, the appropriate permissions are set, and more.
- Parameter success: Callback that is fired if the application can proceed with launch
- Parameter failure: Callback that is fired if the application must retry launch
*/
public func checkEnvironment(success: () -> Void, failure: @escaping () -> Void)
{ {
self.presentAlertOnMainThreadIf( self.failureCallback = failure
!Shell.user.pipe("which php").contains("/usr/local/bin/php"),
messageText: "PHP is not correctly installed", self.performEnvironmentCheck(
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. (Usually `brew link php` resolves this issue.)" !Shell.fileExists("\(Paths.binPath())/php"),
messageText: "startup.errors.php_binary.title".localized,
informativeText: "startup.errors.php_binary_desc".localized,
breaking: true
) )
self.presentAlertOnMainThreadIf( self.performEnvironmentCheck(
!Shell.user.pipe("ls /usr/local/opt | grep php@7.4").contains("php@7.4"), !Shell.user.pipe("ls \(Paths.optPath()) | grep php").contains("php"),
messageText: "PHP 7.4 is not correctly installed", messageText: "startup.errors.php_opt.title".localized,
informativeText: "PHP 7.4 alias was not found in `/usr/local/opt`. The app will not work correctly until you resolve this issue. If you already have the `php` formula installed, you may need to run `brew install php@7.4` in order for PHP Monitor to detect this installation." informativeText: "startup.errors.php_opt.desc".localized,
breaking: true
) )
self.presentAlertOnMainThreadIf( self.performEnvironmentCheck(
!Shell.user.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: "startup.errors.valet_executable.title".localized,
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: "startup.errors.valet_executable.desc".localized,
breaking: true
) )
self.presentAlertOnMainThreadIf( self.performEnvironmentCheck(
!Shell.user.pipe("cat /private/etc/sudoers.d/brew").contains("/usr/local/bin/brew"), !Shell.user.pipe("cat /private/etc/sudoers.d/brew").contains("\(Paths.binPath())/brew"),
messageText: "Brew has not been added to sudoers.d", messageText: "startup.errors.sudoers_brew.title".localized,
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: "startup.errors.sudoers_brew.desc".localized,
breaking: true
) )
self.presentAlertOnMainThreadIf( self.performEnvironmentCheck(
!Shell.user.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: "startup.errors.sudoers_valet.title".localized,
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: "startup.errors.sudoers_valet.desc".localized,
breaking: true
) )
let services = Shell.user.pipe("brew services list | grep php") let services = Shell.user.pipe("\(Paths.brew()) services list | grep php")
self.presentAlertOnMainThreadIf( self.performEnvironmentCheck(
(services.countInstances(of: "started") > 1), (services.countInstances(of: "started") > 1),
messageText: "Multiple PHP services are active", messageText: "startup.errors.services.title".localized,
informativeText: "This can cause php-fpm to serve a more recent version of PHP than the one you'd like to see active. Please terminate all extra PHP processes." + informativeText: "startup.errors.services.desc".localized,
"\n\nThe easiest solution is to choose the option 'Force load latest PHP version' in the menu bar." + breaking: false
"\n\nAlternatively, you can fix this manually. You can do this by running `brew services list` and running `sudo brew services stop php@7.3` (and use the version that applies)." +
"\n\nPHP Monitor usually handles the starting and stopping of these services, so once the correct version is the only PHP version running you should not have any issues. It is recommended to restart PHP Monitor once you have resolved this issue." +
"\n\nFor more information about this issue, please see the README.md file in the repository on GitHub."
) )
if (!self.failed) {
self.determineBrewAliasVersion()
success()
}
} }
private static func presentAlertOnMainThreadIf( /**
* In order to avoid having to hard-code which version of PHP is aliased to what specific subversion,
* PHP Monitor now determines the alias by checking the user's system.
*/
private func determineBrewAliasVersion()
{
print("PHP Monitor has determined the application has successfully passed all checks.")
print("Determining which version of PHP is aliased to `php` via Homebrew...")
let brewPhpAlias = Shell.user.pipe("\(Paths.brew()) info php --json");
App.shared.brewPhpPackage = try! JSONDecoder().decode(
[HomebrewPackage].self,
from: brewPhpAlias.data(using: .utf8)!
).first!
print("When on your system, the `php` formula means version \(App.shared.brewPhpVersion)!")
}
/**
* Perform an environment check. Will cause the application to terminate, if `breaking` is set to true.
*
* - Parameter condition: Fail condition to check for; if this returns `true`, the alert will be shown
* - Parameter messageText: Short description of what is wrong
* - Parameter informativeText: Expanded description of the environment check that failed
* - Parameter breaking: If the application should terminate afterwards
*/
private func performEnvironmentCheck(
_ condition: Bool, _ condition: Bool,
messageText: String, messageText: String,
informativeText: String informativeText: String,
breaking: Bool
) )
{ {
if (condition) { if (condition) {
// Only breaking issues will cause the notification
if (breaking) {
self.failed = true
}
DispatchQueue.main.async { DispatchQueue.main.async {
Alert.present( // Present the information to the user
_ = Alert.present(
messageText: messageText, messageText: messageText,
informativeText: informativeText informativeText: informativeText
) )
// Only breaking issues will throw the extra retry modal
if (breaking) {
self.failureCallback()
}
} }
} }
} }

View File

@ -12,12 +12,16 @@ class Alert {
public static func present( public static func present(
messageText: String, messageText: String,
informativeText: String, informativeText: String,
buttonTitle: String = "OK" buttonTitle: String = "OK",
) { secondButtonTitle: String = ""
) -> Bool {
let alert = NSAlert.init() let alert = NSAlert.init()
alert.messageText = messageText alert.messageText = messageText
alert.informativeText = informativeText alert.informativeText = informativeText
alert.addButton(withTitle: buttonTitle) alert.addButton(withTitle: buttonTitle)
alert.runModal() if (!secondButtonTitle.isEmpty) {
alert.addButton(withTitle: secondButtonTitle)
}
return alert.runModal() == .alertFirstButtonReturn
} }
} }

View File

@ -0,0 +1,19 @@
//
// HomebrewPackage.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 26/11/2020.
// Copyright © 2020 Nico Verbruggen. All rights reserved.
//
import Foundation
struct HomebrewPackage : Decodable {
let name: String
let full_name: String
let aliases: [String]
public func getVersion() -> String {
return aliases.first!.replacingOccurrences(of: "php@", with: "")
}
}

View File

@ -0,0 +1,19 @@
//
// LocalNotification.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 16/07/2020.
// Copyright © 2020 Nico Verbruggen. All rights reserved.
//
import Foundation
class LocalNotification {
public static func send(title: String, subtitle: String)
{
let notification = NSUserNotification()
notification.title = title
notification.subtitle = subtitle
NSUserNotificationCenter.default.deliver(notification)
}
}

View File

@ -19,7 +19,10 @@ class PhpVersion {
var error : Bool = false var error : Bool = false
init() { init() {
let version = Command.execute(path: "/usr/local/bin/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.short = "💩 BROKEN" self.short = "💩 BROKEN"

View File

@ -0,0 +1,15 @@
//
// PhpMenuItem.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 13/12/2020.
// Copyright © 2020 Nico Verbruggen. All rights reserved.
//
import Cocoa
class PhpMenuItem: NSMenuItem {
var version: String = ""
}

View File

@ -12,17 +12,18 @@ class StatusMenu : NSMenu {
public func addPhpVersionMenuItems() public func addPhpVersionMenuItems()
{ {
var string = "We are not sure what version of PHP you are running." var string = "mi_unsure".localized
if (App.shared.currentVersion != nil) { if (App.shared.currentVersion != nil) {
if (!App.shared.currentVersion!.error) { if (!App.shared.currentVersion!.error) {
string = "You are running PHP \(App.shared.currentVersion!.long)" // in case the php version loaded without issue
string = "\("mi_php_version".localized) \(App.shared.currentVersion!.long)"
self.addItem(NSMenuItem(title: string, action: nil, keyEquivalent: "")) self.addItem(NSMenuItem(title: string, action: nil, keyEquivalent: ""))
} else { } else {
// in case of an error show the error message // in case of an error show the error message
self.addItem(NSMenuItem(title: "Oof! It appears your PHP installation is broken...", action: nil, keyEquivalent: "")) ["mi_php_broken_1", "mi_php_broken_2",
self.addItem(NSMenuItem(title: "Try running `php -v` in your terminal.", action: nil, keyEquivalent: "")) "mi_php_broken_3", "mi_php_broken_4"].forEach { (message) in
self.addItem(NSMenuItem(title: "You could also try switching to another version.", action: nil, keyEquivalent: "")) self.addItem(NSMenuItem(title: message.localized, action: nil, keyEquivalent: ""))
self.addItem(NSMenuItem(title: "Running `brew reinstall php` (or for the equivalent version) might help.", action: nil, keyEquivalent: "")) }
} }
} }
} }
@ -34,30 +35,38 @@ class StatusMenu : NSMenu {
for index in (0..<App.shared.availablePhpVersions.count).reversed() { for index in (0..<App.shared.availablePhpVersions.count).reversed() {
let version = App.shared.availablePhpVersions[index] let version = App.shared.availablePhpVersions[index]
let action = #selector(MainMenu.switchToPhpVersion(sender:)) let action = #selector(MainMenu.switchToPhpVersion(sender:))
let menuItem = NSMenuItem(title: "Switch to PHP \(version)", action: (version == App.shared.currentVersion?.short) ? nil : action, keyEquivalent: "\(shortcutKey)") let brew = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
menuItem.tag = index let menuItem = PhpMenuItem(title: "\("mi_php_switch".localized) \(version) (\(brew))", action: (version == App.shared.currentVersion?.short) ? nil : action, keyEquivalent: "\(shortcutKey)")
menuItem.version = version
shortcutKey = shortcutKey + 1 shortcutKey = shortcutKey + 1
self.addItem(menuItem) self.addItem(menuItem)
} }
self.addItem(NSMenuItem.separator()) self.addItem(NSMenuItem.separator())
self.addItem(NSMenuItem(title: "Active Services", action: nil, keyEquivalent: "")) self.addItem(NSMenuItem(title: "mi_active_services".localized, action: nil, keyEquivalent: ""))
self.addItem(NSMenuItem(title: "Restart php-fpm service", action: #selector(MainMenu.restartPhpFpm), keyEquivalent: "f")) self.addItem(NSMenuItem(title: "mi_restart_dnsmasq".localized, action: #selector(MainMenu.restartDnsMasq), keyEquivalent: "d"))
self.addItem(NSMenuItem(title: "Restart nginx service", action: #selector(MainMenu.restartNginx), keyEquivalent: "n")) self.addItem(NSMenuItem(title: "mi_restart_php_fpm".localized, action: #selector(MainMenu.restartPhpFpm), keyEquivalent: "p"))
self.addItem(NSMenuItem(title: "Force load latest PHP version", action: #selector(MainMenu.forceRestartLatestPhp), keyEquivalent: "")) self.addItem(NSMenuItem(title: "mi_restart_nginx".localized, action: #selector(MainMenu.restartNginx), keyEquivalent: "n"))
self.addItem(NSMenuItem(title: "mi_restart_all_services".localized, action: #selector(MainMenu.restartAllServices), keyEquivalent: "s"))
self.addItem(NSMenuItem.separator())
self.addItem(NSMenuItem(title: "mi_diagnostics".localized, action: nil, keyEquivalent: ""))
self.addItem(NSMenuItem(title: "mi_force_load_latest".localized, action: #selector(MainMenu.forceRestartLatestPhp), keyEquivalent: "f"))
} }
if (App.shared.busy) { if (App.shared.busy) {
self.addItem(NSMenuItem(title: "PHP Monitor is busy...", action: nil, keyEquivalent: "")) self.addItem(NSMenuItem(title: "mi_busy".localized, action: nil, keyEquivalent: ""))
} }
} }
public func addPhpConfigurationMenuItems() public func addPhpConfigurationMenuItems()
{ {
if (App.shared.currentVersion != nil) { if (App.shared.currentVersion != nil) {
self.addItem(NSMenuItem(title: "Configuration", action: nil, keyEquivalent: "")) self.addItem(NSMenuItem(title: "mi_configuration".localized, action: nil, keyEquivalent: ""))
self.addItem(NSMenuItem(title: "Valet configuration (.config/valet)", action: #selector(MainMenu.openValetConfigFolder), keyEquivalent: "v")) self.addItem(NSMenuItem(title: "mi_valet_config".localized, action: #selector(MainMenu.openValetConfigFolder), keyEquivalent: "v"))
self.addItem(NSMenuItem(title: "PHP configuration file (php.ini)", action: #selector(MainMenu.openActiveConfigFolder), keyEquivalent: "c")) self.addItem(NSMenuItem(title: "mi_php_config".localized, action: #selector(MainMenu.openActiveConfigFolder), keyEquivalent: "c"))
self.addItem(NSMenuItem(title: "mi_phpinfo".localized, action: #selector(MainMenu.openPhpInfo), keyEquivalent: "i"))
self.addItem(NSMenuItem.separator()) self.addItem(NSMenuItem.separator())
self.addItem(NSMenuItem(title: "Enabled Extensions", action: nil, keyEquivalent: "")) self.addItem(NSMenuItem(title: "mi_enabled_extensions".localized, action: nil, keyEquivalent: ""))
self.addXdebugMenuItem() self.addXdebugMenuItem()
} }
} }
@ -68,7 +77,7 @@ class StatusMenu : NSMenu {
if (xdebugFound) { if (xdebugFound) {
let xdebugOn = App.shared.currentVersion!.xdebugEnabled let xdebugOn = App.shared.currentVersion!.xdebugEnabled
let xdebugToggleMenuItem = NSMenuItem( let xdebugToggleMenuItem = NSMenuItem(
title: "Xdebug", title: "mi_xdebug".localized,
action: #selector(MainMenu.toggleXdebug), keyEquivalent: "x" action: #selector(MainMenu.toggleXdebug), keyEquivalent: "x"
) )
if (xdebugOn) { if (xdebugOn) {
@ -77,7 +86,7 @@ class StatusMenu : NSMenu {
self.addItem(xdebugToggleMenuItem) self.addItem(xdebugToggleMenuItem)
} else { } else {
let disabledItem = NSMenuItem( let disabledItem = NSMenuItem(
title: "xdebug.so missing", title: "mi_xdebug_missing".localized,
action: nil, keyEquivalent: "x" action: nil, keyEquivalent: "x"
) )
disabledItem.isEnabled = false disabledItem.isEnabled = false

View File

@ -12,15 +12,17 @@ class Constants {
/** /**
* The PHP versions supported by this application. * The PHP versions supported by this application.
* Versions that do not appear in this array are omitted from the list.
*/ */
static let SupportedPhpVersions = [ static let SupportedPhpVersions = [
"5.6", "7.0", "7.1", "7.2", "7.3", "7.4" "5.6",
"7.0",
"7.1",
"7.2",
"7.3",
"7.4",
"8.0",
"8.1"
] ]
/**
Which php version is aliased as `php` to brew?
This is usually the latest PHP version.
*/
static let LatestPhpVersion = "7.4"
} }

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ApplicationDescription</key>
<string>PHP Monitor is a tool that shows the active PHP version in your menu bar and gives you easy access to certain PHP service actions and config files.</string>
<key>DeveloperName</key>
<string>Nico Verbruggen</string>
<key>Website</key>
<string>https://github.com/nicoverbruggen/phpmon</string>
<key>Connections</key>
<array>
<dict>
<key>IsIncoming</key>
<false/>
<key>Host</key>
<string>registry.npmjs.org</string>
<key>NetworkProtocol</key>
<string>TCP</string>
<key>Port</key>
<string>80, 443</string>
<key>Relevance</key>
<string>Essential</string>
<key>Purpose</key>
<string>PHP Monitor directly invokes Homebrew which contacts the NPM Registry.</string>
<key>DenyConsequences</key>
<string>If you deny these connections, PHP Monitor might not be able to complete its preset set of instructions, causing version switching to fail.</string>
</dict>
<dict>
<key>IsIncoming</key>
<false/>
<key>Host</key>
<string>github.com, api.github.com</string>
<key>NetworkProtocol</key>
<string>TCP</string>
<key>Port</key>
<string>443</string>
<key>Relevance</key>
<string>Essential</string>
<key>Purpose</key>
<string>PHP Monitor directly invokes Homebrew which contacts GitHub. This happens when PHP Monitor asks for more information about the PHP formula to determine which version of PHP you&apos;ve got running.</string>
<key>DenyConsequences</key>
<string>If you deny these connections, PHP Monitor might not be able to complete its preset set of instructions, causing version switching to fail.</string>
</dict>
</array>
</dict>
</plist>

View File

@ -0,0 +1,2 @@
// Top-level, general application description:
"ApplicationDescription" = "PHP Monitor is a tool that shows the active PHP version in your menu bar and gives you easy access to certain PHP service actions and config files.";

View File

@ -6,6 +6,42 @@
Copyright © 2020 Nico Verbruggen. All rights reserved. Copyright © 2020 Nico Verbruggen. All rights reserved.
*/ */
// MENU ITEMS (MI)
"mi_busy" = "PHP Monitor is busy...";
"mi_unsure" = "We are not sure what version of PHP you are running.";
"mi_php_version" = "You are running PHP";
"mi_php_switch" = "Switch to PHP";
"mi_php_broken_1" = "Oof! It appears your PHP installation is broken...";
"mi_php_broken_2" = "Try running `php -v` in your terminal.";
"mi_php_broken_3" = "You could also try switching to another version.";
"mi_php_broken_4" = "Running `brew reinstall php` (or for the equivalent version) might help.";
"mi_diagnostics" = "Diagnostics";
"mi_active_services" = "Active Services";
"mi_restart_php_fpm" = "Restart service: php";
"mi_restart_nginx" = "Restart service: nginx";
"mi_restart_dnsmasq" = "Restart service: dnsmasq";
"mi_restart_all_services" = "Restart all services";
"mi_force_load_latest" = "Force load latest PHP version";
"mi_configuration" = "Configuration";
"mi_valet_config" = "Locate Valet folder (.config/valet)";
"mi_php_config" = "Locate PHP configuration file (php.ini)";
"mi_phpinfo" = "Show current configuration (phpinfo)";
"mi_enabled_extensions" = "Enabled Extensions";
"mi_xdebug" = "Xdebug";
"mi_xdebug_missing" = "xdebug.so missing";
"mi_quit" = "Quit PHP Monitor";
"mi_about" = "About PHP Monitor";
// NOTIFICATIONS
"notification.version_changed_title" = "PHP %@ now active";
"notification.version_changed_desc" = "PHP Monitor has finished the switch to PHP %@.";
// ALERTS // ALERTS
// Force Reload Started // Force Reload Started
@ -14,4 +50,36 @@
// Force Reload Done // Force Reload Done
"alert.force_reload_done.title" = "PHP has been force reloaded"; "alert.force_reload_done.title" = "PHP has been force reloaded";
"alert.force_reload_done.info" = "All appropriate services have been restarted, and the latest version of PHP is now active. You can now try switching to another version of PHP."; "alert.force_reload_done.info" = "All appropriate services have been restarted, and the latest version of PHP is now active. You can now try switching to another version of PHP. If visiting sites still does not work, you may try running `valet install` again, this can fix a 502 issue (Bad Gateway).";
// PHP Monitor Cannot Start
"alert.cannot_start.title" = "PHP Monitor cannot start";
"alert.cannot_start.info" = "The issue you were just notified about is keeping PHP Monitor from functioning correctly. Please fix the issue and restart PHP Monitor. After clicking on OK, PHP Monitor will close.\n\nIf you have fixed the issue (or don't remember what the exact issue is) you can click on Retry, which will have PHP Monitor retry the startup checks.";
"alert.cannot_start.close" = "Close";
"alert.cannot_start.retry" = "Retry";
// STARTUP
/// 1. PHP binary not found
"startup.errors.php_binary.title" = "PHP is not correctly installed";
"startup.errors.php_binary_desc" = "You must install PHP via brew. Try running `which php` in Terminal, it should return `/usr/local/bin/php` (or `/opt/homebrew/bin/php`). The app will not work correctly until you resolve this issue. (Usually `brew link php` resolves this issue.)";
/// 2. PHP not found in /usr/local/opt or /opt/homebrew/opt
"startup.errors.php_opt.title" = "PHP is not correctly installed";
"startup.errors.php_opt.desc" = "PHP alias was not found in `/usr/local/opt` (or `/opt/homebrew/opt`). The app will not work correctly until you resolve this issue. If you already have the `php` formula installed, you may need to run `brew install php` in order for PHP Monitor to detect this installation.";
/// 3. Valet not installed
"startup.errors.valet_executable.title" = "Laravel Valet is not correctly installed";
"startup.errors.valet_executable.desc" = "You must install Valet with composer. Try running `which valet` in Terminal, it should return `/usr/local/bin/valet`. The app will not work correctly until you resolve this issue.";
/// 4. Brew & sudoers
"startup.errors.sudoers_brew.title" = "Brew has not been added to sudoers.d";
"startup.errors.sudoers_brew.desc" = "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.";
/// 5. Valet & sudoers
"startup.errors.sudoers_valet.title" = "Valet has not been added to sudoers.d";
"startup.errors.sudoers_valet.desc" = "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.";
/// 6. Multiple services active
"startup.errors.services.title" = "Multiple PHP services are active";
"startup.errors.services.desc" = "This can cause php-fpm to serve a more recent version of PHP than the one you'd like to see active. Please terminate all extra PHP processes.\n\nThe easiest solution is to choose the option 'Force load latest PHP version' in the menu bar.\n\nAlternatively, you can fix this manually. You can do this by running `brew services list` and running `sudo brew services stop php@7.3` (and use the version that applies).\n\nPHP Monitor usually handles the starting and stopping of these services, so once the correct version is the only PHP version running you should not have any issues. It is recommended to restart PHP Monitor once you have resolved this issue.\n\nFor more information about this issue, please see the README.md file in the repository on GitHub.";

View File

@ -33,8 +33,23 @@ class App {
var timer: Timer? var timer: Timer?
/** /**
The window controller that will show the log. Information we were able to discern from the Homebrew info command (as JSON).
*/ */
var windowController: NSWindowController? = nil var brewPhpPackage: HomebrewPackage? = nil {
didSet {
self.brewPhpVersion = self.brewPhpPackage!.getVersion()
}
}
/**
The version that the `php` formula via Brew is aliased to on the current system.
If you're up to date, `php` will be aliased to the latest version,
but that might not be the case.
We'll technically default to version 8.0, but the information should always be loaded
from Homebrew itself upon starting the application.
*/
var brewPhpVersion: String = "8.0"
} }

View File

@ -9,8 +9,13 @@
import Cocoa import Cocoa
class Command { class Command {
/// Immediately executes a command. /**
Immediately executes a command.
- Parameter path: The path of the command or program to invoke.
- Parameter arguments: A list of arguments that are passed on.
*/
public static func execute(path: String, arguments: [String]) -> String { public static func execute(path: String, arguments: [String]) -> String {
let task = Process() let task = Process()
task.launchPath = path task.launchPath = path

View File

@ -12,31 +12,71 @@ class MainMenu: NSObject, NSWindowDelegate {
static let shared = MainMenu() static let shared = MainMenu()
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) /**
The status bar item with variable length.
*/
let statusItem = NSStatusBar.system.statusItem(
withLength: NSStatusItem.variableLength
)
// MARK: - UI related // MARK: - UI related
/**
Kick off the startup of the rendering of the main menu.
*/
public func startup() { public func startup() {
// Start with the icon // Start with the icon
self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!) self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!)
// Perform environment boot checks // Perform environment boot checks
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
Startup.checkEnvironment() Startup().checkEnvironment(success: {
App.shared.availablePhpVersions = Actions.detectPhpVersions() self.onEnvironmentPass()
self.updatePhpVersionInStatusBar() }, failure: {
// Schedule a request to fetch the PHP version every 60 seconds self.onEnvironmentFail()
DispatchQueue.main.async { })
App.shared.timer = Timer.scheduledTimer( }
timeInterval: 60, }
target: self,
selector: #selector(self.updatePhpVersionInStatusBar), /**
userInfo: nil, When the environment is all clear and the app can run, let's go.
repeats: true */
) private func onEnvironmentPass() {
App.shared.availablePhpVersions = Actions.detectPhpVersions()
self.updatePhpVersionInStatusBar()
// Schedule a request to fetch the PHP version every 60 seconds
DispatchQueue.main.async {
App.shared.timer = Timer.scheduledTimer(
timeInterval: 60,
target: self,
selector: #selector(self.updatePhpVersionInStatusBar),
userInfo: nil,
repeats: true
)
}
}
/**
When the environment is not OK, present an alert to inform the user.
*/
private func onEnvironmentFail() {
DispatchQueue.main.async {
let close = Alert.present(
messageText: "alert.cannot_start.title".localized,
informativeText: "alert.cannot_start.info".localized,
buttonTitle: "alert.cannot_start.close".localized,
secondButtonTitle: "alert.cannot_start.retry".localized
)
if (!close) {
self.startup()
} else {
exit(1)
} }
} }
} }
/**
Update the menu's contents, based on what's going on.
*/
public func update() { public func update() {
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
// Create a new menu // Create a new menu
@ -55,8 +95,8 @@ class MainMenu: NSObject, NSWindowDelegate {
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())
// Add about & quit menu items // Add about & quit menu items
menu.addItem(NSMenuItem(title: "About PHP Monitor", action: #selector(self.openAbout), keyEquivalent: "")) menu.addItem(NSMenuItem(title: "mi_about".localized, action: #selector(self.openAbout), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Quit PHP Monitor", action: #selector(self.terminateApp), keyEquivalent: "q")) menu.addItem(NSMenuItem(title: "mi_quit".localized, action: #selector(self.terminateApp), keyEquivalent: "q"))
// Make sure every item can be interacted with // Make sure every item can be interacted with
menu.items.forEach({ (item) in menu.items.forEach({ (item) in
@ -70,10 +110,19 @@ class MainMenu: NSObject, NSWindowDelegate {
} }
} }
/**
Sets the status bar image based on a version string.
*/
func setStatusBarImage(version: String) { func setStatusBarImage(version: String) {
self.setStatusBar(image: MenuBarImageGenerator.textToImage(text: version)) self.setStatusBar(
image: MenuBarImageGenerator.textToImage(text: version)
)
} }
/**
Sets the status bar image, based on the provided NSImage.
The image will be used as a template image.
*/
func setStatusBar(image: NSImage) { func setStatusBar(image: NSImage) {
if let button = statusItem.button { if let button = statusItem.button {
image.isTemplate = true image.isTemplate = true
@ -83,6 +132,14 @@ class MainMenu: NSObject, NSWindowDelegate {
// MARK: - Nicer callbacks // MARK: - Nicer callbacks
/**
Executes a specific callback and fires the completion callback,
while updating the UI as required. As long as the completion callback
does not fire, the app is presumed to be busy and the UI reflects this.
- Parameter execute: Escaping callback of the work that needs to happen.
- Parameter completion: Callback that is fired when the work is done.
*/
private func waitAndExecute(_ execute: @escaping () -> Void, _ completion: @escaping () -> Void = {}) private func waitAndExecute(_ execute: @escaping () -> Void, _ completion: @escaping () -> Void = {})
{ {
App.shared.busy = true App.shared.busy = true
@ -99,7 +156,7 @@ class MainMenu: NSObject, NSWindowDelegate {
} }
} }
// MARK: - Actions // MARK: - User Interface
@objc func updatePhpVersionInStatusBar() { @objc func updatePhpVersionInStatusBar() {
App.shared.currentVersion = PhpVersion() App.shared.currentVersion = PhpVersion()
@ -121,31 +178,58 @@ class MainMenu: NSObject, NSWindowDelegate {
} }
} }
// MARK: - Actions
@objc public func restartPhpFpm() { @objc public func restartPhpFpm() {
self.waitAndExecute({ self.waitAndExecute({
Actions.restartPhpFpm() Actions.restartPhpFpm()
}) })
} }
@objc public func restartAllServices() {
self.waitAndExecute({
Actions.restartDnsMasq()
Actions.restartPhpFpm()
Actions.restartNginx()
})
}
@objc public func restartNginx() { @objc public func restartNginx() {
self.waitAndExecute({ self.waitAndExecute({
Actions.restartNginx() Actions.restartNginx()
}) })
} }
@objc public func restartDnsMasq() {
self.waitAndExecute({
Actions.restartDnsMasq()
})
}
@objc public func toggleXdebug() { @objc public func toggleXdebug() {
self.waitAndExecute({ self.waitAndExecute({
Actions.toggleXdebug() Actions.toggleXdebug()
}) })
} }
@objc public func openPhpInfo() {
self.waitAndExecute({
try! "<?php phpinfo();".write(toFile: "/tmp/phpmon_phpinfo.php", atomically: true, encoding: .utf8)
Shell.user.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")!)
})
}
@objc public func forceRestartLatestPhp() { @objc public func forceRestartLatestPhp() {
Alert.present( // Tell the user the switch is about to occur
_ = Alert.present(
messageText: "alert.force_reload.title".localized, messageText: "alert.force_reload.title".localized,
informativeText: "alert.force_reload.info".localized informativeText: "alert.force_reload.info".localized
) )
// Start switching
self.waitAndExecute({ Actions.fixMyPhp() }, { self.waitAndExecute({ Actions.fixMyPhp() }, {
Alert.present( _ = Alert.present(
messageText: "alert.force_reload_done.title".localized, messageText: "alert.force_reload_done.title".localized,
informativeText: "alert.force_reload_done.info".localized informativeText: "alert.force_reload_done.info".localized
) )
@ -167,10 +251,9 @@ class MainMenu: NSObject, NSWindowDelegate {
Actions.openValetConfigFolder() Actions.openValetConfigFolder()
} }
@objc public func switchToPhpVersion(sender: AnyObject) { @objc public func switchToPhpVersion(sender: PhpMenuItem) {
print("Switching to: PHP \(sender.version)")
self.setBusyImage() self.setBusyImage()
let index = sender.tag!
let version = App.shared.availablePhpVersions[index]
App.shared.busy = true App.shared.busy = true
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
// Update the PHP version in the status bar // Update the PHP version in the status bar
@ -179,7 +262,7 @@ class MainMenu: NSObject, NSWindowDelegate {
self.update() self.update()
// Switch the PHP version // Switch the PHP version
Actions.switchToPhpVersion( Actions.switchToPhpVersion(
version: version, version: sender.version,
availableVersions: App.shared.availablePhpVersions availableVersions: App.shared.availablePhpVersions
) )
// Mark as no longer busy // Mark as no longer busy
@ -188,6 +271,11 @@ class MainMenu: NSObject, NSWindowDelegate {
DispatchQueue.main.async { DispatchQueue.main.async {
self.updatePhpVersionInStatusBar() self.updatePhpVersionInStatusBar()
self.update() self.update()
// Send a notification that the switch has been completed
LocalNotification.send(
title: String(format: "notification.version_changed_title".localized, sender.version),
subtitle: String(format: "notification.version_changed_desc".localized, sender.version)
)
} }
} }
} }
@ -200,11 +288,4 @@ class MainMenu: NSObject, NSWindowDelegate {
@objc public func terminateApp() { @objc public func terminateApp() {
NSApplication.shared.terminate(nil) NSApplication.shared.terminate(nil)
} }
// MARK: - Cleanup when window closes
func windowWillClose(_ notification: Notification) {
App.shared.windowController = nil
Shell.user.delegate = nil
}
} }

View File

@ -0,0 +1,66 @@
//
// Paths.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 01/01/2021.
// Copyright © 2021 Nico Verbruggen. All rights reserved.
//
import Foundation
enum HomebrewDir: String {
case opt = "/opt/homebrew"
case usr = "/usr/local"
}
class Paths {
static let shared = Paths()
var baseDir : HomebrewDir
init() {
let optBrewFound = Shell.fileExists("\(HomebrewDir.opt.rawValue)/bin/brew")
let usrBrewFound = Shell.fileExists("\(HomebrewDir.usr.rawValue)/bin/brew")
if (optBrewFound) {
// This is usually the case with Homebrew installed on Apple Silicon
self.baseDir = .opt
} else if (usrBrewFound) {
// This is usually the case with Homebrew installed on Intel (or Rosetta 2)
self.baseDir = .usr
} else {
// Falling back to default "legacy" Homebrew location (for Intel)
print("Seems like we couldn't determine the Homebrew directory.")
print("This usually means we're in trouble... (no Homebrew?)")
self.baseDir = .usr
}
print("Homebrew directory: \(self.baseDir)")
}
// - MARK: Binaries
public static func brew() -> String {
return "\(self.binPath())/brew"
}
public static func php() -> String {
return "\(self.binPath())/php"
}
// - MARK: Paths
public static func binPath() -> String {
return "\(self.shared.baseDir.rawValue)/bin"
}
public static func optPath() -> String {
return "\(self.shared.baseDir.rawValue)/opt"
}
public static func etcPath() -> String {
return "\(self.shared.baseDir.rawValue)/etc"
}
}

View File

@ -8,61 +8,51 @@
import Cocoa import Cocoa
protocol ShellDelegate: class {
func didCompleteCommand(historyItem: ShellHistoryItem)
}
class ShellHistoryItem {
var command: String
var output: String
var date: Date
init(command: String, output: String) {
self.command = command
self.output = output
self.date = Date()
}
}
class Shell { class Shell {
// Singleton to access a user shell (with --login) /**
Singleton to access a user shell (with --login)
*/
static let user = Shell() static let user = Shell()
var history : [ShellHistoryItem] = [] /**
Runs a shell command without using the output.
var delegate : ShellDelegate? Uses the default shell.
/// Runs a shell command without using the description. - Parameter command: The command to run
*/
public func run(_ command: String) { public func run(_ command: String) {
// Equivalent of piping to /dev/null; don't do anything with the string // Equivalent of piping to /dev/null; don't do anything with the string
_ = self.pipe(command) _ = self.pipe(command)
} }
/// Runs a shell command and returns the output. /**
Runs a shell command and returns the output.
- Parameter command: The command to run
- Parameter shell: Path to the shell to invoke
*/
public func pipe(_ command: String, shell: String = "/bin/sh") -> String { public func pipe(_ command: String, shell: String = "/bin/sh") -> String {
let task = Process() let task = Process()
let pipe = Pipe()
task.launchPath = shell task.launchPath = shell
task.arguments = ["--login", "-c", command] task.arguments = ["--login", "-c", command]
let pipe = Pipe()
task.standardOutput = pipe task.standardOutput = pipe
task.launch() task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! as String
let historyItem = ShellHistoryItem(command: command, output: output)
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
self.history.append(historyItem)
// Keep the last 100 items
self.history = self.history.suffix(100)
}
delegate?.didCompleteCommand(historyItem: historyItem)
return output return String(
data: pipe.fileHandleForReading.readDataToEndOfFile(),
encoding: .utf8
)!
}
/**
Checks if a file exists at the provided path.
*/
public static func fileExists(_ path: String) -> Bool {
return Shell.user.pipe(
"if [ -f \(path) ]; then echo \"PHP_Y_FE\"; fi"
).contains("PHP_Y_FE")
} }
} }

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17506"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
<!--Application--> <!--Application-->
@ -55,68 +54,5 @@
</objects> </objects>
<point key="canvasLocation" x="-343" y="-16"/> <point key="canvasLocation" x="-343" y="-16"/>
</scene> </scene>
<!--Log View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController storyboardIdentifier="logWindow" id="XfG-lQ-9wD" customClass="LogViewController" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" identifier="main" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="662" height="475"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ICa-gx-jgq">
<rect key="frame" x="578" y="8" width="75" height="32"/>
<buttonCell key="cell" type="push" title="Close" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="3md-FI-EWa">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="pressed:" target="XfG-lQ-9wD" id="fIC-Bz-vTK"/>
</connections>
</button>
<scrollView borderType="line" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vZy-5S-021">
<rect key="frame" x="15" y="46" width="632" height="414"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="s5L-AU-0fw">
<rect key="frame" x="1" y="1" width="630" height="412"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView importsGraphics="NO" richText="NO" verticallyResizable="YES" smartInsertDelete="YES" id="tN6-Y9-1pA">
<rect key="frame" x="0.0" y="0.0" width="630" height="412"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="630" height="412"/>
<size key="maxSize" width="640" height="10000000"/>
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="Kho-JF-NZJ">
<rect key="frame" x="-100" y="-100" width="240" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="qp7-7R-gTO">
<rect key="frame" x="615" y="1" width="16" height="412"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
</subviews>
<constraints>
<constraint firstItem="vZy-5S-021" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" constant="15" id="K0k-oE-r37"/>
<constraint firstAttribute="trailing" secondItem="ICa-gx-jgq" secondAttribute="trailing" constant="15" id="LFS-0E-Ibw"/>
<constraint firstItem="vZy-5S-021" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" constant="15" id="Nec-oI-CjE"/>
<constraint firstAttribute="trailing" secondItem="vZy-5S-021" secondAttribute="trailing" constant="15" id="kBJ-O5-eYI"/>
<constraint firstAttribute="bottom" secondItem="ICa-gx-jgq" secondAttribute="bottom" constant="15" id="kYB-Fn-DSA"/>
<constraint firstItem="ICa-gx-jgq" firstAttribute="top" secondItem="vZy-5S-021" secondAttribute="bottom" constant="10" id="xdn-yU-LVb"/>
</constraints>
</view>
<connections>
<outlet property="textView" destination="tN6-Y9-1pA" id="z77-me-Od6"/>
</connections>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-105" y="377.5"/>
</scene>
</scenes> </scenes>
</document> </document>