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

🔥 Cleanup

This commit is contained in:
2022-02-07 18:00:35 +01:00
parent 776c2095e6
commit 0f464f5814
20 changed files with 4 additions and 42 deletions

View File

@ -0,0 +1,44 @@
//
// VersionExtractor.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 16/12/2021.
// Copyright © 2021 Nico Verbruggen. All rights reserved.
//
import Foundation
class VersionExtractor {
/**
This attempts to extract the version number from the command line output of Valet.
*/
public static func from(_ string: String) -> String? {
do {
let regex = try NSRegularExpression(
pattern: #"Laravel Valet (?<version>(\d+)(.)(\d+)((.)(\d+))?)"#,
options: []
)
let match = regex.matches(
in: string,
options: [],
range: NSMakeRange(0, string.count)
).first
guard let match = match else {
return nil
}
let range = Range(
match.range(withName: "version"),
in: string
)!
return String(string[range])
} catch {
return nil
}
}
}