1
0
mirror of https://github.com/deuill/go-php.git synced 2024-09-21 08:50:45 +00:00
go-php/engine.go
Alex Palaistras bd0f41e3d5 Initial commit of entire workspace
Code was seperated out from the Sigil web application framework.
https://github.com/deuill/sigil
2015-09-17 22:22:07 +01:00

48 lines
860 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}
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
}