1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

🏗 WIP: Parsing .valetrc file

This commit is contained in:
2023-01-20 16:36:56 +01:00
parent 5923be099f
commit c3261b8873
2 changed files with 39 additions and 9 deletions

View File

@ -65,6 +65,7 @@ class ValetSite: ValetListable {
case require
case platform
case valetphprc
case valetrc
}
init(
@ -215,21 +216,49 @@ class ValetSite: ValetListable {
Checks the contents of the .valetphprc file and determine the version, if possible.
*/
private func determineValetPhpFileInfo() {
let path = "\(absolutePath)/.valetphprc"
let files = [
(".valetphprc", VersionSource.valetphprc),
(".valetrc", VersionSource.valetrc)
]
do {
if FileSystem.fileExists(path) {
let contents = try String(contentsOf: URL(fileURLWithPath: path), encoding: .utf8)
if let version = VersionExtractor.from(contents) {
self.composerPhp = version
self.composerPhpSource = .valetphprc
for (suffix, source) in files {
do {
let path = "\(absolutePath)/\(suffix)"
if FileSystem.fileExists(path) {
try self.handleValetFile(path, source)
}
} catch {
Log.err("Something went wrong parsing the '\(suffix)' file")
}
} catch {
Log.err("Something went wrong parsing the .valetphprc file")
}
}
/**
Parse a Valet file (either .valetphprc or .valetrc).
*/
private func handleValetFile(_ path: String, _ source: VersionSource) throws {
let contents = try String(contentsOf: URL(fileURLWithPath: path), encoding: .utf8)
switch source {
case .valetphprc:
if let version = VersionExtractor.from(contents) {
self.composerPhp = version
self.composerPhpSource = source
}
case .valetrc:
self.parseValetRcFile(contents)
default:
return
}
}
/**
Specifically extract PHP information from a .valetrc file.
*/
private func parseValetRcFile(_ text: String) {
// TODO: Implement this
fatalError("A .valetrc file was found, needs to be parsed!")
}
// MARK: - File Parsing
public static func isolatedVersion(_ filePath: String) -> String? {

View File

@ -388,6 +388,7 @@ problem manually, using your own Terminal app (this just shows you the output)."
"alert.composer_php_requirement.type.require" = "This required PHP version was determined by checking the `require` field in the `composer.json` file when the site list was last refreshed.";
"alert.composer_php_requirement.type.platform" = "This required PHP version was determined by checking the `platform` field in the `composer.json` file when the site list was last refreshed.";
"alert.composer_php_requirement.type.valetphprc" = "This required PHP version was determined by checking the .valetphprc file in your project's directory.";
"alert.composer_php_requirement.type.valetrc" = "This required PHP version was determined by checking the .valetrc file in your project's directory.";
"alert.unable_to_determine_is_fine" = "If you have a simple project, there may not be a specified PHP version set as a requirement. In that case, you are free to ignore this warning.";
"alert.php_version_ideal" = "The currently active PHP version is ideal for this site.";
"alert.php_version_incorrect" = "The currently active PHP version does not match the required constraint set for this site.";