mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
🎨 Updated localization, cleanup
This commit is contained in:
@ -16,13 +16,38 @@ import Foundation
|
|||||||
instances. You can find more information here: https://nshipster.com/swift-regular-expressions/
|
instances. You can find more information here: https://nshipster.com/swift-regular-expressions/
|
||||||
*/
|
*/
|
||||||
class PhpExtension {
|
class PhpExtension {
|
||||||
|
|
||||||
|
/// The file where this extension was located.
|
||||||
var file: String
|
var file: String
|
||||||
|
|
||||||
|
/// The original string that was used to determine this extension is active.
|
||||||
var line: String
|
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
|
var name: String
|
||||||
|
|
||||||
|
/// Whether the extension has been enabled.
|
||||||
var enabled: Bool
|
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) {
|
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 match = regex.matches(in: line, options: [], range: NSMakeRange(0, line.count)).first
|
||||||
let range = Range(match!.range(withName: "name"), in: line)!
|
let range = Range(match!.range(withName: "name"), in: line)!
|
||||||
|
|
||||||
@ -32,6 +57,9 @@ class PhpExtension {
|
|||||||
self.file = file
|
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() {
|
public func toggle() {
|
||||||
Actions.sed(
|
Actions.sed(
|
||||||
file: self.file,
|
file: self.file,
|
||||||
@ -41,15 +69,22 @@ class PhpExtension {
|
|||||||
self.enabled = !self.enabled
|
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] {
|
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
|
.filter({ (line) -> Bool in
|
||||||
return line.range(
|
return line.range(of: PhpExtension.extensionRegex, options: .regularExpression) != nil
|
||||||
of: #"^(extension=|zend_extension=|; extension=|; zend_extension=)"[a-zA-Z]*.so"$"#,
|
|
||||||
options: .regularExpression
|
|
||||||
) != nil
|
|
||||||
})
|
})
|
||||||
.map { (line) -> PhpExtension in
|
.map { (line) -> PhpExtension in
|
||||||
return PhpExtension(line, file: path.path)
|
return PhpExtension(line, file: path.path)
|
||||||
|
@ -9,21 +9,19 @@ import Cocoa
|
|||||||
|
|
||||||
class StatusMenu : NSMenu {
|
class StatusMenu : NSMenu {
|
||||||
public func addPhpVersionMenuItems() {
|
public func addPhpVersionMenuItems() {
|
||||||
if (App.shared.currentInstall == nil) {
|
if App.shared.currentInstall == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!App.phpInstall!.version.error) {
|
if App.phpInstall!.version.error {
|
||||||
// in case the php version loaded without issue
|
for message in ["mi_php_broken_1", "mi_php_broken_2", "mi_php_broken_3", "mi_php_broken_4"] {
|
||||||
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
|
|
||||||
self.addItem(NSMenuItem(title: message.localized, action: nil, keyEquivalent: ""))
|
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() {
|
public func addPhpActionMenuItems() {
|
||||||
@ -31,17 +29,13 @@ class StatusMenu : NSMenu {
|
|||||||
self.addItem(NSMenuItem(title: "mi_busy".localized, action: nil, keyEquivalent: ""))
|
self.addItem(NSMenuItem(title: "mi_busy".localized, action: nil, keyEquivalent: ""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if App.shared.availablePhpVersions.count == 0 {
|
if App.shared.availablePhpVersions.count == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to PHP X.X
|
|
||||||
self.addSwitchToPhpMenuItems()
|
self.addSwitchToPhpMenuItems()
|
||||||
|
|
||||||
// Separator
|
|
||||||
self.addItem(NSMenuItem.separator())
|
self.addItem(NSMenuItem.separator())
|
||||||
|
|
||||||
// Services
|
|
||||||
self.addServicesMenuItems()
|
self.addServicesMenuItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +66,6 @@ class StatusMenu : NSMenu {
|
|||||||
for item in servicesMenu.items {
|
for item in servicesMenu.items {
|
||||||
item.target = MainMenu.shared
|
item.target = MainMenu.shared
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setSubmenu(servicesMenu, for: services)
|
self.setSubmenu(servicesMenu, for: services)
|
||||||
|
|
||||||
self.addItem(NSMenuItem(title: "mi_force_load_latest".localized, action: #selector(MainMenu.forceRestartLatestPhp), keyEquivalent: "f"))
|
self.addItem(NSMenuItem(title: "mi_force_load_latest".localized, action: #selector(MainMenu.forceRestartLatestPhp), keyEquivalent: "f"))
|
||||||
@ -86,14 +79,12 @@ class StatusMenu : NSMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
|
|
||||||
self.addItem(NSMenuItem(title: "mi_configuration".localized, action: nil, keyEquivalent: ""))
|
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_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_php_config".localized, action: #selector(MainMenu.openActiveConfigFolder), keyEquivalent: "c"))
|
||||||
self.addItem(NSMenuItem(title: "mi_phpinfo".localized, action: #selector(MainMenu.openPhpInfo), keyEquivalent: "i"))
|
self.addItem(NSMenuItem(title: "mi_phpinfo".localized, action: #selector(MainMenu.openPhpInfo), keyEquivalent: "i"))
|
||||||
|
|
||||||
// Memory Limits
|
// Limits
|
||||||
|
|
||||||
self.addItem(NSMenuItem.separator())
|
self.addItem(NSMenuItem.separator())
|
||||||
self.addItem(NSMenuItem(title: "mi_limits".localized, action: nil, keyEquivalent: ""))
|
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: ""))
|
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: ""))
|
self.addItem(NSMenuItem(title: "\("mi_upload_max_filesize".localized): \(App.phpInstall!.configuration.upload_max_filesize)", action: #selector(MainMenu.openActiveConfigFolder), keyEquivalent: ""))
|
||||||
|
|
||||||
// Extensions
|
// Extensions
|
||||||
|
|
||||||
self.addItem(NSMenuItem.separator())
|
self.addItem(NSMenuItem.separator())
|
||||||
self.addItem(NSMenuItem(title: "mi_detected_extensions".localized, action: nil, keyEquivalent: ""))
|
self.addItem(NSMenuItem(title: "mi_detected_extensions".localized, action: nil, keyEquivalent: ""))
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
"mi_force_load_latest" = "Force load latest PHP version";
|
"mi_force_load_latest" = "Force load latest PHP version";
|
||||||
|
|
||||||
"mi_configuration" = "Configuration";
|
"mi_configuration" = "Configuration";
|
||||||
"mi_limits" = "Memory & Upload Limits";
|
"mi_limits" = "Limits Configuration";
|
||||||
"mi_memory_limit" = "Script Memory Limit";
|
"mi_memory_limit" = "Script Memory Limit";
|
||||||
"mi_post_max_size" = "Max POST Size";
|
"mi_post_max_size" = "Max POST Size";
|
||||||
"mi_upload_max_filesize" = "Max Upload File Size";
|
"mi_upload_max_filesize" = "Max Upload File Size";
|
||||||
|
Reference in New Issue
Block a user