Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de7b11e

Browse files
committed
merged branch GromNaN/master (PR #7367)
This PR was merged into the master branch. Commits ------- cce3a6b [HttpKernel] Collect data if the controller is a Closure Discussion ---------- [HttpKernel] RequestDataCollector: collect data if the controller is a Closure | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | no | License | MIT | Doc PR | no Use the same format as object methods to describe closures and collect the file and the line where it's been declared. Currently, the `file` and `line` parameters are not shown by the webprofiler, but they could be useful to find a closure.
2 parents b8b8cd2 + cce3a6b commit de7b11e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ public function collect(Request $request, Response $response, \Exception $except
133133
}
134134
}
135135
} elseif ($controller instanceof \Closure) {
136-
$this->data['controller'] = 'Closure';
136+
$r = new \ReflectionFunction($controller);
137+
$this->data['controller'] = array(
138+
'class' => $r->getName(),
139+
'method' => null,
140+
'file' => $r->getFilename(),
141+
'line' => $r->getStartLine(),
142+
);
137143
} else {
138144
$this->data['controller'] = (string) $controller ?: 'n/a';
139145
}

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ public function testControllerInspection(Request $request, Response $response)
8181
array(
8282
'Closure',
8383
function() { return 'foo'; },
84-
'Closure',
84+
array(
85+
'class' => __NAMESPACE__ . '\{closure}',
86+
'method' => null,
87+
'file' => __FILE__,
88+
'line' => __LINE__ - 5,
89+
),
8590
),
8691

8792
array(

0 commit comments

Comments
 (0)