1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-08 05:30:05 +01:00

👌 Handle additional states

This commit is contained in:
2022-06-08 18:26:06 +02:00
parent 1040bcd037
commit 1fdf687c15
4 changed files with 103 additions and 58 deletions

View File

@@ -25,22 +25,24 @@ extension ValetSite {
self.composerPhp = constraint self.composerPhp = constraint
self.composerPhpSource = constraint != "" ? .require : .unknown self.composerPhpSource = constraint != "" ? .require : .unknown
self.composerPhpCompatibleWithLinked = self.composerPhp.split(separator: "|")
.map { string in
return !PhpVersionNumberCollection.make(from: [PhpEnv.phpInstall.version.long])
.matching(constraint: string.trimmingCharacters(in: .whitespacesAndNewlines))
.isEmpty
}.contains(true)
self.driver = driver self.driver = driver
self.driverDeterminedByComposer = true self.driverDeterminedByComposer = true
if linked { if linked {
self.aliasPath = self.absolutePath self.aliasPath = self.absolutePath
} }
if let isolated = isolated { if let isolated = isolated {
self.isolatedPhpVersion = PhpInstallation(isolated) self.isolatedPhpVersion = PhpInstallation(isolated)
} }
self.composerPhpCompatibleWithLinked = self.composerPhp.split(separator: "|")
.map { string in
let origin = self.isolatedPhpVersion?.versionNumber.homebrewVersion ?? PhpEnv.phpInstall.version.long
return !PhpVersionNumberCollection.make(from: [origin])
.matching(constraint: string.trimmingCharacters(in: .whitespacesAndNewlines))
.isEmpty
}.contains(true)
} }
} }

View File

