2017-12-10 06:00:51 +01:00
|
|
|
package mvc2
|
|
|
|
|
2017-12-14 22:04:42 +01:00
|
|
|
import (
|
2017-12-15 19:28:06 +01:00
|
|
|
"github.com/kataras/iris/mvc2/di"
|
2017-12-14 22:04:42 +01:00
|
|
|
"reflect"
|
2017-12-10 06:00:51 +01:00
|
|
|
)
|
|
|
|
|
2017-12-14 22:04:42 +01:00
|
|
|
var (
|
|
|
|
typeChecker = func(fn reflect.Type) bool {
|
|
|
|
// invalid if that single input arg is not a typeof context.Context.
|
|
|
|
return isContext(fn.In(0))
|
2017-12-10 06:00:51 +01:00
|
|
|
}
|
|
|
|
|
2017-12-14 22:04:42 +01:00
|
|
|
hijacker = func(fieldOrFuncInput reflect.Type) (*di.BindObject, bool) {
|
|
|
|
if isContext(fieldOrFuncInput) {
|
|
|
|
return newContextBindObject(), true
|
2017-12-10 06:00:51 +01:00
|
|
|
}
|
2017-12-14 22:04:42 +01:00
|
|
|
return nil, false
|
2017-12-10 06:00:51 +01:00
|
|
|
}
|
2017-12-14 22:04:42 +01:00
|
|
|
)
|
2017-12-10 06:00:51 +01:00
|
|
|
|
2017-12-13 05:17:28 +01:00
|
|
|
// newContextBindObject is being used on both targetFunc and targetStruct.
|
|
|
|
// if the func's input argument or the struct's field is a type of Context
|
|
|
|
// then we can do a fast binding using the ctxValue
|
|
|
|
// which is used as slice of reflect.Value, because of the final method's `Call`.
|
2017-12-14 22:04:42 +01:00
|
|
|
func newContextBindObject() *di.BindObject {
|
|
|
|
return &di.BindObject{
|
2017-12-13 05:17:28 +01:00
|
|
|
Type: contextTyp,
|
2017-12-14 22:04:42 +01:00
|
|
|
BindType: di.Dynamic,
|
2017-12-13 05:17:28 +01:00
|
|
|
ReturnValue: func(ctxValue []reflect.Value) reflect.Value {
|
|
|
|
return ctxValue[0]
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|