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

🏗 Added initial TODO items for #148

This commit is contained in:
2022-03-14 19:13:38 +01:00
parent ba4ed3b365
commit 48b4f9b160
5 changed files with 44 additions and 25 deletions

View File

@ -34,6 +34,8 @@ class InternalSwitcher: PhpSwitcher {
? "php" : "php@\(available)"
brew("unlink \(formula)")
// TODO: (ISOLATION) Only stop formulae that are not used for isolation
brew("services stop \(formula)", sudo: true)
Log.perf("Unlinked and stopped services for \(formula)")

View File

@ -41,7 +41,7 @@ class Valet {
let file = FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent(".config/valet/config.json")
// TODO: (5.1) Fix loading of invalid JSON: do not crash the app
// TODO: (5.2) Fix loading of invalid JSON: do not crash the app
config = try! JSONDecoder().decode(
Valet.Configuration.self,
from: try! String(contentsOf: file, encoding: .utf8).data(using: .utf8)!
@ -83,6 +83,10 @@ class Valet {
installed is not recent enough.
*/
public func validateVersion() -> Void {
if version.versionCompare("3.0") == .orderedAscending {
Log.warn("This version of Valet does not support isolation yet. Disabling isolation checks.")
}
if version.versionCompare(Constants.MinimumRecommendedValetVersion) == .orderedAscending {
let version = version
Log.warn("Valet version \(version!) is too old! (recommended: \(Constants.MinimumRecommendedValetVersion))")

View File

@ -11,10 +11,10 @@ import Foundation
class ValetSite {
/// Name of the site. Does not include the TLD.
var name: String!
var name: String
/// The absolute path to the directory that is served.
var absolutePath: String!
var absolutePath: String
/// The absolute path to the directory that is served,
/// replacing the user's home folder with ~.
@ -23,6 +23,12 @@ class ValetSite {
.replacingOccurrences(of: "/Users/\(Paths.whoami)", with: "~")
}()
/// The TLD used to locate this site.
var tld: String = "test"
/// The PHP version that is being used to serve this site specifically (if not global).
var isolatedPhpVersion: PhpInstallation?
/// Location of the alias. If set, this is a linked domain.
var aliasPath: String?
@ -54,34 +60,41 @@ class ValetSite {
case valetphprc = "valetphprc"
}
init() {}
convenience init(absolutePath: String, tld: String) {
self.init()
init(absolutePath: String, tld: String) {
self.absolutePath = absolutePath
self.tld = tld
self.name = URL(fileURLWithPath: absolutePath).lastPathComponent
self.aliasPath = nil
determineSecured(tld)
determineSecured()
determineComposerPhpVersion()
determineDriver()
}
convenience init(aliasPath: String, tld: String) {
self.init()
self.absolutePath = try! FileManager.default.destinationOfSymbolicLink(atPath: aliasPath)
let absolutePath = try! FileManager.default.destinationOfSymbolicLink(atPath: aliasPath)
self.init(absolutePath: absolutePath, tld: tld)
self.name = URL(fileURLWithPath: aliasPath).lastPathComponent
self.aliasPath = aliasPath
determineSecured(tld)
determineSecured()
determineComposerPhpVersion()
determineDriver()
}
public func determineIsolated() {
// TODO: (ISOLATION) Determine whether the domain is isolated by checking for `# Valet isolated PHP version`
// This needs to be checked in: "~/.config/valet/Nginx/\(self.name).\(self.tld)"
self.isolatedPhpVersion = nil
}
/**
Checks if a certificate file can be found in the `valet/Certificates` directory.
- Note: The file is not validated, only its presence is checked.
*/
public func determineSecured(_ tld: String) {
secured = Filesystem.fileExists("~/.config/valet/Certificates/\(self.name!).\(tld).key")
public func determineSecured() {
secured = Filesystem.fileExists("~/.config/valet/Certificates/\(self.name).\(self.tld).key")
}
/**
@ -147,7 +160,7 @@ class ValetSite {
as well as the requested PHP version. If no composer.json file is found, nothing happens.
*/
private func determineComposerInformation() {
let path = "\(absolutePath!)/composer.json"
let path = "\(absolutePath)/composer.json"
do {
if Filesystem.fileExists(path) {
@ -168,7 +181,7 @@ class ValetSite {
Checks the contents of the .valetphprc file and determine the version, if possible.
*/
private func determineValetPhpFileInfo() {
let path = "\(absolutePath!)/.valetphprc"
let path = "\(absolutePath)/.valetphprc"
do {
if Filesystem.fileExists(path) {

View File

@ -33,7 +33,7 @@ class SiteListCell: NSTableCellView
self.site = site
// Make sure to show the TLD
labelSiteName.stringValue = "\(site.name!).\(Valet.shared.config.tld)"
labelSiteName.stringValue = "\(site.name).\(Valet.shared.config.tld)"
// Show the absolute path, except make sure to replace the /Users/username segment with ~ for readability
labelPathName.stringValue = site.absolutePathRelative
@ -79,7 +79,7 @@ class SiteListCell: NSTableCellView
alert.alertStyle = .informational
alert.messageText = "alert.composer_php_requirement.title"
.localized("\(site.name!).\(Valet.shared.config.tld)", site.composerPhp)
.localized("\(site.name).\(Valet.shared.config.tld)", site.composerPhp)
alert.informativeText = "alert.composer_php_requirement.type.\(site.composerPhpSource.rawValue)"
.localized

View File

@ -16,12 +16,12 @@ extension SiteListVC {
let originalSecureStatus = selectedSite!.secured
let action = selectedSite!.secured ? "unsecure" : "secure"
let selectedSite = selectedSite!
let command = "cd '\(selectedSite.absolutePath!)' && sudo \(Paths.valet) \(action) && exit;"
let command = "cd '\(selectedSite.absolutePath)' && sudo \(Paths.valet) \(action) && exit;"
waitAndExecute {
Shell.run(command, requiresPath: true)
} completion: { [self] in
selectedSite.determineSecured(Valet.shared.config.tld)
selectedSite.determineSecured()
if selectedSite.secured == originalSecureStatus {
BetterAlert()
.withInformation(
@ -36,7 +36,7 @@ extension SiteListVC {
title: "site_list.alerts_status_changed.title".localized,
subtitle: "site_list.alerts_status_changed.desc"
.localized(
"\(selectedSite.name!).\(Valet.shared.config.tld)",
"\(selectedSite.name).\(Valet.shared.config.tld)",
newState
)
)
@ -50,7 +50,7 @@ extension SiteListVC {
@objc func openInBrowser() {
let prefix = selectedSite!.secured ? "https://" : "http://"
let url = URL(string: "\(prefix)\(selectedSite!.name!).\(Valet.shared.config.tld)")
let url = URL(string: "\(prefix)\(selectedSite!.name).\(Valet.shared.config.tld)")
if url != nil {
NSWorkspace.shared.open(url!)
} else {
@ -65,16 +65,16 @@ extension SiteListVC {
}
@objc func openInFinder() {
Shell.run("open '\(selectedSite!.absolutePath!)'")
Shell.run("open '\(selectedSite!.absolutePath)'")
}
@objc func openInTerminal() {
Shell.run("open -b com.apple.terminal '\(selectedSite!.absolutePath!)'")
Shell.run("open -b com.apple.terminal '\(selectedSite!.absolutePath)'")
}
@objc func openWithEditor(sender: EditorMenuItem) {
guard let editor = sender.editor else { return }
editor.openDirectory(file: selectedSite!.absolutePath!)
editor.openDirectory(file: selectedSite!.absolutePath)
}
@objc func unlinkSite() {
@ -94,7 +94,7 @@ extension SiteListVC {
secondButtonTitle: "Cancel",
style: .critical,
onFirstButtonPressed: {
Shell.run("valet unlink '\(site.name!)'", requiresPath: true)
Shell.run("valet unlink '\(site.name)'", requiresPath: true)
self.reloadSites()
}
)