1919use Symfony \Component \HttpKernel \Log \DebugLoggerInterface ;
2020use Symfony \Component \HttpFoundation \Request ;
2121use Symfony \Component \HttpFoundation \Response ;
22-
2322use FOS \RestBundle \Util \Codes ;
2423use FOS \RestBundle \View \ViewHandler ;
2524use FOS \RestBundle \View \View ;
@@ -42,18 +41,21 @@ protected function createExceptionWrapper(array $parameters)
4241 {
4342 /** @var ExceptionWrapperHandlerInterface $exceptionWrapperHandler */
4443 $ exceptionWrapperHandler = $ this ->container ->get ('fos_rest.view.exception_wrapper_handler ' );
44+
4545 return $ exceptionWrapperHandler ->wrap ($ parameters );
4646 }
4747
4848 /**
4949 * Converts an Exception to a Response.
5050 *
51- * @param Request $request Request
52- * @param HttpFlattenException|DebugFlattenException $exception A HttpFlattenException|DebugFlattenException instance
53- * @param DebugLoggerInterface $logger A DebugLoggerInterface instance
54- * @param string $format The format to use for rendering (html, xml, ...)
51+ * @param Request $request
52+ * @param HttpFlattenException|DebugFlattenException $exception
53+ * @param DebugLoggerInterface $logger
54+ * @param string $format
5555 *
56- * @return Response Response instance
56+ * @return Response
57+ *
58+ * @throws \InvalidArgumentException
5759 */
5860 public function showAction (Request $ request , $ exception , DebugLoggerInterface $ logger = null , $ format = 'html ' )
5961 {
@@ -109,7 +111,7 @@ public function showAction(Request $request, $exception, DebugLoggerInterface $l
109111 }
110112
111113 /**
112- * Get and clean any content that was already outputted
114+ * Gets and cleans any content that was already outputted.
113115 *
114116 * This code comes from Symfony and should be synchronized on a regular basis
115117 * see src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
@@ -134,12 +136,12 @@ protected function getAndCleanOutputBuffering()
134136 }
135137
136138 /**
137- * Extract the exception message
139+ * Extracts the exception message.
138140 *
139- * @param HttpFlattenException|DebugFlattenException $exception A HttpFlattenException|DebugFlattenException instance
141+ * @param HttpFlattenException|DebugFlattenException $exception
140142 * @param array $exceptionMap
141143 *
142- * @return string Message
144+ * @return int|false
143145 */
144146 protected function isSubclassOf ($ exception , $ exceptionMap )
145147 {
@@ -162,9 +164,9 @@ protected function isSubclassOf($exception, $exceptionMap)
162164 }
163165
164166 /**
165- * Extract the exception message
167+ * Extracts the exception message.
166168 *
167- * @param HttpFlattenException|DebugFlattenException $exception A HttpFlattenException|DebugFlattenException instance
169+ * @param HttpFlattenException|DebugFlattenException $exception
168170 *
169171 * @return string Message
170172 */
@@ -183,27 +185,27 @@ protected function getExceptionMessage($exception)
183185 }
184186
185187 /**
186- * Determine the status code to use for the response
188+ * Determines the status code to use for the response.
187189 *
188- * @param HttpFlattenException|DebugFlattenException $exception A HttpFlattenException|DebugFlattenException instance
190+ * @param HttpFlattenException|DebugFlattenException $exception
189191 *
190- * @return integer An HTTP response code
192+ * @return int
191193 */
192194 protected function getStatusCode ($ exception )
193195 {
194196 $ exceptionMap = $ this ->container ->getParameter ('fos_rest.exception.codes ' );
195197 $ isExceptionMappedToStatusCode = $ this ->isSubclassOf ($ exception , $ exceptionMap );
196198
197- return ( $ isExceptionMappedToStatusCode) ? $ isExceptionMappedToStatusCode : $ exception ->getStatusCode ();
199+ return $ isExceptionMappedToStatusCode ? : $ exception ->getStatusCode ();
198200 }
199201
200202 /**
201- * Determine the format to use for the response
203+ * Determines the format to use for the response.
202204 *
203- * @param Request $request Request instance
204- * @param string $format The format to use for rendering (html, xml, ...)
205+ * @param Request $request
206+ * @param string $format
205207 *
206- * @return string Encoding format
208+ * @return string
207209 */
208210 protected function getFormat (Request $ request , $ format )
209211 {
@@ -215,19 +217,19 @@ protected function getFormat(Request $request, $format)
215217 }
216218
217219 /**
218- * Determine the parameters to pass to the view layer.
220+ * Determines the parameters to pass to the view layer.
219221 *
220222 * Overwrite it in a custom ExceptionController class to add additionally parameters
221223 * that should be passed to the view layer.
222224 *
223- * @param ViewHandler $viewHandler The view handler instance
224- * @param string $currentContent The current content in the output buffer
225- * @param integer $code An HTTP response code
226- * @param HttpFlattenException|DebugFlattenException $exception A HttpFlattenException|DebugFlattenException instance
227- * @param DebugLoggerInterface $logger A DebugLoggerInterface instance
228- * @param string $format The format to use for rendering (html, xml, ...)
225+ * @param ViewHandler $viewHandler
226+ * @param string $currentContent
227+ * @param int $ code
228+ * @param HttpFlattenException|DebugFlattenException $exception
229+ * @param DebugLoggerInterface $logger
230+ * @param string $format
229231 *
230- * @return array Template parameters
232+ * @return array
231233 */
232234 protected function getParameters (ViewHandler $ viewHandler , $ currentContent , $ code , $ exception , DebugLoggerInterface $ logger = null , $ format = 'html ' )
233235 {
@@ -248,7 +250,7 @@ protected function getParameters(ViewHandler $viewHandler, $currentContent, $cod
248250 }
249251
250252 /**
251- * Find the template for the given format and status code
253+ * Finds the template for the given format and status code.
252254 *
253255 * Note this method needs to be overridden in case another
254256 * engine than Twig should be supported;
@@ -258,12 +260,12 @@ protected function getParameters(ViewHandler $viewHandler, $currentContent, $cod
258260 *
259261 * @param Request $request
260262 * @param string $format
261- * @param integer $code An HTTP response status code
262- * @param Boolean $debug
263+ * @param int $statusCode
264+ * @param bool $debug
263265 *
264266 * @return TemplateReference
265267 */
266- protected function findTemplate (Request $ request , $ format , $ code , $ debug )
268+ protected function findTemplate (Request $ request , $ format , $ statusCode , $ debug )
267269 {
268270 $ name = $ debug ? 'exception ' : 'error ' ;
269271 if ($ debug && 'html ' == $ format ) {
@@ -272,7 +274,7 @@ protected function findTemplate(Request $request, $format, $code, $debug)
272274
273275 // when not in debug, try to find a template for the specific HTTP status code and format
274276 if (!$ debug ) {
275- $ template = new TemplateReference ('TwigBundle ' , 'Exception ' , $ name .$ code , $ format , 'twig ' );
277+ $ template = new TemplateReference ('TwigBundle ' , 'Exception ' , $ name .$ statusCode , $ format , 'twig ' );
276278 if ($ this ->container ->get ('templating ' )->exists ($ template )) {
277279 return $ template ;
278280 }
0 commit comments