mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-09 13:10:24 +01:00
👌 Clean up switchToPhpVersion() and fixMyPhp()
This commit is contained in:
@@ -51,29 +51,25 @@ class Actions {
|
|||||||
Shell.user.run("sudo brew services restart nginx")
|
Shell.user.run("sudo brew services restart nginx")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Switching to a new PHP version involves:
|
||||||
|
- unlinking the current version
|
||||||
|
- stopping the active services
|
||||||
|
- linking the new desired version
|
||||||
|
|
||||||
|
Please note that depending on which version is installed,
|
||||||
|
the version that is switched to may or may not be identical to `php` (without @version).
|
||||||
|
*/
|
||||||
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
|
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
|
||||||
availableVersions.forEach { (version) in
|
availableVersions.forEach { (available) in
|
||||||
// Unlink the current version
|
let formula = (available == App.shared.brewPhpVersion) ? "php" : "php@\(available)"
|
||||||
Shell.user.run("brew unlink php@\(version)")
|
Shell.user.run("brew unlink \(formula)")
|
||||||
// Stop the services
|
Shell.user.run("sudo brew services stop \(formula)")
|
||||||
if (version == App.shared.brewPhpVersion) {
|
|
||||||
Shell.user.run("sudo brew services stop php")
|
|
||||||
} else {
|
|
||||||
Shell.user.run("sudo brew services stop php@\(version)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (availableVersions.contains(App.shared.brewPhpVersion)) {
|
|
||||||
// Use the latest version as a default
|
|
||||||
Shell.user.run("brew link php@\(App.shared.brewPhpVersion) --overwrite --force")
|
|
||||||
if (version == App.shared.brewPhpVersion) {
|
|
||||||
// If said version was also requested, all we need to do is start the service
|
|
||||||
Shell.user.run("sudo brew services start php")
|
|
||||||
} else {
|
|
||||||
// Otherwise, link the correct php version + start the correct service
|
|
||||||
Shell.user.run("brew link php@\(version) --overwrite --force")
|
|
||||||
Shell.user.run("sudo brew services start php@\(version)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
||||||
|
Shell.user.run("brew link \(formula) --overwrite --force")
|
||||||
|
Shell.user.run("sudo brew services start \(formula)")
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func openGenericPhpConfigFolder() {
|
public static func openGenericPhpConfigFolder() {
|
||||||
@@ -120,8 +116,11 @@ class Actions {
|
|||||||
Shell.user.run(command)
|
Shell.user.run(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
// unlink all the crap and link the latest version
|
/**
|
||||||
// this also restarts all services
|
Detects all currently available PHP versions, and unlinks each and every one of them.
|
||||||
|
After this, the brew services are also stopped, the latest PHP version is linked, and php + nginx are restarted.
|
||||||
|
If this does not solve the issue, the user may need to install additional extensions and/or run `composer global update`.
|
||||||
|
*/
|
||||||
public static func fixMyPhp() {
|
public static func fixMyPhp() {
|
||||||
let versions = self.detectPhpVersions()
|
let versions = self.detectPhpVersions()
|
||||||
versions.forEach { (version) in
|
versions.forEach { (version) in
|
||||||
|
|||||||
Reference in New Issue
Block a user