MCPcopy Create free account
hub / github.com/deuill/go-php / NewObject

Method NewObject

engine/receiver.go:30–65  ·  view source on GitHub ↗

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

(args []interface{})

Source from the content-addressed store, hash-verified

28// NewObject instantiates a new method receiver object, using the Receiver's
29// create function and passing in a slice of values as a parameter.
30func (r *Receiver) NewObject(args []interface{}) (*ReceiverObject, error) {
31 obj := &ReceiverObject{
32 instance: r.create(args),
33 values: make(map[string]reflect.Value),
34 methods: make(map[string]reflect.Value),
35 }
36
37 if obj.instance == nil {
38 return nil, fmt.Errorf("Failed to instantiate method receiver")
39 }
40
41 v := reflect.ValueOf(obj.instance)
42 vi := reflect.Indirect(v)
43
44 for i := 0; i < v.NumMethod(); i++ {
45 // Skip unexported methods.
46 if v.Type().Method(i).PkgPath != "" {
47 continue
48 }
49
50 obj.methods[v.Type().Method(i).Name] = v.Method(i)
51 }
52
53 if vi.Kind() == reflect.Struct {
54 for i := 0; i < vi.NumField(); i++ {
55 // Skip unexported fields.
56 if vi.Type().Field(i).PkgPath != "" {
57 continue
58 }
59
60 obj.values[vi.Type().Field(i).Name] = vi.Field(i)
61 }
62 }
63
64 return obj, nil
65}
66
67// Destroy removes references to the generated PHP class for this receiver and
68// frees any memory used by object instances.

Callers 1

engineReceiverNewFunction · 0.80

Calls 1

KindMethod · 0.80

Tested by

no test coverage detected