Skip to content

Commit 4ba77e4

Browse files
jameshalsallfabpot
authored andcommitted
[HttpKernel][2.6] Adding support for invokable controllers in the RequestDataCollector
1 parent c483f74 commit 4ba77e4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

DataCollector/RequestDataCollector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ public function collect(Request $request, Response $response, \Exception $except
147147
'file' => $r->getFilename(),
148148
'line' => $r->getStartLine(),
149149
);
150+
} elseif (is_object($controller)) {
151+
$r = new \ReflectionClass($controller);
152+
$this->data['controller'] = array(
153+
'class' => $r->getName(),
154+
'method' => null,
155+
'file' => $r->getFileName(),
156+
'line' => $r->getStartLine(),
157+
);
150158
} else {
151159
$this->data['controller'] = (string) $controller ?: 'n/a';
152160
}

Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function testControllerInspection()
5959
// make sure we always match the line number
6060
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
6161
$r2 = new \ReflectionMethod($this, 'staticControllerMethod');
62+
$r3 = new \ReflectionClass($this);
6263
// test name, callable, expected
6364
$controllerTests = array(
6465
array(
@@ -132,6 +133,17 @@ function () { return 'foo'; },
132133
'line' => 'n/a',
133134
),
134135
),
136+
137+
array(
138+
'Invokable controller',
139+
$this,
140+
array(
141+
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
142+
'method' => null,
143+
'file' => __FILE__,
144+
'line' => $r3->getStartLine(),
145+
),
146+
),
135147
);
136148

137149
$c = new RequestDataCollector();
@@ -202,4 +214,9 @@ public static function __callStatic($method, $args)
202214
{
203215
throw new \LogicException('Unexpected method call');
204216
}
217+
218+
public function __invoke()
219+
{
220+
throw new \LogicException('Unexpected method call');
221+
}
205222
}

0 commit comments

Comments
 (0)