1
0
mirror of https://github.com/deuill/go-php.git synced 2024-09-21 00:40:45 +00:00
go-php/engine.go
Alex Palaistras 6fa93f5160 First version of variable bindings to context.
This commit contains an initial version of variable bindings
to a context, along with tests. Currently supported types are
integers, floating point numbers, and strings.
2015-09-20 01:16:43 +01:00

48 lines
900 B
Go

package php
// #cgo CFLAGS: -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM
// #cgo CFLAGS: -I/usr/include/php/Zend
// #cgo LDFLAGS: -lphp5
//
// #include <stdio.h>
// #include "engine.h"
// #include "context.h"
import "C"
import (
"fmt"
"io"
"unsafe"
)
type Engine struct {
engine *C.struct__php_engine
}
func (e *Engine) NewContext(w io.Writer) (*Context, error) {
ctx := &Context{writer: w, zvals: make(map[string]unsafe.Pointer)}
ptr, err := C.context_new(e.engine, unsafe.Pointer(ctx))
if err != nil {
return nil, fmt.Errorf("Failed to initialize context for PHP engine")
}
ctx.context = ptr
return ctx, nil
}
func (e *Engine) Destroy() {
C.engine_shutdown(e.engine)
e = nil
}
func New() (*Engine, error) {
ptr, err := C.engine_init()
if err != nil {
return nil, fmt.Errorf("PHP engine failed to initialize")
}
return &Engine{engine: ptr}, nil
}