phpv

package
v0.0.0-...-271b4c5 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2018 License: BSD-3-Clause Imports: 12 Imported by: 56

Documentation

Overview

Package phpv contains all required types and interfaces for storing Goro values, context or compiled PHP code.

Index

Constants

View Source
const (
	// would use 1 << iota but those values come from php, so making them constants is more appropriate
	ZClassStatic           ZClassAttr = 0x001
	ZClassAbstract                    = 0x002
	ZClassImplAbstract                = 0x008 // an abstract method which has been implemented
	ZClassImplicitAbstract            = 0x010 // for classes
	ZClassExplicitAbstract            = 0x020 // for classes
	ZClassFinal                       = 0x040 // class attribute (not method)
	ZClassTrait                       = 0x80
	ZClassAnon                        = 0x100
	ZClassAnonBound                   = 0x200
	ZClassInherited                   = 0x400

	ZClassTypeImplicitAbstract ZClassType = 0x10
	ZClassTypeExplicitAbstract            = 0x20
	ZClassTypeInterface                   = 0x40
	ZClassTypeTrait                       = 0x80
	ZClassTypeAnon                        = 0x100

	ZAttrStatic         ZObjectAttr = ZObjectAttr(ZClassStatic)
	ZAttrAbstract                   = ZObjectAttr(ZClassAbstract)
	ZAttrFinal                      = 0x004 // final method, not the same value as ZClassFinal
	ZAttrPublic                     = 0x100
	ZAttrProtected                  = 0x200
	ZAttrPrivate                    = 0x400
	ZAttrAccess                     = ZAttrPublic | ZAttrProtected | ZAttrPrivate
	ZAttrImplicitPublic             = 0x1000 // method without flag
	ZAttrCtor                       = 0x2000
	ZAttrDtor                       = 0x4000
	ZAttrUserArgInfo                = 0x80    // method flag used by Closure::__invoke()
	ZAttrAllowStatic                = 0x10000 // method flag (bc only), any method that has this flag can be used statically and non statically.
	ZAttrShadow                     = 0x20000 // shadow of parent's private method/property
	ZAttrDeprecated                 = 0x40000 // deprecation flag
	ZAttrClosure                    = 0x100000
	ZAttrFakeClosure                = 0x40
	ZAttrGenerator                  = 0x800000
	ZAttrViaTrampoline              = 0x200000           // call through user function trampoline. e.g. __call, __callstatic
	ZAttrViaHandler                 = ZAttrViaTrampoline // call through internal function handler. e.g. Closure::invoke()
	ZAttrVariadic                   = 0x1000000
	ZAttrReturnRef                  = 0x4000000
	ZAttrUseGuard                   = 0x1000000  // class has magic methods __get/__set/__unset/__isset that use guards
	ZAttrHasTypeHints               = 0x10000000 // function has typed arguments
	ZAttrHasReturnType              = 0x40000000 // Function has a return type (or class has such non-private function)
)

Variables

View Source
var ZNULL = ZNull{}

global NULL for easy call

Functions

func DebugDump

func DebugDump(v Runnable) string

func ExitError

func ExitError(retcode ZInt) error

func FilterError

func FilterError(err error) error

Types

type Callable

type Callable interface {
	Call(ctx Context, args []*ZVal) (*ZVal, error)
}

type Compilable

type Compilable interface {
	Compile(ctx Context) error
}

type CompileDelayed

type CompileDelayed struct {
	V Runnable
}

func (*CompileDelayed) AsVal

func (c *CompileDelayed) AsVal(ctx Context, t ZType) (Val, error)

func (*CompileDelayed) GetType

func (c *CompileDelayed) GetType() ZType

func (*CompileDelayed) Run

func (c *CompileDelayed) Run(ctx Context) (*ZVal, error)

func (*CompileDelayed) String

func (c *CompileDelayed) String() string

func (*CompileDelayed) Value

func (c *CompileDelayed) Value() Val

func (*CompileDelayed) ZVal

func (c *CompileDelayed) ZVal() *ZVal

type Context

