Documentation
¶
Overview ¶
Package core holds the part of PHP's standard library that computes: strings, arrays, json, the language constructs exposed as functions, the tokenizer, the environment and the platform surface a program expects to find before it does anything interesting. It also holds the phpscript extensions that are each too small to be worth a package: SharedMemory, defer and register_shutdown_function.
The line against stdlib/compat is behavioural, not historical: compat holds the surface whose behaviour is the interpreter's (output buffering, preg_*, the date functions), core holds the surface whose behaviour is its own.
Every file registers its own area from its own init(), so an area is added, moved or dropped without touching another file. Importing the package is what wires them in, the way a program imports a database/sql driver:
import _ "github.com/titpetric/phpscript/stdlib/core"
stdlib/imports.go does that for you.
Index ¶
- func RegisterDefer(rt *runner.Runtime)
- func RegisterSharedMemory(rt *runner.Runtime)
- func RegisterShutdown(rt *runner.Runtime)
- func SharedMemoryContext(ctx context.Context, s *SharedMemory) context.Context
- type SharedMemory
- func (s *SharedMemory) Clear(_ context.Context)
- func (s *SharedMemory) Count(_ context.Context, key string) string
- func (s *SharedMemory) Delete(_ context.Context, key string) bool
- func (s *SharedMemory) Get(_ context.Context, key string) string
- func (s *SharedMemory) Has(_ context.Context, key string) bool
- func (s *SharedMemory) Incr(_ context.Context, key string) int64
- func (s *SharedMemory) Set(_ context.Context, key, value string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterDefer ¶
RegisterDefer installs defer() in the global function namespace.
func RegisterSharedMemory ¶
RegisterSharedMemory installs SharedMemory in the runtime.
func RegisterShutdown ¶
RegisterShutdown installs register_shutdown_function() in the global function namespace. Callbacks run in registration order when Runtime.Run finishes, including after exit or an execution error.
func SharedMemoryContext ¶
func SharedMemoryContext(ctx context.Context, s *SharedMemory) context.Context
SharedMemoryContext binds an SharedMemory instance into the context.
Types ¶
type SharedMemory ¶
type SharedMemory struct {
// contains filtered or unexported fields
}
SharedMemory is a thread-safe in-memory key-value and atomic counter store exposed as SharedMemory to scripts.
func NewSharedMemory ¶
func NewSharedMemory() *SharedMemory
NewSharedMemory returns a new empty SharedMemory instance.
func NewSharedMemoryBinding ¶
func NewSharedMemoryBinding(ctx context.Context) (*SharedMemory, error)
NewSharedMemoryBinding is a key-value and counter store shared across requests: `new SharedMemory` returns the store the host bound into the runtime context, or a fresh empty store when none is bound.
func (*SharedMemory) Clear ¶
func (s *SharedMemory) Clear(_ context.Context)
Clear resets all keys and counters.
func (*SharedMemory) Count ¶
func (s *SharedMemory) Count(_ context.Context, key string) string
Count returns a counter as a formatted string.
func (*SharedMemory) Delete ¶
func (s *SharedMemory) Delete(_ context.Context, key string) bool
Delete removes a key from storage.
func (*SharedMemory) Get ¶
func (s *SharedMemory) Get(_ context.Context, key string) string
Get retrieves a string value by key, or returns empty string if missing.
func (*SharedMemory) Has ¶
func (s *SharedMemory) Has(_ context.Context, key string) bool
Has checks if a key exists in data or counters.