Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Record ¶
Record is a rich value type returned to PHP. Its exported fields are read from PHP via property access (`$rec->key`, `$rec->value`), matched case-insensitively.
type Storage ¶
type Storage interface {
Set(ctx context.Context, key, value string)
Get(ctx context.Context, key string) (Record, error)
All(ctx context.Context) ([]Record, error)
Len() int64
Tenant() string
}
Storage is a host capability exposed to PHP. The constructor takes a context.Context (auto-injected by the runner) and may fail; its methods read and write key/value pairs. This is the "bring your own type" bridge:
PHP: $storage = new Storage; // == storage, err := NewStorage(ctx)
$storage->set("k", "v"); // storage.Set("k", "v")
$val = $storage->get("k"); // val, err := storage.Get("k")
echo $val; // print the assigned value
Every method takes a context.Context as its first parameter; the runner auto-injects the runtime context, so PHP calls them without it (`$storage->get("k")` == storage.Get(ctx, "k")).
Example ¶
ctx := context.WithValue(context.Background(), tenantKey, "acme")
storage, err := NewStorage(ctx)
if err != nil {
fmt.Println(err)
return
}
storage.Set(ctx, "color", "blue")
record, err := storage.Get(ctx, "color")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(storage.Tenant())
fmt.Println(record.Key, record.Value)
fmt.Println(storage.Len())
Output: acme color blue 1
func NewFailStorage ¶
NewFailStorage is a constructor that always fails, used to exercise the thrown-error path of `new`.