type Context interface {
	context.Context
	ZArrayAccess
	ZCountable
	ZIterable
	io.Writer

	Global() GlobalContext
	Func() FuncContext
	Parent(n int) Context
	This() ZObject
	Loc() *Loc
	Tick(ctx Context, l *Loc) error
	MemAlloc(ctx Context, s uint64) error

	GetConfig(name ZString, def *ZVal) *ZVal

	Call(ctx Context, f Callable, args []Runnable, this ZObject) (*ZVal, error)
	CallZVal(ctx Context, f Callable, args []*ZVal, this ZObject) (*ZVal, error)
}

type FuncArg

type FuncArg struct {
	VarName      ZString
	Ref          bool
	Required     bool
	DefaultValue Val
	Hint         *TypeHint
}

type FuncContext

type FuncContext interface {
	Context
}

type FuncGetArgs

type FuncGetArgs interface {
	GetArgs() []*FuncArg
}

type FuncUse

type FuncUse struct {
	VarName ZString
	Value   *ZVal
}

type GlobalContext

type GlobalContext interface {
	Context

	Flush()

	RegisterFunction(name ZString, f Callable) error
	GetFunction(ctx Context, name ZString) (Callable, error)

	RegisterClass(name ZString, c ZClass) error
	GetClass(ctx Context, name ZString, autoload bool) (ZClass, error)
	SetLocalConfig(name ZString, val *ZVal) error

	ConstantSet(k ZString, v Val) bool
	ConstantGet(k ZString) (Val, bool)

	RegisterLazyFunc(name ZString, r Runnables, p int)
	RegisterLazyClass(name ZString, r Runnables, p int)

	Open(fn ZString, isInclude bool) (*stream.Stream, error)
	Exists(fn ZString) (bool, error)
	Chdir(d ZString) error
	Getwd() ZString

	Getenv(key string) (string, bool)
	Setenv(key, value string) error
	Unsetenv(key string) error

	Include(ctx Context, fn ZString) (*ZVal, error)
	Require(ctx Context, fn ZString) (*ZVal, error)
	IncludeOnce(ctx Context, fn ZString) (*ZVal, error)
	RequireOnce(ctx Context, fn ZString) (*ZVal, error)
}

type Loc

type Loc struct {
	Filename   string
	Line, Char int
}

func (*Loc) Dump

func (l *Loc) Dump(w io.Writer) error

func (*Loc) Error

func (l *Loc) Error(e error) *PhpError

func (*Loc) Errorf

func (l *Loc) Errorf(ctx Context, code PhpErrorType, f string, arg ...interface{}) *PhpError

func (*Loc) Loc

func (l *Loc) Loc() *Loc

func (*Loc) Run

func (l *Loc) Run(ctx Context) (*ZVal, error)

func (*Loc) String

func (l *Loc) String() string

type ObjectCallable

type ObjectCallable interface {
	GetMethod(method ZString, ctx Context, args []*ZVal) (*ZVal, error)
}

type PhpError

type PhpError struct {
	Err  error
	Code PhpErrorType
	// contains filtered or unexported fields
}

func (*PhpError) Error

func (e *PhpError) Error() string

func (*PhpError) IsExit

func (e *PhpError) IsExit() bool

func (*PhpError) Loc

func (e *PhpError) Loc() *Loc

type PhpErrorType

type PhpErrorType int
const (
	E_ERROR PhpErrorType = 1 << iota
	E_WARNING
	E_PARSE
	E_NOTICE
	E_CORE_ERROR
	E_CORE_WARNING
	E_COMPILE_ERROR
	E_COMPILE_WARNING
	E_USER_ERROR
	E_USER_WARNING
	E_USER_NOTICE
	E_STRICT
	E_RECOVERABLE_ERROR
	E_DEPRECATED
	E_USER_DEPRECATED
	E_ALL PhpErrorType = (1 << iota) - 1
)

type PhpExit

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

func (*PhpExit) Dump

func (e *PhpExit) Dump(w io.Writer) error

func (*PhpExit) Error

func (e *PhpExit) Error() string

func (*PhpExit) Loc

func (e *PhpExit) Loc() *Loc

func (*PhpExit) Run

func (e *PhpExit) Run(ctx Context) (*ZVal, error)

type RunNull

type RunNull struct{}

func (RunNull) Dump

func (r RunNull) Dump(w io.Writer) error

