@@ -25,75 +25,66 @@ public function __construct(array $responses)
25
25
/**
26
26
* Push a response to the sequence.
27
27
*
28
- * @param mixed $response
29
- * @return $this
30
- */
31
- public function pushResponse ($ response )
32
- {
33
- $ this ->responses [] = $ response ;
34
-
35
- return $ this ;
36
- }
37
-
38
- /**
39
- * Push an empty response to the sequence.
40
- *
28
+ * @param string|array $body
41
29
* @param int $status
42
30
* @param array $headers
43
31
* @return $this
44
32
*/
45
- public function pushEmptyResponse ( $ status = 200 , $ headers = [])
33
+ public function push ( $ body = '' , int $ status = 200 , array $ headers = [])
46
34
{
35
+ if (is_array ($ body )) {
36
+ return $ this ->pushResponse (
37
+ Factory::response (json_encode ($ body ), $ status , $ headers )
38
+ );
39
+ }
40
+
47
41
return $ this ->pushResponse (
48
- Factory::response ('' , $ status , $ headers )
42
+ Factory::response ($ body , $ status , $ headers )
49
43
);
50
44
}
51
45
52
46
/**
53
- * Push response with a string body to the sequence.
47
+ * Push a response with the given status code to the sequence.
54
48
*
55
- * @param string $string
56
49
* @param int $status
57
50
* @param array $headers
58
51
* @return $this
59
52
*/
60
- public function pushString ( $ string , $ status = 200 , $ headers = [])
53
+ public function pushStatus ( int $ status, array $ headers = [])
61
54
{
62
55
return $ this ->pushResponse (
63
- Factory::response ($ string , $ status , $ headers )
56
+ Factory::response ('' , $ status , $ headers )
64
57
);
65
58
}
66
59
67
60
/**
68
- * Push response with a json body to the sequence.
61
+ * Push response with the contents of a file as the body to the sequence.
69
62
*
70
- * @param array $data
63
+ * @param string $filePath
71
64
* @param int $status
72
65
* @param array $headers
73
66
* @return $this
74
67
*/
75
- public function pushJson ( array $ data , $ status = 200 , $ headers = [])
68
+ public function pushFile ( string $ filePath , int $ status = 200 , array $ headers = [])
76
69
{
70
+ $ string = file_get_contents ($ filePath );
71
+
77
72
return $ this ->pushResponse (
78
- Factory::response (json_encode ( $ data ) , $ status , $ headers )
73
+ Factory::response ($ string , $ status , $ headers )
79
74
);
80
75
}
81
76
82
77
/**
83
- * Push response with the contents of a file as the body to the sequence.
78
+ * Push a response to the sequence.
84
79
*
85
- * @param string $filePath
86
- * @param int $status
87
- * @param array $headers
80
+ * @param mixed $response
88
81
* @return $this
89
82
*/
90
- public function pushFile ( $ filePath , $ status = 200 , $ headers = [] )
83
+ public function pushResponse ( $ response )
91
84
{
92
- $ string = file_get_contents ( $ filePath ) ;
85
+ $ this -> responses [] = $ response ;
93
86
94
- return $ this ->pushResponse (
95
- Factory::response ($ string , $ status , $ headers )
96
- );
87
+ return $ this ;
97
88
}
98
89
99
90
/**
0 commit comments