1 | <?php |
||
24 | trait ControllerTrait |
||
25 | { |
||
26 | /** |
||
27 | * @var ViewHandlerInterface |
||
28 | */ |
||
29 | private $viewhandler; |
||
30 | |||
31 | /** |
||
32 | * Get the ViewHandler. |
||
33 | * |
||
34 | * @param ViewHandlerInterface $viewhandler |
||
35 | */ |
||
36 | public function setViewHandler(ViewHandlerInterface $viewhandler) |
||
40 | |||
41 | /** |
||
42 | * Get the ViewHandler. |
||
43 | * |
||
44 | * @return ViewHandlerInterface |
||
45 | */ |
||
46 | protected function getViewHandler() |
||
47 | { |
||
48 | if (!$this->viewhandler instanceof ViewHandlerInterface) { |
||
49 | throw new \RuntimeException('A "ViewHandlerInterface" instance must be set when usign the FOSRestBundle "ControllerTrait".'); |
||
50 | } |
||
51 | |||
52 | return $this->viewhandler; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Creates a view. |
||
57 | * |
||
58 | * Convenience method to allow for a fluent interface. |
||
59 | * |
||
60 | * @param mixed $data |
||
61 | * @param int $statusCode |
||
62 | * @param array $headers |
||
63 | * |
||
64 | * @return View |
||
65 | */ |
||
66 | 1 | protected function view($data = null, $statusCode = null, array $headers = []) |
|
67 | { |
||
68 | 1 | return View::create($data, $statusCode, $headers); |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * Creates a Redirect view. |
||
73 | * |
||
74 | * Convenience method to allow for a fluent interface. |
||
75 | * |
||
76 | * @param string $url |
||
77 | * @param int $statusCode |
||
78 | * @param array $headers |
||
79 | * |
||
80 | * @return View |
||
81 | */ |
||
82 | protected function redirectView($url, $statusCode = Response::HTTP_FOUND, array $headers = []) |
||
86 | |||
87 | /** |
||
88 | * Creates a Route Redirect View. |
||
89 | * |
||
90 | * Convenience method to allow for a fluent interface. |
||
91 | * |
||
92 | * @param string $route |
||
93 | * @param mixed $parameters |
||
94 | * @param int $statusCode |
||
95 | * @param array $headers |
||
96 | * |
||
97 | * @return View |
||
98 | */ |
||
99 | protected function routeRedirectView($route, array $parameters = [], $statusCode = Response::HTTP_CREATED, array $headers = []) |
||
103 | |||
104 | /** |
||
105 | * Converts view into a response object. |
||
106 | * |
||
107 | * Not necessary to use, if you are using the "ViewResponseListener", which |
||
108 | * does this conversion automatically in kernel event "onKernelView". |
||
109 | * |
||
110 | * @param View $view |
||
111 | * |
||
112 | * @return Response |
||
113 | */ |
||
114 | protected function handleView(View $view) |
||
118 | } |
||
119 |