func (RunNull) Run

func (r RunNull) Run(ctx Context) (*ZVal, error)

type Runnable

type Runnable interface {
	Run(Context) (*ZVal, error)
	Dump(io.Writer) error
}

type Runnables

type Runnables []Runnable

func (Runnables) Dump

func (r Runnables) Dump(w io.Writer) error

func (Runnables) DumpWith

func (r Runnables) DumpWith(w io.Writer, sep []byte) error

func (Runnables) Run

func (r Runnables) Run(ctx Context) (l *ZVal, err error)

type TypeHint

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

func ParseTypeHint

func ParseTypeHint(s ZString) *TypeHint

type Val

type Val interface {
	GetType() ZType                          // GetType returns the type of the value
	ZVal() *ZVal                             // ZVal returns a ZVal pointing to this value
	Value() Val                              // Value returns the raw value, in case it was in a ZVal
	AsVal(ctx Context, t ZType) (Val, error) // AsVal converts the value to another type
	String() string                          // String should only be used on ZtString values
}

Val is a basic value of any PHP kind: null, bool, int, float, string, array, resource or object.

type Writable

type Writable interface {
	WriteValue(ctx Context, value *ZVal) error
}

type ZArray

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

func NewZArray

func NewZArray() *ZArray

func (*ZArray) AsVal

func (a *ZArray) AsVal(ctx Context, t ZType) (Val, error)

func (*ZArray) Count

func (a *ZArray) Count(ctx Context) ZInt

func (*ZArray) Dup

func (a *ZArray) Dup() *ZArray

func (*ZArray) GetType

func (a *ZArray) GetType() ZType

func (*ZArray) HasStringKeys

func (a *ZArray) HasStringKeys() bool

func (*ZArray) HashTable

func (a *ZArray) HashTable() *ZHashTable

func (*ZArray) MergeArray

func (a *ZArray) MergeArray(b *ZArray) error

func (*ZArray) MergeTable

func (a *ZArray) MergeTable(h *ZHashTable) error

func (*ZArray) NewIterator

func (a *ZArray) NewIterator() ZIterator

func (*ZArray) OffsetExists

func (a *ZArray) OffsetExists(ctx Context, key Val) (bool, error)

func (*ZArray) OffsetGet

func (a *ZArray) OffsetGet(ctx Context, key Val) (*ZVal, error)

func (*ZArray) OffsetSet

func (a *ZArray) OffsetSet(ctx Context, key Val, value *ZVal) error

func (*ZArray) OffsetUnset

func (a *ZArray) OffsetUnset(ctx Context, key Val) error

func (*ZArray) String

func (a *ZArray) String() string

func (*ZArray) Value

func (a *ZArray) Value() Val

func (*ZArray) ZVal

func (a *ZArray) ZVal() *ZVal

type ZArrayAccess

type ZArrayAccess interface {
	OffsetGet(ctx Context, key Val) (*ZVal, error)
	OffsetSet(ctx Context, key Val, value *ZVal) error
	OffsetUnset(ctx Context, key Val) error
	OffsetExists(ctx Context, key Val) (bool, error)
}

type ZBool

type ZBool bool

func (ZBool) AsVal

func (z ZBool) AsVal(ctx Context, t ZType) (Val, error)

func (ZBool) GetType

func (z ZBool) GetType() ZType

func (ZBool) String

func (z ZBool) String() string

func (ZBool) Value

func (z ZBool) Value() Val

func (ZBool) ZVal

func (z ZBool) ZVal() *ZVal

type ZClass

type ZClass interface {
	GetName() ZString
	InstanceOf(subc ZClass) bool
	BaseName() ZString
	GetStaticProps(ctx Context) (*ZHashTable, error)
	GetMethod(name ZString) (*ZClassMethod, bool)
	Handlers() *ZClassHandlers
	GetParent() ZClass
}

type ZClassAttr

type ZClassAttr int

func (ZClassAttr) Has

func (a ZClassAttr) Has(c ZClassAttr) bool

func (ZClassAttr) String

func (a ZClassAttr) String() string

type ZClassHandlers

type ZClassHandlers struct {
	Constructor  *ZClassMethod
	HandleInvoke func(ctx Context, o ZObject, args []Runnable) (*ZVal, error)
}

