2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2017-12-29 16:03:30 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2017-12-29 16:03:30 +08:00
|
|
|
|
2019-01-16 09:00:23 +08:00
|
|
|
// Package gmvc provides basic object classes for MVC.
|
2017-12-11 17:16:59 +08:00
|
|
|
package gmvc
|
2017-12-08 09:50:11 +08:00
|
|
|
|
2017-12-13 16:45:00 +08:00
|
|
|
import (
|
2019-07-29 21:01:19 +08:00
|
|
|
"github.com/gogf/gf/net/ghttp"
|
2017-12-13 16:45:00 +08:00
|
|
|
)
|
|
|
|
|
2020-02-24 21:09:19 +08:00
|
|
|
// Controller is used for controller register of ghttp.Server.
|
2017-12-08 09:50:11 +08:00
|
|
|
type Controller struct {
|
2020-02-24 21:09:19 +08:00
|
|
|
Request *ghttp.Request
|
|
|
|
Response *ghttp.Response
|
|
|
|
Server *ghttp.Server
|
|
|
|
Cookie *ghttp.Cookie
|
|
|
|
Session *ghttp.Session
|
|
|
|
View *View
|
2017-12-13 16:45:00 +08:00
|
|
|
}
|
|
|
|
|
2020-02-24 21:09:19 +08:00
|
|
|
// Init is the callback function for each request initialization.
|
2018-01-02 15:52:32 +08:00
|
|
|
func (c *Controller) Init(r *ghttp.Request) {
|
2019-06-19 09:06:52 +08:00
|
|
|
c.Request = r
|
|
|
|
c.Response = r.Response
|
|
|
|
c.Server = r.Server
|
|
|
|
c.View = NewView(r.Response)
|
|
|
|
c.Cookie = r.Cookie
|
|
|
|
c.Session = r.Session
|
2017-12-08 09:50:11 +08:00
|
|
|
}
|
2017-12-13 16:45:00 +08:00
|
|
|
|
2020-02-24 21:09:19 +08:00
|
|
|
// Shut is the callback function for each request close.
|
2018-12-28 21:46:01 +08:00
|
|
|
func (c *Controller) Shut() {
|
2017-12-30 23:49:55 +08:00
|
|
|
|
2017-12-13 16:45:00 +08:00
|
|
|
}
|
|
|
|
|
2020-02-24 21:09:19 +08:00
|
|
|
// Exit equals to function Request.Exit().
|
2018-04-16 16:50:24 +08:00
|
|
|
func (c *Controller) Exit() {
|
2019-06-19 09:06:52 +08:00
|
|
|
c.Request.Exit()
|
2018-04-16 16:50:24 +08:00
|
|
|
}
|