tests

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Record

type Record struct {
	Key   string
	Value string
}

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

func NewFailStorage(ctx context.Context) (Storage, error)

NewFailStorage is a constructor that always fails, used to exercise the thrown-error path of `new`.

func NewStorage

func NewStorage(ctx context.Context) (Storage, error)

NewStorage is the constructor registered for `new Storage`. Its first parameter is a context.Context, filled in automatically by the runner, so PHP calls `new Storage` with no arguments.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL