diff --git a/phpmon/Domain/Core/PhpInstall.swift b/phpmon/Domain/Core/PhpInstall.swift
index 1410954..ed8170a 100644
--- a/phpmon/Domain/Core/PhpInstall.swift
+++ b/phpmon/Domain/Core/PhpInstall.swift
@@ -38,17 +38,21 @@ class PhpInstall {
// Get configuration values
self.configuration = Configuration(
- memory_limit: type(of: self).getIniValue(key: "memory_limit"),
- upload_max_filesize: type(of: self).getIniValue(key: "upload_max_filesize"),
- post_max_size: type(of: self).getIniValue(key: "post_max_size")
+ memory_limit: type(of: self).getByteCount(key: "memory_limit"),
+ upload_max_filesize: type(of: self).getByteCount(key: "upload_max_filesize"),
+ post_max_size: type(of: self).getByteCount(key: "post_max_size")
)
}
+ /**
+ When the app tries to retrieve the version, the installation is considered broken if the output is nothing,
+ _or_ if the output contains the word "Warning" or "Error". In normal situations this should not be the case.
+ */
private static func getVersion() -> Version {
var versionStruct = Version()
let version = Command.execute(path: Paths.php, arguments: ["-r", "print phpversion();"])
- if (version == "" || version.contains("Warning")) {
+ if (version == "" || version.contains("Warning") || version.contains("Error")) {
versionStruct.short = "💩 BROKEN"
versionStruct.long = "";
versionStruct.error = true
@@ -67,8 +71,31 @@ class PhpInstall {
return versionStruct
}
- private static func getIniValue(key: String) -> String {
- return Command.execute(path: Paths.php, arguments: ["-r", "echo ini_get('\(key)');"])
+ /**
+ Retrieves the display value for a specific key in the `.ini` file.
+
+ The following values are valid:
+ * -1: unlimited (show the infinity icon)
+ * 10000: an integer = amount of bytes
+ * 1K, 1M, 1G = shorthand for kilobytes, megabytes and gigabytes
+
+ If none of these notations are used, the _fallback_ value is used. We'll show an emoji to indicate something has gone wrong here.
+ To clarify, B gets appended to valid values. As a result, "5M" (valid) becomes "5MB", and "5MB" (invalid) becomes ⚠️.
+
+ - Parameter key: The key of the `ini` value that needs to be retrieved. For example, you can use `memory_limit`.
+ */
+ private static func getByteCount(key: String) -> String {
+ let value = Command.execute(path: Paths.php, arguments: ["-r", "echo ini_get('\(key)');"])
+
+ // Check if the value is unlimited
+ if (value == "-1") {
+ return "∞"
+ }
+
+ // Check if the syntax is valid otherwise
+ let regex = try! NSRegularExpression(pattern: #"^([0-9]*)(K|M|G|)$"#, options: [])
+ let match = regex.matches(in: value, options: [], range: NSMakeRange(0, value.count)).first
+ return (match == nil) ? "⚠️" : "\(value)B"
}
// MARK: - Structs
diff --git a/phpmon/Domain/Menu/StatsView.xib b/phpmon/Domain/Menu/StatsView.xib
index 1a6c77e..1ad4bd9 100644
--- a/phpmon/Domain/Menu/StatsView.xib
+++ b/phpmon/Domain/Menu/StatsView.xib
@@ -10,17 +10,17 @@
-
+
-
+
-
+
-
+
@@ -28,9 +28,9 @@
-
+
-
+
@@ -46,10 +46,10 @@
-
+
-
+
@@ -57,9 +57,9 @@
-
+
-
+
@@ -75,10 +75,10 @@
-
+
-
+
@@ -86,9 +86,9 @@
-
+
-
+