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