mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
✅ Added test to parse the proxy address
This commit is contained in:
@ -33,4 +33,10 @@ class NginxConfigParserTest: XCTestCase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCanDetermineProxy() throws {
|
||||||
|
let parsed = NginxConfigParser(filePath: NginxConfigParserTest.proxyUrl.path)
|
||||||
|
XCTAssertTrue(parsed.contents.contains("# valet stub: proxy.valet.conf"))
|
||||||
|
XCTAssertEqual("http://127.0.0.1:90", parsed.proxy)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,25 @@ class NginxConfigParser {
|
|||||||
.replacingOccurrences(of: "~", with: "/Users/\(Paths.whoami)")
|
.replacingOccurrences(of: "~", with: "/Users/\(Paths.whoami)")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Retrieves what address this domain is proxying.
|
||||||
|
*/
|
||||||
|
lazy var proxy: String? = {
|
||||||
|
let regex = try! NSRegularExpression(
|
||||||
|
pattern: #"proxy_pass (?<proxy>.*:\d*);"#,
|
||||||
|
options: []
|
||||||
|
)
|
||||||
|
|
||||||
|
guard let match = regex.firstMatch(in: contents, range: NSMakeRange(0, contents.count))
|
||||||
|
else { return nil }
|
||||||
|
|
||||||
|
return contents[Range(match.range(withName: "proxy"), in: contents)!]
|
||||||
|
}()
|
||||||
|
|
||||||
|
/**
|
||||||
|
Retrieves which isolated version is active for this domain.
|
||||||
|
*/
|
||||||
lazy var isolatedVersion: String? = {
|
lazy var isolatedVersion: String? = {
|
||||||
let regex = try! NSRegularExpression(
|
let regex = try! NSRegularExpression(
|
||||||
// PHP versions have (so far) never needed multiple digits for version numbers
|
// PHP versions have (so far) never needed multiple digits for version numbers
|
||||||
@ -25,14 +43,11 @@ class NginxConfigParser {
|
|||||||
options: []
|
options: []
|
||||||
)
|
)
|
||||||
|
|
||||||
let match = regex.firstMatch(in: contents, range: NSMakeRange(0, contents.count))
|
guard let match = regex.firstMatch(in: contents, range: NSMakeRange(0, contents.count))
|
||||||
|
else { return nil }
|
||||||
if match == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
let major: String = contents[Range(match!.range(withName: "major"), in: contents)!]
|
let major: String = contents[Range(match.range(withName: "major"), in: contents)!],
|
||||||
let minor: String = contents[Range(match!.range(withName: "minor"), in: contents)!]
|
minor: String = contents[Range(match.range(withName: "minor"), in: contents)!]
|
||||||
|
|
||||||
return "\(major).\(minor)"
|
return "\(major).\(minor)"
|
||||||
}()
|
}()
|
||||||
|
Reference in New Issue
Block a user