1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-12-21 03:10:06 +01:00
Files
app/packages/container-macro/README.md
2025-10-16 18:58:10 +02:00

1.1 KiB

ContainerMacro

A Swift macro for automatic container dependency injection in PHP Monitor.

Usage

import ContainerMacro

@ContainerAccess
class MyClass {
    func doSomething() {
        container.shell.run("command")
        container.favorites.add(site)
    }
}

What it generates

The @ContainerAccess macro automatically adds:

  • A private container: Container property
  • An init(_ container:) initializer
  • 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"),
    // 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