type ZClassMethod

type ZClassMethod struct {
	Name      ZString
	Modifiers ZObjectAttr
	Method    Callable
}

type ZClassProp

type ZClassProp struct {
	VarName   ZString
	Default   Val
	Modifiers ZObjectAttr
}

type ZClassType

type ZClassType int

func (ZClassType) Has

func (a ZClassType) Has(c ZClassType) bool

func (ZClassType) IsInterface

func (a ZClassType) IsInterface() bool

type ZClosure

type ZClosure interface {
	FuncGetArgs
	Callable
	Runnable

	GetClass() ZClass
}

type ZCountable

type ZCountable interface {
	Count(ctx Context) ZInt
}

type ZFloat

type ZFloat float64

func (ZFloat) AsVal

func (z ZFloat) AsVal(ctx Context, t ZType) (Val, error)

func (ZFloat) GetType

func (z ZFloat) GetType() ZType

func (ZFloat) String

func (v ZFloat) String() string

func (ZFloat) Value

func (v ZFloat) Value() Val

func (ZFloat) ZVal

func (z ZFloat) ZVal() *ZVal

type ZHashTable

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

func NewHashTable

func NewHashTable() *ZHashTable

func (*ZHashTable) Append

func (z *ZHashTable) Append(v *ZVal) error

func (*ZHashTable) Array

func (z *ZHashTable) Array() *ZArray

func (*ZHashTable) Count

func (z *ZHashTable) Count() ZInt

func (*ZHashTable) Dup

func (z *ZHashTable) Dup() *ZHashTable

func (*ZHashTable) GetInt

func (z *ZHashTable) GetInt(k ZInt) *ZVal

func (*ZHashTable) GetString

func (z *ZHashTable) GetString(k ZString) *ZVal

func (*ZHashTable) GetStringB

func (z *ZHashTable) GetStringB(k ZString) (*ZVal, bool)

func (*ZHashTable) HasInt

func (z *ZHashTable) HasInt(k ZInt) bool

func (*ZHashTable) HasString

func (z *ZHashTable) HasString(k ZString) bool

func (ZHashTable) HasStringKeys

func (z ZHashTable) HasStringKeys() bool

func (*ZHashTable) MergeTable

func (z *ZHashTable) MergeTable(b *ZHashTable) error

func (*ZHashTable) NewIterator

func (z *ZHashTable) NewIterator() ZIterator

func (*ZHashTable) SetInt

func (z *ZHashTable) SetInt(k ZInt, v *ZVal) error

func (*ZHashTable) SetString

func (z *ZHashTable) SetString(k ZString, v *ZVal) error

func (*ZHashTable) UnsetInt

func (z *ZHashTable) UnsetInt(k ZInt) error

func (*ZHashTable) UnsetString

func (z *ZHashTable) UnsetString(k ZString) error

type ZInt

type ZInt int64

func (ZInt) AsVal

func (z ZInt) AsVal(ctx Context, t ZType) (Val, error)

func (ZInt) GetType

func (z ZInt) GetType() ZType

func (ZInt) String

func (v ZInt) String() string

func (ZInt) Value

func (v ZInt) Value() Val

func (ZInt) ZVal

func (z ZInt) ZVal() *ZVal

type ZIterable

type ZIterable interface {
	NewIterator() ZIterator
}

type ZIterator

type ZIterator interface {
	Current(ctx Context) (*ZVal, error)
	Key(ctx Context) (*ZVal, error)
	Next(ctx Context) error
	Rewind(ctx Context) error
	Valid(ctx Context) bool
}

type ZNull

type ZNull struct{}

scalar stuff

func (ZNull) AsVal

func (z ZNull) AsVal(ctx Context, t ZType) (Val, error)

func (ZNull) GetType

func (z ZNull) GetType() ZType

func (ZNull) String

func (v ZNull) String() string

func (ZNull) Value

func (z ZNull) Value() Val

func (ZNull) ZVal

func (z ZNull) ZVal() *ZVal

type ZObject

