-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.hh
118 lines (102 loc) · 3.04 KB
/
Controller.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?hh // partial
// Because of PSR.
/**
* @copyright 2010-2015, The Titon Project
* @license http://opensource.org/licenses/bsd-license.php
* @link http://titon.io
*/
namespace Titon\Controller;
use Psr\Http\Message\OutgoingResponseInterface;
use Psr\Http\Message\IncomingRequestInterface;
use Titon\Controller\Action;
use Titon\View\View;
use \Exception;
/**
* Interface for the controllers library.
*
* @package Titon\Controller
*/
interface Controller {
/**
* Dispatch to an action with a list of arguments and use the output as the HTTP response.
* If an exception is thrown within an action, or an action returns void, automatically render a view.
*
* @param string $action
* @param \Titon\Controller\ArgumentList $args
* @return \Psr\Http\Message\OutgoingResponseInterface
*/
public function dispatchTo(string $action, ArgumentList $args): OutgoingResponseInterface;
/**
* Forward the current request to a new action, instead of doing an additional HTTP request.
*
* @param string $action
* @param \Titon\Controller\ArgumentList $args
* @return \Psr\Http\Message\OutgoingResponseInterface
*/
public function forwardTo(string $action, ArgumentList $args): OutgoingResponseInterface;
/**
* Return the request object.
*
* @return \Psr\Http\Message\IncomingRequestInterface
*/
public function getRequest(): IncomingRequestInterface;
/**
* Return the response object.
*
* @return \Psr\Http\Message\OutgoingResponseInterface
*/
public function getResponse(): OutgoingResponseInterface;
/**
* Return the view object.
*
* @return \Titon\View\View
*/
public function getView(): ?View;
/**
* Method to be called when an action is missing.
*
* @return mixed
*/
public function missingAction(): mixed;
/**
* Render a view template for an error/exception and return the output.
*
* @param \Exception $exception
* @return string
*/
public function renderError(Exception $exception): string;
/**
* Render a view template and return the output.
*
* @return string
*/
public function renderView(): string;
/**
* Trigger a custom action class that should either return a string or a response object.
*
* @param \Titon\Controller\Action $action
* @return mixed
*/
public function runAction(Action $action): mixed;
/**
* Set the request object.
*
* @param \Psr\Http\Message\IncomingRequestInterface $request
* @return $this
*/
public function setRequest(IncomingRequestInterface $request): this;
/**
* Set the response object.
*
* @param \Psr\Http\Message\OutgoingResponseInterface $response
* @return $this
*/
public function setResponse(OutgoingResponseInterface $response): this;
/**
* Set the view object.
*
* @param \Titon\View\View $view
* @return $this
*/
public function setView(View $view): this;
}