mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 10:57:05 +00:00
remove the old 'mvc' folder - examples are not changed yet - add the 'di' package inside the mvc2 package - which will be renamed to 'mvc' on the next commit - new mvc.Application and some dublications removed - The new version will be version 9 because it will contain breaking changes (not to the end-developer's controllers but to the API they register them) - get ready for 'Christmas Edition' for believers
Former-commit-id: c7114233dee90ee308c0a3e77ec2ad0c361094b8
This commit is contained in:
@@ -1,65 +1,52 @@
|
||||
package mvc2
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/kataras/di"
|
||||
"github.com/kataras/iris/mvc2/di"
|
||||
"github.com/kataras/golog"
|
||||
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/core/router"
|
||||
)
|
||||
|
||||
var (
|
||||
errNil = errors.New("nil")
|
||||
errBad = errors.New("bad")
|
||||
errAlreadyExists = errors.New("already exists")
|
||||
)
|
||||
|
||||
type Engine struct {
|
||||
dependencies *di.D
|
||||
Dependencies *di.D
|
||||
}
|
||||
|
||||
func New() *Engine {
|
||||
func NewEngine() *Engine {
|
||||
return &Engine{
|
||||
dependencies: di.New().Hijack(hijacker).GoodFunc(typeChecker),
|
||||
Dependencies: di.New().Hijack(hijacker).GoodFunc(typeChecker),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Engine) Bind(values ...interface{}) *Engine {
|
||||
e.dependencies.Bind(values...)
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Engine) Child() *Engine {
|
||||
child := New()
|
||||
child.dependencies = e.dependencies.Clone()
|
||||
func (e *Engine) Clone() *Engine {
|
||||
child := NewEngine()
|
||||
child.Dependencies = e.Dependencies.Clone()
|
||||
return child
|
||||
}
|
||||
|
||||
func (e *Engine) Handler(handler interface{}) context.Handler {
|
||||
h, err := MakeHandler(handler, e.dependencies.Values...)
|
||||
h, err := MakeHandler(handler, e.Dependencies.Values...)
|
||||
if err != nil {
|
||||
golog.Errorf("mvc handler: %v", err)
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func (e *Engine) Controller(router router.Party, controller interface{}, onActivate ...func(*ControllerActivator)) {
|
||||
ca := newControllerActivator(router, controller, e.dependencies)
|
||||
func (e *Engine) Controller(router router.Party, controller interface{}, beforeActivate ...func(*ControllerActivator)) {
|
||||
ca := newControllerActivator(router, controller, e.Dependencies)
|
||||
|
||||
// give a priority to the "onActivate"
|
||||
// give a priority to the "beforeActivate"
|
||||
// callbacks, if any.
|
||||
for _, cb := range onActivate {
|
||||
for _, cb := range beforeActivate {
|
||||
cb(ca)
|
||||
}
|
||||
|
||||
// check if controller has an "OnActivate" function
|
||||
// check if controller has an "BeforeActivate" function
|
||||
// which accepts the controller activator and call it.
|
||||
if activateListener, ok := controller.(interface {
|
||||
OnActivate(*ControllerActivator)
|
||||
BeforeActivate(*ControllerActivator)
|
||||
}); ok {
|
||||
activateListener.OnActivate(ca)
|
||||
activateListener.BeforeActivate(ca)
|
||||
}
|
||||
|
||||
ca.activate()
|
||||
|
||||
Reference in New Issue
Block a user