PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/Classes/TYPO3/FLOW3/Cli/CommandExceptionHandler.php

https://github.com/christianjul/FLOW3-Composer
PHP | 70 lines | 25 code | 9 blank | 36 comment | 0 complexity | a5ac47ef38e48a6881f2317dcf9346b4 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. namespace TYPO3\FLOW3\Cli;
  3. /* *
  4. * This script belongs to the FLOW3 framework. *
  5. * *
  6. * It is free software; you can redistribute it and/or modify it under *
  7. * the terms of the GNU Lesser General Public License, either version 3 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * The TYPO3 project - inspiring people to share! *
  11. * */
  12. use TYPO3\FLOW3\Annotations as FLOW3;
  13. /**
  14. * An Exception handler exclusively responsible for Exceptions that occur during command controller invocation
  15. *
  16. * @FLOW3\Scope("singleton")
  17. */
  18. class CommandExceptionHandler extends \TYPO3\FLOW3\Error\AbstractExceptionHandler {
  19. /**
  20. * Dummy method to satisfy the parent abstract class
  21. *
  22. * @param \Exception $exception The exception
  23. *
  24. * @return void
  25. */
  26. protected function echoExceptionWeb(\Exception $exception) {
  27. }
  28. /**
  29. * Displays a human readable, partly beautified version of the given exception
  30. * and stops the application, return a non-zero exit code.
  31. *
  32. * @param \Exception $exception
  33. * @return void
  34. */
  35. protected function echoExceptionCli(\Exception $exception) {
  36. self::writeResponseAndExit($exception);
  37. }
  38. /**
  39. * Displays a human readable, partly beautified version of the given exception
  40. * and stops the application, return a non-zero exit code.
  41. *
  42. * @static
  43. * @param \Exception $exception
  44. * @return void
  45. */
  46. public static function writeResponseAndExit(\Exception $exception) {
  47. $response = new Response();
  48. $exceptionMessage = '';
  49. $exceptionReference = "\n<b>More Information</b>\n";
  50. $exceptionReference .= " Exception code #" . $exception->getCode() . "\n";
  51. $exceptionReference .= " File " . $exception->getFile() . ($exception->getLine() ? ' line ' . $exception->getLine() : '') . "\n";
  52. $exceptionReference .= ($exception instanceof \TYPO3\FLOW3\Exception ? " Exception reference #" . $exception->getReferenceCode() . "\n" : '');
  53. foreach (explode(chr(10), wordwrap($exception->getMessage(), 73)) as $messageLine) {
  54. $exceptionMessage .= " $messageLine\n";
  55. }
  56. $response->setContent(sprintf("<b>Uncaught Exception</b>\n%s%s\n", $exceptionMessage, $exceptionReference));
  57. $response->send();
  58. exit(1);
  59. }
  60. }
  61. ?>