mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-12-24 04:10:05 +01:00
✨ Version constraint checks (#84)
The version constraint checks will also be used in the future to evaluate whether any given site's PHP constraint (if set) is valid for the currently linked version of PHP. For example, assuming you have PHP 8.1.2 linked, we could evaluate: * A site requires "8.0" -> invalid * A site requires "^8.0" -> valid * A site requires "^8.0.0" -> valid * A site requires "~8.0" -> valid * A site requires "~8.0.0" -> invalid Currently, this constraint check is used to determine which versions that are currently installed are good suggestions to switch to. If you have a site with constraint "^8.0" for example, and you have PHP 8.0 and 8.1 installed (with 8.1 linked), then you will get a suggestion to switch back to 8.0.
This commit is contained in:
@@ -10,20 +10,26 @@ import Foundation
|
||||
|
||||
class PhpInstallation {
|
||||
|
||||
var longVersion: String
|
||||
var longVersion: PhpVersionNumber
|
||||
|
||||
/**
|
||||
In order to determine details about a PHP installation, we’ll simply run `php-config --version`
|
||||
in the relevant directory.
|
||||
*/
|
||||
init(_ version: String) {
|
||||
|
||||
let phpConfigExecutablePath = "\(Paths.optPath)/php@\(version)/bin/php-config"
|
||||
self.longVersion = version
|
||||
self.longVersion = PhpVersionNumber.make(from: version)!
|
||||
|
||||
if Shell.fileExists(phpConfigExecutablePath) {
|
||||
self.longVersion = Command.execute(
|
||||
let longVersionString = Command.execute(
|
||||
path: phpConfigExecutablePath,
|
||||
arguments: ["--version"]
|
||||
)
|
||||
).trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
self.longVersion = PhpVersionNumber.make(
|
||||
from: String(longVersionString.split(separator: "-")[0])
|
||||
)!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user