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

Skip to content

Commit 91a2b39

Browse files
committed
Memoize getPrettyJson
1 parent 9446deb commit 91a2b39

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface
2727
{
2828
protected $controllers;
29+
protected $prettyJson;
2930

3031
public function __construct()
3132
{
@@ -265,11 +266,15 @@ public function getContent()
265266

266267
public function getPrettyJson()
267268
{
269+
if ($this->prettyJson) {
270+
return $this->prettyJson;
271+
}
272+
268273
$decoded = json_decode($this->getContent());
269274
$valid = JSON_ERROR_NONE === json_last_error();
270275
$content = json_encode($decoded, JSON_PRETTY_PRINT);
271276

272-
return array(
277+
return $this->prettyJson = array(
273278
'valid' => $valid,
274279
'content' => $content,
275280
);

0 commit comments

Comments
 (0)