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:
@ -34,6 +34,8 @@ class InternalSwitcher: PhpSwitcher {
|
|||||||
? "php" : "php@\(available)"
|
? "php" : "php@\(available)"
|
||||||
|
|
||||||
brew("unlink \(formula)")
|
brew("unlink \(formula)")
|
||||||
|
|
||||||
|
// TODO: (ISOLATION) Only stop formulae that are not used for isolation
|
||||||
brew("services stop \(formula)", sudo: true)
|
brew("services stop \(formula)", sudo: true)
|
||||||
|
|
||||||
Log.perf("Unlinked and stopped services for \(formula)")
|
Log.perf("Unlinked and stopped services for \(formula)")
|
||||||
|
@ -41,7 +41,7 @@ class Valet {
|
|||||||
let file = FileManager.default.homeDirectoryForCurrentUser
|
let file = FileManager.default.homeDirectoryForCurrentUser
|
||||||
.appendingPathComponent(".config/valet/config.json")
|
.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(
|
config = try! JSONDecoder().decode(
|
||||||
Valet.Configuration.self,
|
Valet.Configuration.self,
|
||||||
from: try! String(contentsOf: file, encoding: .utf8).data(using: .utf8)!
|
from: try! String(contentsOf: file, encoding: .utf8).data(using: .utf8)!
|
||||||
@ -83,6 +83,10 @@ class Valet {
|
|||||||
installed is not recent enough.
|
installed is not recent enough.
|
||||||
*/
|
*/
|
||||||
public func validateVersion() -> Void {
|
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 {
|
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))")
|
||||||
|
@ -11,10 +11,10 @@ import Foundation
|
|||||||
class ValetSite {
|
class ValetSite {
|
||||||
|
|
||||||
/// Name of the site. Does not include the TLD.
|
/// Name of the site. Does not include the TLD.
|
||||||
var name: String!
|
var name: String
|
||||||
|
|
||||||
/// The absolute path to the directory that is served.
|
/// The absolute path to the directory that is served.
|
||||||
var absolutePath: String!
|
var absolutePath: String
|
||||||
|
|
||||||
/// The absolute path to the directory that is served,
|
/// The absolute path to the directory that is served,
|
||||||
/// replacing the user's home folder with ~.
|
/// replacing the user's home folder with ~.
|
||||||
@ -23,6 +23,12 @@ class ValetSite {
|
|||||||
.replacingOccurrences(of: "/Users/\(Paths.whoami)", with: "~")
|
.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.
|
/// Location of the alias. If set, this is a linked domain.
|
||||||
var aliasPath: String?
|
var aliasPath: String?
|
||||||
|
|
||||||
@ -54,34 +60,41 @@ class ValetSite {
|
|||||||
case valetphprc = "valetphprc"
|
case valetphprc = "valetphprc"
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {}
|
init(absolutePath: String, tld: String) {
|
||||||
|
|
||||||
convenience init(absolutePath: String, tld: String) {
|
|
||||||
self.init()
|
|
||||||
self.absolutePath = absolutePath
|
self.absolutePath = absolutePath
|
||||||
|
self.tld = tld
|
||||||
self.name = URL(fileURLWithPath: absolutePath).lastPathComponent
|
self.name = URL(fileURLWithPath: absolutePath).lastPathComponent
|
||||||
self.aliasPath = nil
|
self.aliasPath = nil
|
||||||
determineSecured(tld)
|
|
||||||
|
determineSecured()
|
||||||
determineComposerPhpVersion()
|
determineComposerPhpVersion()
|
||||||
determineDriver()
|
determineDriver()
|
||||||
}
|
}
|
||||||
|
|
||||||
convenience init(aliasPath: String, tld: String) {
|
convenience init(aliasPath: String, tld: String) {
|
||||||
self.init()
|
let absolutePath = try! FileManager.default.destinationOfSymbolicLink(atPath: aliasPath)
|
||||||
self.absolutePath = try! FileManager.default.destinationOfSymbolicLink(atPath: aliasPath)
|
|
||||||
|
self.init(absolutePath: absolutePath, tld: tld)
|
||||||
self.name = URL(fileURLWithPath: aliasPath).lastPathComponent
|
self.name = URL(fileURLWithPath: aliasPath).lastPathComponent
|
||||||
self.aliasPath = aliasPath
|
self.aliasPath = aliasPath
|
||||||
determineSecured(tld)
|
|
||||||
|
determineSecured()
|
||||||
determineComposerPhpVersion()
|
determineComposerPhpVersion()
|
||||||
determineDriver()
|
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.
|
Checks if a certificate file can be found in the `valet/Certificates` directory.
|
||||||
- Note: The file is not validated, only its presence is checked.
|
- Note: The file is not validated, only its presence is checked.
|
||||||
*/
|
*/
|
||||||
public func determineSecured(_ tld: String) {
|
public func determineSecured() {
|
||||||
secured = Filesystem.fileExists("~/.config/valet/Certificates/\(self.name!).\(tld).key")
|
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.
|
as well as the requested PHP version. If no composer.json file is found, nothing happens.
|
||||||
*/
|
*/
|
||||||
private func determineComposerInformation() {
|
private func determineComposerInformation() {
|
||||||
let path = "\(absolutePath!)/composer.json"
|
let path = "\(absolutePath)/composer.json"
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if Filesystem.fileExists(path) {
|
if Filesystem.fileExists(path) {
|
||||||
@ -168,7 +181,7 @@ class ValetSite {
|
|||||||
Checks the contents of the .valetphprc file and determine the version, if possible.
|
Checks the contents of the .valetphprc file and determine the version, if possible.
|
||||||
*/
|
*/
|
||||||
private func determineValetPhpFileInfo() {
|
private func determineValetPhpFileInfo() {
|
||||||
let path = "\(absolutePath!)/.valetphprc"
|
let path = "\(absolutePath)/.valetphprc"
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if Filesystem.fileExists(path) {
|
if Filesystem.fileExists(path) {
|
||||||
|
@ -33,7 +33,7 @@ class SiteListCell: NSTableCellView
|
|||||||
self.site = site
|
self.site = site
|
||||||
|
|
||||||
// Make sure to show the TLD
|
// 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
|
// Show the absolute path, except make sure to replace the /Users/username segment with ~ for readability
|
||||||
labelPathName.stringValue = site.absolutePathRelative
|
labelPathName.stringValue = site.absolutePathRelative
|
||||||
@ -79,7 +79,7 @@ class SiteListCell: NSTableCellView
|
|||||||
alert.alertStyle = .informational
|
alert.alertStyle = .informational
|
||||||
|
|
||||||
alert.messageText = "alert.composer_php_requirement.title"
|
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)"
|
alert.informativeText = "alert.composer_php_requirement.type.\(site.composerPhpSource.rawValue)"
|
||||||
.localized
|
.localized
|
||||||
|
|
||||||
|
@ -16,12 +16,12 @@ extension SiteListVC {
|
|||||||
let originalSecureStatus = selectedSite!.secured
|
let originalSecureStatus = selectedSite!.secured
|
||||||
let action = selectedSite!.secured ? "unsecure" : "secure"
|
let action = selectedSite!.secured ? "unsecure" : "secure"
|
||||||
let selectedSite = selectedSite!
|
let selectedSite = selectedSite!
|
||||||
let command = "cd '\(selectedSite.absolutePath!)' && sudo \(Paths.valet) \(action) && exit;"
|
let command = "cd '\(selectedSite.absolutePath)' && sudo \(Paths.valet) \(action) && exit;"
|
||||||
|
|
||||||
waitAndExecute {
|
waitAndExecute {
|
||||||
Shell.run(command, requiresPath: true)
|
Shell.run(command, requiresPath: true)
|
||||||
} completion: { [self] in
|
} completion: { [self] in
|
||||||
selectedSite.determineSecured(Valet.shared.config.tld)
|
selectedSite.determineSecured()
|
||||||
if selectedSite.secured == originalSecureStatus {
|
if selectedSite.secured == originalSecureStatus {
|
||||||
BetterAlert()
|
BetterAlert()
|
||||||
.withInformation(
|
.withInformation(
|
||||||
@ -36,7 +36,7 @@ extension SiteListVC {
|
|||||||
title: "site_list.alerts_status_changed.title".localized,
|
title: "site_list.alerts_status_changed.title".localized,
|
||||||
subtitle: "site_list.alerts_status_changed.desc"
|
subtitle: "site_list.alerts_status_changed.desc"
|
||||||
.localized(
|
.localized(
|
||||||
"\(selectedSite.name!).\(Valet.shared.config.tld)",
|
"\(selectedSite.name).\(Valet.shared.config.tld)",
|
||||||
newState
|
newState
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -50,7 +50,7 @@ extension SiteListVC {
|
|||||||
|
|
||||||
@objc func openInBrowser() {
|
@objc func openInBrowser() {
|
||||||
let prefix = selectedSite!.secured ? "https://" : "http://"
|
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 {
|
if url != nil {
|
||||||
NSWorkspace.shared.open(url!)
|
NSWorkspace.shared.open(url!)
|
||||||
} else {
|
} else {
|
||||||
@ -65,16 +65,16 @@ extension SiteListVC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func openInFinder() {
|
@objc func openInFinder() {
|
||||||
Shell.run("open '\(selectedSite!.absolutePath!)'")
|
Shell.run("open '\(selectedSite!.absolutePath)'")
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func openInTerminal() {
|
@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) {
|
@objc func openWithEditor(sender: EditorMenuItem) {
|
||||||
guard let editor = sender.editor else { return }
|
guard let editor = sender.editor else { return }
|
||||||
editor.openDirectory(file: selectedSite!.absolutePath!)
|
editor.openDirectory(file: selectedSite!.absolutePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func unlinkSite() {
|
@objc func unlinkSite() {
|
||||||
@ -94,7 +94,7 @@ extension SiteListVC {
|
|||||||
secondButtonTitle: "Cancel",
|
secondButtonTitle: "Cancel",
|
||||||
style: .critical,
|
style: .critical,
|
||||||
onFirstButtonPressed: {
|
onFirstButtonPressed: {
|
||||||
Shell.run("valet unlink '\(site.name!)'", requiresPath: true)
|
Shell.run("valet unlink '\(site.name)'", requiresPath: true)
|
||||||
self.reloadSites()
|
self.reloadSites()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user