engine

package
v0.0.0-...-d82352a Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2016 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package engine provides methods allowing for the initialization and teardown of PHP engine bindings, off which execution contexts can be launched.

Index

Constants

This section is empty.

Variables

View Source
var PHP_INI_PATH_OVERRIDE string

Functions

func Define

func Define(name string, fn func(args []interface{}) interface{}) error

Define registers a PHP class for the name passed, using function fn as constructor for individual object instances as needed by the PHP context.

The class name registered is assumed to be unique for the active engine.

The constructor function accepts a slice of arguments, as passed by the PHP context, and should return a method receiver instance, or nil on error (in which case, an exception is thrown on the PHP object constructor).

func DestroyValue

func DestroyValue(zval *C.struct__zval_struct)

Destroy removes all active references to the internal PHP value and frees any resources used.

func Initialize

func Initialize() error

New initializes a PHP engine instance on which contexts can be executed. It corresponds to PHP's MINIT (module init) phase.

func IsNull

func IsNull(zval *C.struct__zval_struct) bool

func NewValue

func NewValue(val interface{}) (*C.struct__zval_struct, error)

NewValue creates a PHP value representation of a Go value val. Available bindings for Go to PHP types are:

int -> integer float64 -> double bool -> boolean string -> string slice -> indexed array map[int|string] -> associative array struct -> object

It is only possible to bind maps with integer or string keys. Only exported struct fields are passed to the PHP context. Bindings for functions and method receivers to PHP functions and classes are only available in the engine scope, and must be predeclared before context execution.

func RequestShutdown

func RequestShutdown(ctx *Context)

Destroy tears down the current execution context corresponds to PHP's RSHUTDOWN phase

func RequestStartup

func RequestStartup(ctx *Context) error

NewContext creates a new execution context for the active engine and returns an error if the execution context failed to initialize at any point. This corresponds to PHP's RINIT (request init) phase.

func ToBool

func ToBool(zval *C.struct__zval_struct) bool

Bool returns the internal PHP value as a boolean, converting if necessary.

func ToFloat

func ToFloat(zval *C.struct__zval_struct) float64

Float returns the internal PHP value as a floating point number, converting if necessary.

func ToInt

func ToInt(zval *C.struct__zval_struct) int64

Int returns the internal PHP value as an integer, converting if necessary.

func ToInterface

func ToInterface(zval *C.struct__zval_struct) interface{}

Interface returns the internal PHP value as it lies, with no conversion step.

func ToMap

func ToMap(v *C.struct__zval_struct) map[string]interface{}

Map returns the internal PHP value as a map of interface types, indexed by string keys. Non-array values are implicitly converted to single-element maps with a key of '0'.

func ToSlice

func ToSlice(zval *C.struct__zval_struct) []interface{}

Slice returns the internal PHP value as a slice of interface types. Non-array values are implicitly converted to single-element slices.

func ToString

func ToString(zval *C.struct__zval_struct) string

String returns the internal PHP value as a string, converting if necessary.

Types

type Context

type Context struct {
	// Output and Log are unbuffered writers used for regular and debug output,
	// respectively. If left unset, any data written into either by the calling
	// context will be lost.
	Output io.Writer
	Log    io.Writer

	// Http Input/Output
	ResponseWriter http.ResponseWriter
	Request        *http.Request

	// Other variables in $_SERVER
	DocumentRoot   string
	ScriptFileName string
	// contains filtered or unexported fields
}

Context represents an individual execution context.

func (*Context) Bind

func (c *Context) Bind(name string, val interface{}) error

Bind allows for binding Go values into the current execution context under a certain name. Bind returns an error if attempting to bind an invalid value (check the documentation for NewValue for what is considered to be a "valid" value).

func (*Context) Eval

func (c *Context) Eval(script string) (*C.struct__zval_struct, error)

Eval executes the PHP expression contained in script, and returns a Value containing the PHP value returned by the expression, if any. Any output produced is written context's pre-defined io.Writer instance.

func (*Context) Exec

func (c *Context) Exec(filename string) error

Exec executes a PHP script pointed to by filename in the current execution context, and returns an error, if any. Output produced by the script is written to the context's pre-defined io.Writer instance.

func (*Context) FinishRequest

func (ctx *Context) FinishRequest() error

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine represents the core PHP engine bindings.

type Receiver

type Receiver struct {
	// contains filtered or unexported fields
}

Receiver represents a method receiver.

func (*Receiver) Destroy

func (r *Receiver) Destroy()

Destroy removes references to the generated PHP class for this receiver and frees any memory used by object instances.

func (*Receiver) NewObject

func (r *Receiver) NewObject(args []interface{}) (*ReceiverObject, error)

NewObject instantiates a new method receiver object, using the Receiver's create function and passing in a slice of values as a parameter.

type ReceiverObject

type ReceiverObject struct {
	// contains filtered or unexported fields
}

ReceiverObject represents an object instance of a pre-defined method receiver.

func (*ReceiverObject) Call

func (o *ReceiverObject) Call(name string, args []interface{}) *C.struct__zval_struct

Call executes a method receiver's named internal method, passing a slice of values as arguments to the method. If the method fails to execute or returns no value, nil is returned, otherwise a Value instance is returned.

func (*ReceiverObject) Exists

func (o *ReceiverObject) Exists(name string) bool

Exists checks if named internal property exists and returns true, or false if property does not exist.

func (*ReceiverObject) Get

func (o *ReceiverObject) Get(name string) (*C.struct__zval_struct, error)

Get returns a named internal property of the receiver object instance, or an error if the property does not exist or is not addressable.

func (*ReceiverObject) Set

func (o *ReceiverObject) Set(name string, val interface{})

Set assigns value to named internal property. If the named property does not exist or cannot be set, the method does nothing.

type ValueKind

type ValueKind int

ValueKind represents the specific kind of type represented in Value.

const (
	IS_UNDEF     ValueKind = 0
	IS_NULL      ValueKind = 1
	IS_FALSE     ValueKind = 2
	IS_TRUE      ValueKind = 3
	IS_LONG      ValueKind = 4
	IS_DOUBLE    ValueKind = 5
	IS_STRING    ValueKind = 6
	IS_ARRAY     ValueKind = 7
	IS_OBJECT    ValueKind = 8
	IS_RESOURCE  ValueKind = 9
	IS_REFERENCE ValueKind = 10
)

ZVal types

func GetKind

func GetKind(zval *C.struct__zval_struct) ValueKind

Kind returns the Value's concrete kind of type.

Jump to

Keyboard shortcuts

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