1: <?php namespace Illuminate\Support\Facades;
2:
3: use Illuminate\Http\JsonResponse;
4: use Illuminate\Support\Contracts\ArrayableInterface;
5: use Symfony\Component\HttpFoundation\BinaryFileResponse;
6:
7: class Response {
8:
9: 10: 11: 12: 13: 14: 15: 16:
17: public static function make($content = '', $status = 200, array $headers = array())
18: {
19: return new \Illuminate\Http\Response($content, $status, $headers);
20: }
21:
22: 23: 24: 25: 26: 27: 28: 29: 30:
31: public static function view($view, $data = array(), $status = 200, array $headers = array())
32: {
33: $app = Facade::getFacadeApplication();
34:
35: return static::make($app['view']->make($view, $data), $status, $headers);
36: }
37:
38: 39: 40: 41: 42: 43: 44: 45:
46: public static function json($data = array(), $status = 200, array $headers = array())
47: {
48: if ($data instanceof ArrayableInterface)
49: {
50: $data = $data->toArray();
51: }
52:
53: return new JsonResponse($data, $status, $headers);
54: }
55:
56: 57: 58: 59: 60: 61: 62: 63:
64: public static function stream($callback, $status = 200, array $headers = array())
65: {
66: return new \Symfony\Component\HttpFoundation\StreamedResponse($callback, $status, $headers);
67: }
68:
69: 70: 71: 72: 73: 74: 75: 76:
77: public static function download($file, $name = null, array $headers = array())
78: {
79: $response = new BinaryFileResponse($file, 200, $headers, true, 'attachment');
80:
81: if ( ! is_null($name))
82: {
83: return $response->setContentDisposition('attachment', $name);
84: }
85:
86: return $response;
87: }
88:
89: }