mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-12-21 11:10:08 +01:00
1.2 KiB
1.2 KiB
ContainerMacro
A Swift macro for automatic container dependency injection in PHP Monitor.
Usage
import ContainerMacro
@ContainerAccess
class MyClass {
func doSomething() {
shell.run("command")
favorites.add(site)
warningManager.evaluateWarnings()
}
}
What it generates
The @ContainerAccess macro automatically adds:
- A private
container: Containerproperty - An
init(container:)with default parameterApp.shared.container - Computed properties for each Container service you want to access
Maintenance
When you add new services to Container, you must update the service list in:
Sources/ContainerMacroPlugin/ContainerAccessMacro.swift (lines 14-18):
let allContainerServices: [(name: String, type: String)] = [
("shell", "ShellProtocol"),
("favorites", "Favorites"),
("warningManager", "WarningManager"),
// Add your new service here:
// ("myNewService", "MyServiceType"),
]
Testing
Run tests with:
cd packages/container-macro
swift test
Integration
The package is added as a local Swift Package in Xcode:
- File → Add Package Dependencies → Add Local...
- Select
packages/container-macro