Skip to content

Commit 3fcc881

Browse files
committed
Merge branch '2.6' into 2.7
* 2.6: [FrameworkBundle] fix routing descriptor for options exit when Twig environment is not set [Routing] fix misleading test for condition [Debug] fix test [Debug] add missing conflict dep rules [TwigBundle] allowed SecurityBundle to use the latest versions of FrameworkBundle [HttpFoundation] Make use of isEmpty() method fix missing comma in YamlDumper [VarDumper] fix very special vars handling [Console] Helper\Table->addRow optimization [Console] Helper\Table->addRow optimization Conflicts: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.md src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.md src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.md
2 parents 1eaac8c + 4b5ce2f commit 3fcc881

File tree

6 files changed

+167
-3
lines changed

6 files changed

+167
-3
lines changed

Cloner/AbstractCloner.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ abstract class AbstractCloner implements ClonerInterface
8282

8383
protected $maxItems = 2500;
8484
protected $maxString = -1;
85+
protected $useExt;
8586

8687
private $casters = array();
8788
private $prevErrorHandler;
@@ -98,6 +99,7 @@ public function __construct(array $casters = null)
9899
$casters = static::$defaultCasters;
99100
}
100101
$this->addCasters($casters);
102+
$this->useExt = extension_loaded('symfony_debug');
101103
}
102104

103105
/**

Cloner/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class Data
1818
{
1919
private $data;
20-
private $maxDepth = -1;
20+
private $maxDepth = 20;
2121
private $maxItemsPerDepth = -1;
2222
private $useRefHandles = -1;
2323

Cloner/VarCloner.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class VarCloner extends AbstractCloner
2424
*/
2525
protected function doClone($var)
2626
{
27-
$useExt = extension_loaded('symfony_debug');
27+
$useExt = $this->useExt;
2828
$i = 0; // Current iteration position in $queue
2929
$len = 1; // Length of $queue
3030
$pos = 0; // Number of cloned items past the first level
@@ -120,7 +120,19 @@ protected function doClone($var)
120120
$stub->type = Stub::TYPE_ARRAY;
121121
$stub->class = Stub::ARRAY_ASSOC;
122122
$stub->value = $zval['array_count'] ?: count($v);
123+
123124
$a = $v;
125+
$a[] = null;
126+
$h = count($v);
127+
array_pop($a);
128+
129+
// Happens with copies of $GLOBALS
130+
if ($h !== $stub->value) {
131+
$a = array();
132+
foreach ($v as $gk => &$gv) {
133+
$a[$gk] =& $gv;
134+
}
135+
}
124136
}
125137
break;
126138

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2004-2015 Fabien Potencier
1+
Copyright (c) 2014-2015 Fabien Potencier
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

Tests/CliDumperTest.php

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,154 @@ public function testGet()
104104
105105
EOTXT
106106
,
107+
$out
108+
);
109+
}
110+
111+
/**
112+
* @runInSeparateProcess
113+
* @preserveGlobalState disabled
114+
*/
115+
public function testSpecialVars56()
116+
{
117+
if (PHP_VERSION_ID < 50600) {
118+
$this->markTestSkipped('PHP 5.6 is required');
119+
}
120+
121+
$var = $this->getSpecialVars();
122+
123+
$dumper = new CliDumper();
124+
$dumper->setColors(false);
125+
$cloner = new VarCloner();
126+
127+
$data = $cloner->cloneVar($var);
128+
$out = fopen('php://memory', 'r+b');
129+
$dumper->dump($data, $out);
130+
rewind($out);
131+
$out = stream_get_contents($out);
132+
133+
$this->assertSame(
134+
<<<EOTXT
135+
array:3 [
136+
0 => array:1 [
137+
0 => &1 array:1 [
138+
0 => &1 array:1 [&1]
139+
]
140+
]
141+
1 => array:1 [
142+
"GLOBALS" => &2 array:1 [
143+
"GLOBALS" => &2 array:1 [&2]
144+
]
145+
]
146+
2 => &2 array:1 [&2]
147+
]
107148
149+
EOTXT
150+
,
108151
$out
109152
);
110153
}
154+
155+
/**
156+
* @runInSeparateProcess
157+
* @preserveGlobalState disabled
158+
*/
159+
public function testGlobalsNoExt()
160+
{
161+
$var = $this->getSpecialVars();
162+
unset($var[0]);
163+
$out = '';
164+
165+
$dumper = new CliDumper(function ($line, $depth) use (&$out) {
166+
if ($depth >= 0) {
167+
$out .= str_repeat(' ', $depth).$line."\n";
168+
}
169+
});
170+
$dumper->setColors(false);
171+
$cloner = new VarCloner();
172+
173+
$refl = new \ReflectionProperty($cloner, 'useExt');
174+
$refl->setAccessible(true);
175+
$refl->setValue($cloner, false);
176+
177+
$data = $cloner->cloneVar($var);
178+
$dumper->dump($data);
179+
180+
$this->assertSame(
181+
<<<EOTXT
182+
array:2 [
183+
1 => array:1 [
184+
"GLOBALS" => &1 array:1 [
185+
"GLOBALS" => &1 array:1 [&1]
186+
]
187+
]
188+
2 => &1 array:1 [&1]
189+
]
190+
191+
EOTXT
192+
,
193+
$out
194+
);
195+
}
196+
197+
/**
198+
* @runInSeparateProcess
199+
* @preserveGlobalState disabled
200+
*/
201+
public function testBuggyRefs()
202+
{
203+
if (PHP_VERSION_ID >= 50600) {
204+
$this->markTestSkipped('PHP 5.6 fixed refs counting');
205+
}
206+
207+
$var = $this->getSpecialVars();
208+
$var = $var[0];
209+
210+
$dumper = new CliDumper();
211+
$dumper->setColors(false);
212+
$cloner = new VarCloner();
213+
214+
$data = $cloner->cloneVar($var)->getLimitedClone(3, -1);
215+
$out = '';
216+
$dumper->dump($data, function ($line, $depth) use (&$out) {
217+
if ($depth >= 0) {
218+
$out .= str_repeat(' ', $depth).$line."\n";
219+
}
220+
});
221+
222+
$this->assertSame(
223+
<<<EOTXT
224+
array:1 [
225+
0 => array:1 [
226+
0 => array:1 [
227+
0 => array:1 [
228+
…1
229+
]
230+
]
231+
]
232+
]
233+
234+
EOTXT
235+
,
236+
$out
237+
);
238+
}
239+
240+
private function getSpecialVars()
241+
{
242+
foreach (array_keys($GLOBALS) as $var) {
243+
if ('GLOBALS' !== $var) {
244+
unset($GLOBALS[$var]);
245+
}
246+
}
247+
248+
$var = function &() {
249+
$var = array();
250+
$var[] =& $var;
251+
252+
return $var;
253+
};
254+
255+
return array($var(), $GLOBALS, &$GLOBALS);
256+
}
111257
}

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
{
1010
"name": "Nicolas Grekas",
1111
"email": "[email protected]"
12+
},
13+
{
14+
"name": "Symfony Community",
15+
"homepage": "http://symfony.com/contributors"
1216
}
1317
],
1418
"require": {

0 commit comments

Comments
 (0)