mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
👌 isolatedVersion
as a lazy property
This commit is contained in:
@ -20,12 +20,12 @@ class NginxConfigParserTest: XCTestCase {
|
|||||||
|
|
||||||
func testCanDetermineIsolation() throws {
|
func testCanDetermineIsolation() throws {
|
||||||
XCTAssertNil(
|
XCTAssertNil(
|
||||||
NginxConfigParser(filePath: NginxConfigParserTest.regularUrl.path).isolatedVersion()
|
NginxConfigParser(filePath: NginxConfigParserTest.regularUrl.path).isolatedVersion
|
||||||
)
|
)
|
||||||
|
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
"8.1",
|
"8.1",
|
||||||
NginxConfigParser(filePath: NginxConfigParserTest.isolatedUrl.path).isolatedVersion()
|
NginxConfigParser(filePath: NginxConfigParserTest.isolatedUrl.path).isolatedVersion
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class NginxConfigParser {
|
|||||||
self.contents = try! String(contentsOfFile: filePath)
|
self.contents = try! String(contentsOfFile: filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func isolatedVersion() -> String? {
|
lazy var isolatedVersion: String? = {
|
||||||
let regex = try! NSRegularExpression(
|
let regex = try! NSRegularExpression(
|
||||||
pattern: #"(ISOLATED_PHP_VERSION=(php@)?)((?<major>\d)(.)?(?<minor>\d))"#,
|
pattern: #"(ISOLATED_PHP_VERSION=(php@)?)((?<major>\d)(.)?(?<minor>\d))"#,
|
||||||
options: []
|
options: []
|
||||||
@ -35,5 +35,5 @@ class NginxConfigParser {
|
|||||||
let minor: String = contents[minorRange]
|
let minor: String = contents[minorRange]
|
||||||
|
|
||||||
return "\(major).\(minor)"
|
return "\(major).\(minor)"
|
||||||
}
|
}()
|
||||||
}
|
}
|
||||||
|
@ -89,8 +89,6 @@ class ValetSite {
|
|||||||
public func determineIsolated() {
|
public func determineIsolated() {
|
||||||
if let version = ValetSite.isolatedVersion("~/.config/valet/Nginx/\(self.name).\(self.tld)") {
|
if let version = ValetSite.isolatedVersion("~/.config/valet/Nginx/\(self.name).\(self.tld)") {
|
||||||
self.isolatedPhpVersion = PhpEnv.shared.cachedPhpInstallations[version]
|
self.isolatedPhpVersion = PhpEnv.shared.cachedPhpInstallations[version]
|
||||||
} else {
|
|
||||||
self.isolatedPhpVersion = nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +203,9 @@ class ValetSite {
|
|||||||
|
|
||||||
public static func isolatedVersion(_ filePath: String) -> String? {
|
public static func isolatedVersion(_ filePath: String) -> String? {
|
||||||
if Filesystem.fileExists(filePath) {
|
if Filesystem.fileExists(filePath) {
|
||||||
return NginxConfigParser.init(filePath: filePath).isolatedVersion()
|
return NginxConfigParser
|
||||||
|
.init(filePath: filePath)
|
||||||
|
.isolatedVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user