core

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 24 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDefer

func RegisterDefer(rt *runner.Runtime)

RegisterDefer installs defer() in the global function namespace.

func RegisterSharedMemory

func RegisterSharedMemory(rt *runner.Runtime)

RegisterSharedMemory installs SharedMemory in the runtime.

func RegisterShutdown

func RegisterShutdown(rt *runner.Runtime)

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.

func (*SharedMemory) Incr

func (s *SharedMemory) Incr(_ context.Context, key string) int64

Incr atomically increments and returns a counter.

func (*SharedMemory) Set

func (s *SharedMemory) Set(_ context.Context, key, value string)

Set stores a string value.

Jump to

Keyboard shortcuts

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