vendor/symfony/http-kernel/Exception/ControllerDoesNotReturnResponseException.php line 17

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Exception;
  11. /**
  12. * @author Grégoire Pineau <lyrixx@lyrixx.info>
  13. */
  14. class ControllerDoesNotReturnResponseException extends \LogicException
  15. {
  16. public function __construct(string $message, callable $controller, string $file, int $line)
  17. {
  18. parent::__construct($message);
  19. if (!$controllerDefinition = $this->parseControllerDefinition($controller)) {
  20. return;
  21. }
  22. $this->file = $controllerDefinition['file'];
  23. $this->line = $controllerDefinition['line'];
  24. $r = new \ReflectionProperty(\Exception::class, 'trace');
  25. $r->setAccessible(true);
  26. $r->setValue($this, array_merge([
  27. [
  28. 'line' => $line,
  29. 'file' => $file,
  30. ],
  31. ], $this->getTrace()));
  32. }
  33. private function parseControllerDefinition(callable $controller): ?array
  34. {
  35. if (\is_string($controller) && str_contains($controller, '::')) {
  36. $controller = explode('::', $controller);
  37. }
  38. if (\is_array($controller)) {
  39. try {
  40. $r = new \ReflectionMethod($controller[0], $controller[1]);
  41. return [
  42. 'file' => $r->getFileName(),
  43. 'line' => $r->getEndLine(),
  44. ];
  45. } catch (\ReflectionException $e) {
  46. return null;
  47. }
  48. }
  49. if ($controller instanceof \Closure) {
  50. $r = new \ReflectionFunction($controller);
  51. return [
  52. 'file' => $r->getFileName(),
  53. 'line' => $r->getEndLine(),
  54. ];
  55. }
  56. if (\is_object($controller)) {
  57. $r = new \ReflectionClass($controller);
  58. try {
  59. $line = $r->getMethod('__invoke')->getEndLine();
  60. } catch (\ReflectionException $e) {
  61. $line = $r->getEndLine();
  62. }
  63. return [
  64. 'file' => $r->getFileName(),
  65. 'line' => $line,
  66. ];
  67. }
  68. return null;
  69. }
  70. }