type ZObject interface {
	ZObjectAccess
	Val

	GetOpaque(c ZClass) interface{}
	SetOpaque(c ZClass, v interface{})
	GetClass() ZClass
	NewIterator() ZIterator
	HashTable() *ZHashTable
	Clone() (ZObject, error)
}

type ZObjectAccess

type ZObjectAccess interface {
	ObjectGet(ctx Context, key Val) (*ZVal, error)
	ObjectSet(ctx Context, key Val, value *ZVal) error
}

type ZObjectAttr

type ZObjectAttr int

func (ZObjectAttr) Access

func (a ZObjectAttr) Access() ZObjectAttr

func (ZObjectAttr) Has

func (a ZObjectAttr) Has(c ZObjectAttr) bool

func (ZObjectAttr) IsPrivate

func (a ZObjectAttr) IsPrivate() bool

func (ZObjectAttr) IsProtected

func (a ZObjectAttr) IsProtected() bool

func (ZObjectAttr) IsPublic

func (a ZObjectAttr) IsPublic() bool

func (ZObjectAttr) IsStatic

func (a ZObjectAttr) IsStatic() bool

type ZString

type ZString string

func (ZString) AsNumeric

func (z ZString) AsNumeric() (Val, error)

func (ZString) AsVal

func (z ZString) AsVal(ctx Context, t ZType) (Val, error)

func (ZString) GetType

func (z ZString) GetType() ZType

func (ZString) IsNumeric

func (s ZString) IsNumeric() bool

func (ZString) LooksInt

func (s ZString) LooksInt() bool

func (ZString) String

func (v ZString) String() string

func (ZString) ToLower

func (s ZString) ToLower() ZString

func (ZString) Value

func (v ZString) Value() Val

func (ZString) ZVal

func (z ZString) ZVal() *ZVal

type ZType

type ZType int
const (
	ZtNull ZType = iota
	ZtBool
	ZtInt
	ZtFloat
	ZtString
	ZtArray
	ZtObject
	ZtResource
)

func (ZType) String

func (zt ZType) String() string

type ZVal

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

ZVal is a pointer to a value, that can be used as a Val, a reference, etc.

Eventually, ZVal will only be used for references.

func MakeZVal

func MakeZVal(v Val) *ZVal

func ZStr

func ZStr(s string) *ZVal

func (*ZVal) Array

func (z *ZVal) Array() ZArrayAccess

func (*ZVal) As

func (z *ZVal) As(ctx Context, t ZType) (*ZVal, error)

func (*ZVal) AsBool

func (z *ZVal) AsBool(ctx Context) ZBool

func (*ZVal) AsFloat

func (z *ZVal) AsFloat(ctx Context) ZFloat

func (*ZVal) AsInt

func (z *ZVal) AsInt(ctx Context) ZInt

func (*ZVal) AsNumeric

func (z *ZVal) AsNumeric(ctx Context) (*ZVal, error)

func (*ZVal) AsString

func (z *ZVal) AsString(ctx Context) ZString

func (*ZVal) AsVal

func (z *ZVal) AsVal(ctx Context, t ZType) (Val, error)

func (*ZVal) CastTo

func (z *ZVal) CastTo(ctx Context, t ZType) error

func (*ZVal) Dup

func (z *ZVal) Dup() *ZVal

func (*ZVal) GetType

func (z *ZVal) GetType() ZType

func (*ZVal) HashTable

func (z *ZVal) HashTable() *ZHashTable

func (*ZVal) IsNull

func (z *ZVal) IsNull() bool

func (*ZVal) IsRef

func (z *ZVal) IsRef() bool

func (*ZVal) NewIterator

func (z *ZVal) NewIterator() ZIterator

func (*ZVal) Nude

func (z *ZVal) Nude() *ZVal

Returns actual zval, dropping status of reference

func (*ZVal) Ref

func (z *ZVal) Ref() *ZVal

Ref returns a reference to this zval while making it itself a ref

func (*ZVal) Set

func (z *ZVal) Set(nz *ZVal)

func (*ZVal) String

func (z *ZVal) String() string

func (*ZVal) Value

func (z *ZVal) Value() Val

func (*ZVal) ZVal

func (z *ZVal) ZVal() *ZVal

ZVal will make a copy of a given zval without actually copying memory

Jump to

Keyboard shortcuts

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