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

Skip to content

Commit cb70899

Browse files
committed
feature #14006 [VarDumper] with-er interface for Cloner\Data (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [VarDumper] with-er interface for Cloner\Data | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | symfony/symfony-docs#5106 I should have this idea earlier... :) Commits ------- 2462c5b [VarDumper] with-er interface for Cloner\Data
2 parents a464f37 + 2462c5b commit cb70899

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
168168
$dumps = array();
169169

170170
foreach ($this->data as $dump) {
171-
$dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth));
171+
if (method_exists($dump['data'], 'withMaxDepth')) {
172+
$dumper->dump($dump['data']->withMaxDepth($maxDepthLimit)->withMaxItemsPerDepth($maxItemsPerDepth));
173+
} else {
174+
// getLimitedClone is @deprecated, to be removed in 3.0
175+
$dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth));
176+
}
172177
rewind($data);
173178
$dump['data'] = stream_get_contents($data);
174179
ftruncate($data, 0);

src/Symfony/Component/VarDumper/Cloner/Data.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,51 @@ public function getRawData()
3737
return $this->data;
3838
}
3939

40+
/**
41+
* Returns a depth limited clone of $this.
42+
*
43+
* @param int $maxDepth The max dumped depth level.
44+
*
45+
* @return self A clone of $this.
46+
*/
47+
public function withMaxDepth($maxDepth)
48+
{
49+
$data = clone $this;
50+
$data->maxDepth = (int) $maxDepth;
51+
52+
return $data;
53+
}
54+
55+
/**
56+
* Limits the numbers of elements per depth level.
57+
*
58+
* @param int $maxItemsPerDepth The max number of items dumped per depth level.
59+
*
60+
* @return self A clone of $this.
61+
*/
62+
public function withMaxItemsPerDepth($maxItemsPerDepth)
63+
{
64+
$data = clone $this;
65+
$data->maxItemsPerDepth = (int) $maxItemsPerDepth;
66+
67+
return $data;
68+
}
69+
70+
/**
71+
* Enables/disables objects' identifiers tracking.
72+
*
73+
* @param bool $useRefHandles False to hide global ref. handles.
74+
*
75+
* @return self A clone of $this.
76+
*/
77+
public function withRefHandles($useRefHandles)
78+
{
79+
$data = clone $this;
80+
$data->useRefHandles = $useRefHandles ? -1 : 0;
81+
82+
return $data;
83+
}
84+
4085
/**
4186
* Returns a depth limited clone of $this.
4287
*
@@ -45,9 +90,13 @@ public function getRawData()
4590
* @param bool $useRefHandles False to hide ref. handles.
4691
*
4792
* @return self A depth limited clone of $this.
93+
*
94+
* @deprecated since Symfony 2.7, to be removed in 3.0. Use withMaxDepth, withMaxItemsPerDepth or withRefHandles instead.
4895
*/
4996
public function getLimitedClone($maxDepth, $maxItemsPerDepth, $useRefHandles = true)
5097
{
98+
trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.7 and will be removed in 3.0. Use withMaxDepth, withMaxItemsPerDepth or withRefHandles methods instead.', E_USER_DEPRECATED);
99+
51100
$data = clone $this;
52101
$data->maxDepth = (int) $maxDepth;
53102
$data->maxItemsPerDepth = (int) $maxItemsPerDepth;

src/Symfony/Component/VarDumper/Tests/CliDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function testBuggyRefs()
245245
$dumper->setColors(false);
246246
$cloner = new VarCloner();
247247

248-
$data = $cloner->cloneVar($var)->getLimitedClone(3, -1);
248+
$data = $cloner->cloneVar($var)->withMaxDepth(3);
249249
$out = '';
250250
$dumper->dump($data, function ($line, $depth) use (&$out) {
251251
if ($depth >= 0) {

0 commit comments

Comments
 (0)