1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-12-21 03:10:06 +01:00
Files
app/packages/container-macro
2025-10-16 14:43:29 +02:00
..
2025-10-16 14:43:29 +02:00
2025-10-16 11:37:42 +02:00
2025-10-05 17:30:35 +02:00
2025-10-05 17:30:35 +02:00

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: Container property
  • An init(container:) with default parameter App.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