1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Imanghafoori\HeyMan; |
4
|
|
|
|
5
|
|
|
class Responder |
6
|
|
|
{ |
7
|
|
|
private $action; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Responder constructor. |
11
|
|
|
* |
12
|
|
|
* @param $action |
13
|
|
|
*/ |
14
|
2 |
|
public function __construct($action) |
15
|
|
|
{ |
16
|
2 |
|
$this->action = $action; |
17
|
2 |
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @return \Imanghafoori\HeyMan\RedirectionMsg |
21
|
|
|
*/ |
22
|
|
|
/* public function redirect(): RedirectionMsg |
23
|
|
|
{ |
24
|
|
|
$this->action->response[] = ['redirectTo', func_get_args()]; |
25
|
|
|
|
26
|
|
|
HeyMan::whenYouVisitUrl('/login') |
27
|
|
|
->youShouldBeGuest() |
28
|
|
|
->otherwise() |
29
|
|
|
->redirectTo('/'); |
30
|
|
|
|
31
|
|
|
return new RedirectionMsg($this); |
32
|
|
|
}*/ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Return a new response from the application. |
36
|
|
|
* |
37
|
|
|
* @param string $content |
38
|
|
|
* @param int $status |
39
|
|
|
* @param array $headers |
40
|
|
|
*/ |
41
|
1 |
|
public function make($content = '', $status = 200, array $headers = []) |
42
|
|
|
{ |
43
|
1 |
|
$this->action->response[] = ['make', func_get_args()]; |
44
|
1 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Return a new view response from the application. |
48
|
|
|
* |
49
|
|
|
* @param string $view |
50
|
|
|
* @param array $data |
51
|
|
|
* @param int $status |
52
|
|
|
* @param array $headers |
53
|
|
|
*/ |
54
|
1 |
|
public function view($view, $data = [], $status = 200, array $headers = []) |
55
|
|
|
{ |
56
|
1 |
|
$this->action->response[] = ['view', func_get_args()]; |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Return a new JSON response from the application. |
61
|
|
|
* |
62
|
|
|
* @param string|array $data |
63
|
|
|
* @param int $status |
64
|
|
|
* @param array $headers |
65
|
|
|
* @param int $options |
66
|
|
|
*/ |
67
|
2 |
|
public function json($data = [], $status = 200, array $headers = [], $options = 0) |
68
|
|
|
{ |
69
|
2 |
|
$this->action->response[] = ['json', func_get_args()]; |
70
|
2 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Return a new JSONP response from the application. |
74
|
|
|
* |
75
|
|
|
* @param string $callback |
76
|
|
|
* @param string|array $data |
77
|
|
|
* @param int $status |
78
|
|
|
* @param array $headers |
79
|
|
|
* @param int $options |
80
|
|
|
*/ |
81
|
1 |
|
public function jsonp($callback, $data = [], $status = 200, array $headers = [], $options = 0) |
82
|
|
|
{ |
83
|
1 |
|
$this->action->response[] = ['jsonp', func_get_args()]; |
84
|
1 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Return a new streamed response from the application. |
88
|
|
|
* |
89
|
|
|
* @param \Closure $callback |
90
|
|
|
* @param int $status |
91
|
|
|
* @param array $headers |
92
|
|
|
*/ |
93
|
1 |
|
public function stream($callback, $status = 200, array $headers = []) |
94
|
|
|
{ |
95
|
1 |
|
$this->action->response[] = ['stream', func_get_args()]; |
96
|
1 |
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Return a new streamed response as a file download from the application. |
100
|
|
|
* |
101
|
|
|
* @param \Closure $callback |
102
|
|
|
* @param string|null $name |
103
|
|
|
* @param array $headers |
104
|
|
|
* @param string|null $disposition |
105
|
|
|
*/ |
106
|
1 |
|
public function streamDownload($callback, $name = null, array $headers = [], $disposition = 'attachment') |
107
|
|
|
{ |
108
|
1 |
|
$this->action->response[] = ['streamDownload', func_get_args()]; |
109
|
1 |
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Create a new file download response. |
113
|
|
|
* |
114
|
|
|
* @param \SplFileInfo|string $file |
115
|
|
|
* @param string|null $name |
116
|
|
|
* @param array $headers |
117
|
|
|
* @param string|null $disposition |
118
|
|
|
*/ |
119
|
1 |
|
public function download($file, $name = null, array $headers = [], $disposition = 'attachment') |
120
|
|
|
{ |
121
|
1 |
|
$this->action->response[] = ['download', func_get_args()]; |
122
|
1 |
|
} |
123
|
|
|
} |
124
|
|
|
|