mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-08 13:30:06 +01:00
👌 Extra startup check for invalid config.json
- Up to 50 sites are now preloaded (up from 30) - No longer crash when invalid config.json is found (only at launch) - Added `evaluateFeatureSupport` to Valet.swift - Load configuration during launch checks instead
This commit is contained in:
@@ -34,7 +34,7 @@ struct Constants {
|
|||||||
// STABLE RELEASES
|
// STABLE RELEASES
|
||||||
// ====================
|
// ====================
|
||||||
// Versions of PHP that are stable and are supported.
|
// Versions of PHP that are stable and are supported.
|
||||||
"5.6",
|
"5.6", // only supported when Valet 2.x is active
|
||||||
"7.0",
|
"7.0",
|
||||||
"7.1",
|
"7.1",
|
||||||
"7.2",
|
"7.2",
|
||||||
|
|||||||
@@ -166,6 +166,23 @@ class Startup {
|
|||||||
descriptionText: "startup.errors.services_json_error.desc".localized
|
descriptionText: "startup.errors.services_json_error.desc".localized
|
||||||
),
|
),
|
||||||
// =================================================================================
|
// =================================================================================
|
||||||
|
// Determine that the Valet configuration JSON file is valid.
|
||||||
|
// =================================================================================
|
||||||
|
EnvironmentCheck(
|
||||||
|
command: {
|
||||||
|
// Detect additional binaries (e.g. Composer)
|
||||||
|
Paths.shared.detectBinaryPaths()
|
||||||
|
// Load the configuration file (config.json)
|
||||||
|
Valet.shared.loadConfiguration()
|
||||||
|
// This check fails when the config is nil
|
||||||
|
return Valet.shared.config == nil
|
||||||
|
},
|
||||||
|
name: "`config.json` was valid",
|
||||||
|
titleText: "startup.errors.valet_json_invalid.title".localized,
|
||||||
|
subtitleText: "startup.errors.valet_json_invalid.subtitle".localized,
|
||||||
|
descriptionText: "startup.errors.valet_json_invalid.desc".localized
|
||||||
|
),
|
||||||
|
// =================================================================================
|
||||||
// Determine the Valet version and ensure it isn't unknown.
|
// Determine the Valet version and ensure it isn't unknown.
|
||||||
// =================================================================================
|
// =================================================================================
|
||||||
EnvironmentCheck(
|
EnvironmentCheck(
|
||||||
|
|||||||
@@ -60,10 +60,12 @@ class Valet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
We don't want to load the initial config.json file as soon as the class is initialised.
|
We don't want to load the initial config.json file as soon as the class is initialised.
|
||||||
|
|
||||||
Instead, we'll defer the loading of the configuration file once the initial app checks
|
Instead, we'll defer the loading of the configuration file once the initial app checks
|
||||||
have passed: if the user does not have Valet installed, we'll crash the app because we
|
have passed: otherwise the file might not exist, leading to a crash.
|
||||||
force unwrap the file. Currently, this does also mean that if the JSON is invalid or
|
|
||||||
incompatible with the `Decodable` `Valet.Configuration` class, that the app will crash.
|
Since version 5.2, it is no longer possible for an invalid file to crash the app.
|
||||||
|
If the JSON is invalid when the app launches, an alert will be presented, however.
|
||||||
*/
|
*/
|
||||||
public func loadConfiguration() {
|
public func loadConfiguration() {
|
||||||
let file = FileManager.default.homeDirectoryForCurrentUser
|
let file = FileManager.default.homeDirectoryForCurrentUser
|
||||||
@@ -85,7 +87,7 @@ class Valet {
|
|||||||
(This is done to keep the startup speed as fast as possible.)
|
(This is done to keep the startup speed as fast as possible.)
|
||||||
*/
|
*/
|
||||||
public func startPreloadingSites() {
|
public func startPreloadingSites() {
|
||||||
let maximumPreload = 30
|
let maximumPreload = 50
|
||||||
let foundSites = self.countPaths()
|
let foundSites = self.countPaths()
|
||||||
if foundSites <= maximumPreload {
|
if foundSites <= maximumPreload {
|
||||||
// Preload the sites and their drivers
|
// Preload the sites and their drivers
|
||||||
@@ -98,7 +100,7 @@ class Valet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Reloads the list of sites, assuming that the list isn't being reloaded at the time.
|
Reloads the list of sites, assuming that the list isn't being reloaded at the time.
|
||||||
We don't want to do duplicate or parallel work!
|
(We don't want to do duplicate or parallel work!)
|
||||||
*/
|
*/
|
||||||
public func reloadSites() {
|
public func reloadSites() {
|
||||||
loadConfiguration()
|
loadConfiguration()
|
||||||
@@ -110,21 +112,34 @@ class Valet {
|
|||||||
resolvePaths()
|
resolvePaths()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Depending on the version of Valet that is active, the feature set of PHP Monitor will change.
|
||||||
|
|
||||||
|
In version 6.0, support for Valet 2.x will be dropped, but until then features are evaluated by using the helper
|
||||||
|
`enabled(feature)`, which contains information about the feature set of the version of Valet that is currently
|
||||||
|
in use. This allows PHP Monitor to do different things when Valet 3.0 is enabled.
|
||||||
|
*/
|
||||||
|
public func evaluateFeatureSupport() -> Void {
|
||||||
|
let isOlderThanVersionThree = version.versionCompare("3.0") == .orderedAscending
|
||||||
|
|
||||||
|
if isOlderThanVersionThree {
|
||||||
|
self.features.append(.supportForPhp56)
|
||||||
|
} else {
|
||||||
|
Log.info("This version of Valet supports isolation.")
|
||||||
|
self.features.append(.isolatedSites)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Checks if the version of Valet is more recent than the minimum version required for PHP Monitor to function.
|
Checks if the version of Valet is more recent than the minimum version required for PHP Monitor to function.
|
||||||
Should this procedure fail, the user will get an alert notifying them that the version of Valet they have
|
Should this procedure fail, the user will get an alert notifying them that the version of Valet they have
|
||||||
installed is not recent enough.
|
installed is not recent enough.
|
||||||
*/
|
*/
|
||||||
public func validateVersion() -> Void {
|
public func validateVersion() -> Void {
|
||||||
if version.versionCompare("3.0") == .orderedAscending {
|
// 1. Evaluate feature support
|
||||||
// < 3.0: This version still supports PHP 5.6
|
Valet.shared.evaluateFeatureSupport()
|
||||||
self.features.append(.supportForPhp56)
|
|
||||||
} else {
|
|
||||||
// >= 3.0: This version introduces isolation but drops PHP 5.6 support
|
|
||||||
Log.info("This version of Valet supports isolation.")
|
|
||||||
self.features.append(.isolatedSites)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 2. Notify user if the version is too old
|
||||||
if version.versionCompare(Constants.MinimumRecommendedValetVersion) == .orderedAscending {
|
if version.versionCompare(Constants.MinimumRecommendedValetVersion) == .orderedAscending {
|
||||||
let version = version
|
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))")
|
||||||
|
|||||||
@@ -76,9 +76,6 @@ extension MainMenu {
|
|||||||
Log.info("PHP Monitor has extracted the version number of Valet: \(Valet.shared.version!)")
|
Log.info("PHP Monitor has extracted the version number of Valet: \(Valet.shared.version!)")
|
||||||
}
|
}
|
||||||
|
|
||||||
Paths.shared.detectBinaryPaths()
|
|
||||||
|
|
||||||
Valet.shared.loadConfiguration()
|
|
||||||
Valet.shared.validateVersion()
|
Valet.shared.validateVersion()
|
||||||
Valet.shared.startPreloadingSites()
|
Valet.shared.startPreloadingSites()
|
||||||
|
|
||||||
|
|||||||
@@ -306,9 +306,10 @@ You can do this by running `composer global update` in your terminal. After that
|
|||||||
"startup.errors.valet_executable.subtitle" = "You must install Valet with Composer. The app will not work correctly until you resolve this issue.";
|
"startup.errors.valet_executable.subtitle" = "You must install Valet with Composer. The app will not work correctly until you resolve this issue.";
|
||||||
"startup.errors.valet_executable.desc" = "If you haven't installed Laravel Valet yet, please do so first. If you have it installed but are seeing this message anyway, then try running `which valet` in Terminal, it should return: `%@`.";
|
"startup.errors.valet_executable.desc" = "If you haven't installed Laravel Valet yet, please do so first. If you have it installed but are seeing this message anyway, then try running `which valet` in Terminal, it should return: `%@`.";
|
||||||
|
|
||||||
/// Valet configuration file missing [currently not enabled]
|
/// Valet configuration file missing or broken
|
||||||
"startup.errors.valet_config.title" = "Laravel Valet configuration file missing";
|
"startup.errors.valet_json_invalid.title" = "Laravel Valet configuration file invalid or missing";
|
||||||
"startup.errors.valet_config.desc" = "PHP Monitor needs to be able to read the configuration file in `~/.config/valet/config.json`.";
|
"startup.errors.valet_json_invalid.subtitle" = "PHP Monitor needs to be able to read the configuration file. It appears the file is malformed or missing. Please check that it exists and is formatted correctly.";
|
||||||
|
"startup.errors.valet_json_invalid.desc" = "You can find the file at `~/.config/valet/config.json`. If Laravel Valet cannot parse the configuration file, running any `valet` command will usually automatically fix the JSON file. Try running `valet --version` to automatically fix the file.";
|
||||||
|
|
||||||
/// Valet version not readable
|
/// Valet version not readable
|
||||||
"startup.errors.valet_version_unknown.title" = "Your Valet version could not be read";
|
"startup.errors.valet_version_unknown.title" = "Your Valet version could not be read";
|
||||||
|
|||||||
Reference in New Issue
Block a user