mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
🐛 Enforce readable Valet version
This commit is contained in:
@ -49,6 +49,16 @@ class Startup {
|
||||
breaking: true
|
||||
)
|
||||
|
||||
Valet.shared.version = VersionExtractor.from(valet("--version"))
|
||||
performEnvironmentCheck(
|
||||
Valet.shared.version == nil,
|
||||
messageText: "startup.errors.valet_version_unknown.title".localized,
|
||||
informativeText: "startup.errors.valet_version_unknown.desc".localized(
|
||||
"prefs.auto_composer_update_title".localized
|
||||
),
|
||||
breaking: true
|
||||
)
|
||||
|
||||
performEnvironmentCheck(
|
||||
HomebrewDiagnostics.cannotLoadService(),
|
||||
messageText: "startup.errors.services_json_error.title".localized,
|
||||
|
@ -14,27 +14,31 @@ class VersionExtractor {
|
||||
This attempts to extract the version number from the command line output of Valet.
|
||||
*/
|
||||
public static func from(_ string: String) -> String? {
|
||||
let regex = try! NSRegularExpression(
|
||||
pattern: #"Laravel Valet (?<version>(\d+)(.)(\d+)((.)(\d+))?)"#,
|
||||
options: []
|
||||
)
|
||||
|
||||
let match = regex.matches(
|
||||
in: string,
|
||||
options: [],
|
||||
range: NSMakeRange(0, string.count)
|
||||
).first
|
||||
|
||||
guard let match = match else {
|
||||
do {
|
||||
let regex = try NSRegularExpression(
|
||||
pattern: #"Laravel Valet (?<version>(\d+)(.)(\d+)((.)(\d+))?)"#,
|
||||
options: []
|
||||
)
|
||||
|
||||
let match = regex.matches(
|
||||
in: string,
|
||||
options: [],
|
||||
range: NSMakeRange(0, string.count)
|
||||
).first
|
||||
|
||||
guard let match = match else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let range = Range(
|
||||
match.range(withName: "version"),
|
||||
in: string
|
||||
)!
|
||||
|
||||
return String(string[range])
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
|
||||
let range = Range(
|
||||
match.range(withName: "version"),
|
||||
in: string
|
||||
)!
|
||||
|
||||
return String(string[range])
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class Valet {
|
||||
static let shared = Valet()
|
||||
|
||||
/// The version of Valet that was detected.
|
||||
var version: String
|
||||
var version: String! = nil
|
||||
|
||||
/// The Valet configuration file.
|
||||
var config: Valet.Configuration!
|
||||
@ -26,7 +26,7 @@ class Valet {
|
||||
|
||||
/// When initialising the Valet singleton, extract the Valet version and assume no sites loaded.
|
||||
init() {
|
||||
version = VersionExtractor.from(valet("--version")) ?? "UNKNOWN"
|
||||
self.version = nil
|
||||
self.sites = []
|
||||
}
|
||||
|
||||
@ -83,18 +83,14 @@ class Valet {
|
||||
installed is not recent enough.
|
||||
*/
|
||||
public func validateVersion() -> Void {
|
||||
if version == "UNKNOWN" {
|
||||
return Log.warn("The Valet version could not be extracted... that does not bode well.")
|
||||
}
|
||||
|
||||
if version.versionCompare(Constants.MinimumRecommendedValetVersion) == .orderedAscending {
|
||||
let version = version
|
||||
Log.warn("Valet version \(version) is too old! (recommended: \(Constants.MinimumRecommendedValetVersion))")
|
||||
Log.warn("Valet version \(version!) is too old! (recommended: \(Constants.MinimumRecommendedValetVersion))")
|
||||
DispatchQueue.main.async {
|
||||
Alert.notify(message: "alert.min_valet_version.title".localized, info: "alert.min_valet_version.info".localized(version, Constants.MinimumRecommendedValetVersion))
|
||||
Alert.notify(message: "alert.min_valet_version.title".localized, info: "alert.min_valet_version.info".localized(version!, Constants.MinimumRecommendedValetVersion))
|
||||
}
|
||||
} else {
|
||||
Log.info("Valet version \(version) is recent enough, OK (recommended: \(Constants.MinimumRecommendedValetVersion))")
|
||||
Log.info("Valet version \(version!) is recent enough, OK (recommended: \(Constants.MinimumRecommendedValetVersion))")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,10 +234,14 @@ You can do this by running `composer global update` in your terminal. After that
|
||||
"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` or `/opt/homebrew/bin/valet`. The app will not work correctly until you resolve this issue. (PHP Monitor checks for the existence of `valet` in either of these paths.)";
|
||||
|
||||
/// 3b. Valet configuration file missing
|
||||
/// 3b. Valet configuration file missing [currently not enabled]
|
||||
"startup.errors.valet_config.title" = "Laravel Valet configuration file missing";
|
||||
"startup.errors.valet_config.desc" = "PHP Monitor needs to be able to read the configuration file in `~/.config/valet/config.json`.";
|
||||
|
||||
/// 3c. Valet version not readable
|
||||
"startup.errors.valet_version_unknown.title" = "Your Valet version could not be read (`valet --version` failed)";
|
||||
"startup.errors.valet_version_unknown.desc" = "Make sure your Valet installation works and is up-to-date. Try running `valet --version` in a terminal to find out what's going on. \n\n(This could be your global composer dependencies having been resolved with a higher version of PHP than you're currently running.)\n\nIt is recommended that you run `composer global update` with the lowest version of PHP you'd like to run, and enable '%@' in PHP Monitor afterwards.";
|
||||
|
||||
/// 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.";
|
||||
|
Reference in New Issue
Block a user