Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c877cf8

Browse filesBrowse files
committed
feature #30408 [HttpKernel] Better exception page when the invokable controller returns nothing (dimabory)
This PR was merged into the 4.3-dev branch. Discussion ---------- [HttpKernel] Better exception page when the invokable controller returns nothing | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27138 | License | MIT | Doc PR | --- __Prerequisites__ _Configure invokable controller_ ```php # config/routes.yaml index: path: / controller: App\Controller\Start ``` __Before:__ ![before](https://user-images.githubusercontent.com/11414342/53577698-ca739000-3b7e-11e9-98ac-8c8e27626fbe.png) __After:__ ![after](https://user-images.githubusercontent.com/11414342/53577733-df502380-3b7e-11e9-8377-a4a97ea73df8.png) --- Take a look for an enhancement/refactoring in `HttpKernel.php` Commits ------- f6c1622 [HttpKernel] Better exception page when the invokable controller returns nothing
2 parents 0034e14 + f6c1622 commit c877cf8
Copy full SHA for c877cf8

File tree

2 files changed

+13
-8
lines changed
Filter options

2 files changed

+13
-8
lines changed

‎src/Symfony/Component/HttpKernel/Exception/ControllerDoesNotReturnResponseException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Exception/ControllerDoesNotReturnResponseException.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ private function parseControllerDefinition(callable $controller): ?array
6767
if (\is_object($controller)) {
6868
$r = new \ReflectionClass($controller);
6969

70+
try {
71+
$line = $r->getMethod('__invoke')->getEndLine();
72+
} catch (\ReflectionException $e) {
73+
$line = $r->getEndLine();
74+
}
75+
7076
return [
7177
'file' => $r->getFileName(),
72-
'line' => $r->getEndLine(),
78+
'line' => $line,
7379
];
7480
}
7581

‎src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,19 @@ public function testHandleWhenTheControllerIsAStaticArray()
215215
public function testHandleWhenTheControllerDoesNotReturnAResponse()
216216
{
217217
$dispatcher = new EventDispatcher();
218-
$kernel = $this->getHttpKernel($dispatcher, function () { return 'foo'; });
218+
$kernel = $this->getHttpKernel($dispatcher, function () {});
219219

220220
try {
221221
$kernel->handle(new Request());
222222

223223
$this->fail('The kernel should throw an exception.');
224224
} catch (ControllerDoesNotReturnResponseException $e) {
225-
}
225+
$first = $e->getTrace()[0];
226226

227-
$first = $e->getTrace()[0];
228-
229-
// `file` index the array starting at 0, and __FILE__ starts at 1
230-
$line = file($first['file'])[$first['line'] - 2];
231-
$this->assertContains('// call controller', $line);
227+
// `file` index the array starting at 0, and __FILE__ starts at 1
228+
$line = file($first['file'])[$first['line'] - 2];
229+
$this->assertContains('// call controller', $line);
230+
}
232231
}
233232

234233
public function testHandleWhenTheControllerDoesNotReturnAResponseButAViewIsRegistered()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.