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

🎨 Updated localization, cleanup

This commit is contained in:
2021-02-03 22:09:53 +01:00
parent 0493f61dc8
commit c1b80552a0
3 changed files with 52 additions and 27 deletions

View File

@ -16,13 +16,38 @@ import Foundation
instances. You can find more information here: https://nshipster.com/swift-regular-expressions/
*/
class PhpExtension {
/// The file where this extension was located.
var file: String
/// The original string that was used to determine this extension is active.
var line: String
/// The name of the extension. This is always identical to the name found in the original string. If you want to display this name, capitalize this.
var name: String
/// Whether the extension has been enabled.
var enabled: Bool
/**
This regular expression will allow us to identify lines which activate an extension.
It will match the following items:
* `extension="name.so"`
* `zend_extension="name.so"`
* `; extension="name.so"`
* `; zend_extension="name.so"`
- Note: Extensions that are disabled in a different way will not be detected. This is intentional.
*/
static let extensionRegex = #"^(extension=|zend_extension=|; extension=|; zend_extension=)"(?<name>[a-zA-Z]*).so"$"#
/**
When registering an extension, we do that based on the line found inside the .ini file.
*/
init(_ line: String, file: String) {
let regex = try! NSRegularExpression(pattern: #"^(extension=|zend_extension=|; extension=|; zend_extension=)"(?<name>[a-zA-Z]*).so"$"#, options: [])
let regex = try! NSRegularExpression(pattern: PhpExtension.extensionRegex, options: [])
let match = regex.matches(in: line, options: [], range: NSMakeRange(0, line.count)).first
let range = Range(match!.range(withName: "name"), in: line)!
@ -32,6 +57,9 @@ class PhpExtension {
self.file = file
}
/**
This simply toggles the extension in the .ini file. You may need to restart the other services in order for this change to apply.
*/
public func toggle() {
Actions.sed(
file: self.file,
@ -41,15 +69,22 @@ class PhpExtension {
self.enabled = !self.enabled
}
// MARK: - Static Methods
/**
This method will attempt to identify all extensions in the .ini file at a certain URL.
*/
static func load(from path: URL) -> [PhpExtension] {
let file = try! String(contentsOf: path, encoding: .utf8)
let file = try? String(contentsOf: path, encoding: .utf8)
return file.components(separatedBy: "\n")
if (file == nil) {
print("There was an issue reading the file. Assuming no extensions were found.")
return []
}
return file!.components(separatedBy: "\n")
.filter({ (line) -> Bool in
return line.range(
of: #"^(extension=|zend_extension=|; extension=|; zend_extension=)"[a-zA-Z]*.so"$"#,
options: .regularExpression
) != nil
return line.range(of: PhpExtension.extensionRegex, options: .regularExpression) != nil
})
.map { (line) -> PhpExtension in
return PhpExtension(line, file: path.path)

View File

@ -9,21 +9,19 @@ import Cocoa
class StatusMenu : NSMenu {
public func addPhpVersionMenuItems() {
if (App.shared.currentInstall == nil) {
if App.shared.currentInstall == nil {
return
}
if (!App.phpInstall!.version.error) {
// in case the php version loaded without issue
let string = "\("mi_php_version".localized) \(App.phpInstall!.version.long)"
self.addItem(NSMenuItem(title: string, action: nil, keyEquivalent: ""))
} else {
// in case of an error show the error message
["mi_php_broken_1", "mi_php_broken_2",
"mi_php_broken_3", "mi_php_broken_4"].forEach { (message) in
if App.phpInstall!.version.error {
for message in ["mi_php_broken_1", "mi_php_broken_2", "mi_php_broken_3", "mi_php_broken_4"] {
self.addItem(NSMenuItem(title: message.localized, action: nil, keyEquivalent: ""))
}
return
}
let string = "\("mi_php_version".localized) \(App.phpInstall!.version.long)"
self.addItem(NSMenuItem(title: string, action: nil, keyEquivalent: ""))
}
public func addPhpActionMenuItems() {
@ -31,17 +29,13 @@ class StatusMenu : NSMenu {
self.addItem(NSMenuItem(title: "mi_busy".localized, action: nil, keyEquivalent: ""))
return
}
if App.shared.availablePhpVersions.count == 0 {
return
}
// Switch to PHP X.X
self.addSwitchToPhpMenuItems()
// Separator
self.addItem(NSMenuItem.separator())
// Services
self.addServicesMenuItems()
}
@ -72,7 +66,6 @@ class StatusMenu : NSMenu {
for item in servicesMenu.items {
item.target = MainMenu.shared
}
self.setSubmenu(servicesMenu, for: services)
self.addItem(NSMenuItem(title: "mi_force_load_latest".localized, action: #selector(MainMenu.forceRestartLatestPhp), keyEquivalent: "f"))
@ -86,14 +79,12 @@ class StatusMenu : NSMenu {
}
// Configuration
self.addItem(NSMenuItem(title: "mi_configuration".localized, action: nil, keyEquivalent: ""))
self.addItem(NSMenuItem(title: "mi_valet_config".localized, action: #selector(MainMenu.openValetConfigFolder), keyEquivalent: "v"))
self.addItem(NSMenuItem(title: "mi_php_config".localized, action: #selector(MainMenu.openActiveConfigFolder), keyEquivalent: "c"))
self.addItem(NSMenuItem(title: "mi_phpinfo".localized, action: #selector(MainMenu.openPhpInfo), keyEquivalent: "i"))
// Memory Limits
// Limits
self.addItem(NSMenuItem.separator())
self.addItem(NSMenuItem(title: "mi_limits".localized, action: nil, keyEquivalent: ""))
self.addItem(NSMenuItem(title: "\("mi_memory_limit".localized): \(App.phpInstall!.configuration.memory_limit)", action: #selector(MainMenu.openActiveConfigFolder), keyEquivalent: ""))
@ -101,7 +92,6 @@ class StatusMenu : NSMenu {
self.addItem(NSMenuItem(title: "\("mi_upload_max_filesize".localized): \(App.phpInstall!.configuration.upload_max_filesize)", action: #selector(MainMenu.openActiveConfigFolder), keyEquivalent: ""))
// Extensions
self.addItem(NSMenuItem.separator())
self.addItem(NSMenuItem(title: "mi_detected_extensions".localized, action: nil, keyEquivalent: ""))

View File

@ -27,7 +27,7 @@
"mi_force_load_latest" = "Force load latest PHP version";
"mi_configuration" = "Configuration";
"mi_limits" = "Memory & Upload Limits";
"mi_limits" = "Limits Configuration";
"mi_memory_limit" = "Script Memory Limit";
"mi_post_max_size" = "Max POST Size";
"mi_upload_max_filesize" = "Max Upload File Size";