| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace ImanGhafoori\Terminator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Contracts\Routing\ResponseFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class Responder implements ResponseFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |      * Return a new response from the application. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * @param  string  $content | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public function make($content = '', $status = 200, array $headers = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         respondWith(response()->make($content, $status, $headers)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * Create a new "no content" response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     public function noContent($status = 204, array $headers = []) | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         respondWith(response()->noContent($status, $headers)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * Return a new view response from the application. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @param  string  $view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param  array  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function view($view, $data = [], $status = 200, array $headers = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         respondWith(response()->view($view, $data, $status, $headers)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * Return a new JSON response from the application. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @param  string|array  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @param  int  $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     public function json($data = [], $status = 200, array $headers = [], $options = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         respondWith(response()->json($data, $status, $headers, $options)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * Return a new JSONP response from the application. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @param  string  $callback | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @param  string|array  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @param  int  $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public function jsonp($callback, $data = [], $status = 200, array $headers = [], $options = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         respondWith(response()->jsonp($callback, $data, $status, $headers, $options)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |      * @return \Symfony\Component\HttpFoundation\StreamedResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     public function stream($callback, $status = 200, array $headers = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         respondWith(response()->stream($callback, $status, $headers)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * Return a new streamed response as a file download from the application. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param  \Closure  $callback | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param  string|null  $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @param  string|null  $disposition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @return \Symfony\Component\HttpFoundation\StreamedResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     public function streamDownload($callback, $name = null, array $headers = [], $disposition = 'attachment') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         respondWith(response()->streamDownload($callback, $name, $headers, $disposition)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * Create a new file download response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * @param  \SplFileInfo|string  $file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @param  string|null  $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @param  string|null  $disposition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @return \Symfony\Component\HttpFoundation\BinaryFileResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     public function download($file, $name = null, array $headers = [], $disposition = 'attachment') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         respondWith(response()->download($file, $name, $headers, $disposition)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * Return the raw contents of a binary file. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * @param  \SplFileInfo|string  $file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * @return \Symfony\Component\HttpFoundation\BinaryFileResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     public function file($file, array $headers = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         respondWith(response()->file($file, $headers)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * Create a new redirect response to the given path. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * @param  string  $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * @param  bool|null  $secure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 | 1 |  |     public function redirectTo($path, $status = 302, $headers = [], $secure = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 | 1 |  |         return new Chain([$path, $status, $headers, $secure], 'redirectTo'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * Create a new redirect response to a named route. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * @param  string  $route | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * @param  array  $parameters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 | 2 |  |     public function redirectToRoute($route, $parameters = [], $status = 302, $headers = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 2 |  |         return new Chain([$route, $parameters, $status, $headers], 'redirectToRoute'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |      * Create a new redirect response to a controller action. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * @param  string  $action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      * @param  array  $parameters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     public function redirectToAction($action, $parameters = [], $status = 302, $headers = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         return new Chain([$action, $parameters, $status, $headers], 'redirectToAction'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |      * Create a new redirect response, while putting the current URL in the session. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      * @param  string  $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * @param  bool|null  $secure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     public function redirectGuest($path, $status = 302, $headers = [], $secure = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         return new Chain([$path, $status, $headers, $secure], 'redirectGuest'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      * Create a new redirect response to the previously intended location. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      * @param  string  $default | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      * @param  int  $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      * @param  array  $headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |      * @param  bool|null  $secure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |     public function redirectToIntended($default = '/', $status = 302, $headers = [], $secure = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         return new Chain([$default, $status, $headers, $secure], 'redirectToIntended'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 199 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 200 |  |  |  |