@@ -81,9 +81,9 @@ class ValetSite: DomainListable {
if makeDeterminations { if makeDeterminations {
determineSecured() determineSecured()
determineIsolated()
determineComposerPhpVersion() determineComposerPhpVersion()
determineDriver() determineDriver()
determineIsolated()
} }
} }
@@ -133,7 +133,6 @@ class ValetSite: DomainListable {
with the currently linked version of PHP (see `composerPhpMatchesSystem`). with the currently linked version of PHP (see `composerPhpMatchesSystem`).
*/ */
public func determineComposerPhpVersion() { public func determineComposerPhpVersion() {
self.determineComposerInformation() self.determineComposerInformation()
self.determineValetPhpFileInfo() self.determineValetPhpFileInfo()
@@ -145,7 +144,8 @@ class ValetSite: DomainListable {
// For example, for Laravel 8 projects the value is "^7.3|^8.0" // For example, for Laravel 8 projects the value is "^7.3|^8.0"
self.composerPhpCompatibleWithLinked = self.composerPhp.split(separator: "|") self.composerPhpCompatibleWithLinked = self.composerPhp.split(separator: "|")
.map { string in .map { string in
return !PhpVersionNumberCollection.make(from: [PhpEnv.phpInstall.version.long]) let origin = self.isolatedPhpVersion?.versionNumber.homebrewVersion ?? PhpEnv.phpInstall.version.long
return !PhpVersionNumberCollection.make(from: [origin])
.matching(constraint: string.trimmingCharacters(in: .whitespacesAndNewlines)) .matching(constraint: string.trimmingCharacters(in: .whitespacesAndNewlines))
.isEmpty .isEmpty
}.contains(true) }.contains(true)

View File

@@ -16,7 +16,63 @@ struct VersionPopoverView: View {
@State var parent: NSPopover! @State var parent: NSPopover!
func getTitle() -> String { var body: some View {
VStack(alignment: .leading, spacing: 10) {
Text(getTitleText())
.fontWeight(.bold)
.fixedSize(horizontal: false, vertical: true)
Text(getSourceText())
.fixedSize(horizontal: false, vertical: true)
.font(.subheadline)
if !validPhpVersions.isEmpty {
// Suggestions for alternative PHP versions
VStack(alignment: .leading, spacing: 10) {
DisclaimerView(
iconName: "info.circle.fill",
message: "alert.php_suggestions".localized,
color: Color("AppColor")
)
HStack {
ForEach(validPhpVersions, id: \.self) { version in
Button("site_link.switch_to_php".localized(version.homebrewVersion), action: {
MainMenu.shared.switchToPhpVersion(version.homebrewVersion)
parent?.close()
})
}
}.padding(EdgeInsets(top: 10, leading: 0, bottom: 0, trailing: 0))
}
} else {
if site.composerPhpSource == .unknown {
// We don't know which PHP version is required
DisclaimerView(
iconName: "questionmark.circle.fill",
message: "alert.unable_to_determine_is_fine".localized
)
} else {
if site.composerPhpCompatibleWithLinked {
DisclaimerView(
iconName: "checkmark.circle.fill",
message: "alert.php_version_ideal".localized,
color: Color("IconColorGreen")
)
} else {
DisclaimerView(
iconName: "exclamationmark.circle.fill",
message: "alert.php_version_incorrect".localized,
color: Color("IconColorRed")
)
}
}
}
}.frame(width: 400, height: nil, alignment: .center)
.padding(20)
.background(
Color(NSColor.windowBackgroundColor)
.padding(-80)
)
}
func getTitleText() -> String {
if site.composerPhpSource == .unknown { if site.composerPhpSource == .unknown {
return "alert.composer_php_requirement.unable_to_determine".localized return "alert.composer_php_requirement.unable_to_determine".localized
} }
@@ -27,7 +83,7 @@ struct VersionPopoverView: View {
) )
} }
func getSource() -> String { func getSourceText() -> String {
var information = "" var information = ""
if site.isolatedPhpVersion != nil { if site.isolatedPhpVersion != nil {
@@ -43,52 +99,6 @@ struct VersionPopoverView: View {
return information return information
} }
var body: some View {
VStack(alignment: .leading, spacing: 10) {
Text(getTitle())
.fontWeight(.bold)
.fixedSize(horizontal: false, vertical: true)
Text(getSource())
.fixedSize(horizontal: false, vertical: true)
.font(.subheadline)
if !validPhpVersions.isEmpty {
// Suggestions for alternative PHP versions
VStack(alignment: .leading, spacing: 10) {
DisclaimerView(
iconName: "info.circle",
message: "alert.php_suggestions".localized,
color: Color("AppColor")
)
HStack {
ForEach(validPhpVersions, id: \.self) { version in
Button("site_link.switch_to_php".localized(version.homebrewVersion), action: {
MainMenu.shared.switchToPhpVersion(version.homebrewVersion)
parent?.close()
})
}
}
}
} else {
if site.composerPhpSource != .unknown {
DisclaimerView(
iconName: "checkmark.seal.fill",
message: "alert.php_version_ideal".localized,
color: Color("IconColorGreen")
)
} else {
DisclaimerView(
iconName: "questionmark.circle",
message: "alert.unable_to_determine_is_fine".localized
)
}
}
}.frame(width: 400, height: nil, alignment: .center)
.padding(20)
.background(
Color(NSColor.windowBackgroundColor).padding(-80)
)
}
} }
struct DisclaimerView: View { struct DisclaimerView: View {
@@ -122,6 +132,8 @@ struct VersionPopoverView_Previews: PreviewProvider {
validPhpVersions: [], validPhpVersions: [],
parent: nil parent: nil
) )
.previewDisplayName("Unknown Requirement")
VersionPopoverView( VersionPopoverView(
site: ValetSite( site: ValetSite(
fakeWithName: "amazingwebsite", fakeWithName: "amazingwebsite",
@@ -134,6 +146,35 @@ struct VersionPopoverView_Previews: PreviewProvider {
validPhpVersions: [], validPhpVersions: [],
parent: nil parent: nil
) )
.previewDisplayName("Requirement Matches")
VersionPopoverView(
site: ValetSite(
fakeWithName: "anothersite",
tld: "test",
secure: true,
path: "/path/to/site",
linked: true,
constraint: "^8.0",
isolated: "8.0"
),
validPhpVersions: [],
parent: nil
)
.previewDisplayName("Isolated")
VersionPopoverView(
site: ValetSite(
fakeWithName: "anothersite",
tld: "test",
secure: true,
path: "/path/to/site",
linked: true,
constraint: "^8.0",
isolated: "7.4"
),
validPhpVersions: [],
parent: nil
)
.previewDisplayName("Isolated Mismatch")
VersionPopoverView( VersionPopoverView(
site: ValetSite( site: ValetSite(
fakeWithName: "anothersite", fakeWithName: "anothersite",
@@ -149,5 +190,6 @@ struct VersionPopoverView_Previews: PreviewProvider {
], ],
parent: nil parent: nil
) )
.previewDisplayName("Recommend Alternatives")
} }
} }

View File

@@ -312,6 +312,7 @@ problem manually, using your own Terminal app (this just shows you the output)."
"alert.composer_php_requirement.type.valetphprc" = "This required PHP version was determined by checking the .valetphprc file in your project's directory."; "alert.composer_php_requirement.type.valetphprc" = "This required PHP version was determined by checking the .valetphprc file in your project's directory.";
"alert.unable_to_determine_is_fine" = "If you have a simple project, there may not be a specified PHP version set as a requirement. In that case, you are free to ignore this warning."; "alert.unable_to_determine_is_fine" = "If you have a simple project, there may not be a specified PHP version set as a requirement. In that case, you are free to ignore this warning.";
"alert.php_version_ideal" = "The currently active PHP version is ideal for this site."; "alert.php_version_ideal" = "The currently active PHP version is ideal for this site.";
"alert.php_version_incorrect" = "The currently active PHP version does not match the required constraint set for this site.";
"alert.php_suggestions" = "There may be a different PHP version which is closer to the constraint."; "alert.php_suggestions" = "There may be a different PHP version which is closer to the constraint.";
// Suggest Fix My Valet // Suggest Fix My Valet