Skip to content

Commit 3ec9897

Browse files
Merge branch '4.4' into 5.4
* 4.4: [VarDumper] Fix dumping floats on PHP8 Fix dumping enums on PHP 8.2 [Cache] Prevent fatal errors on php 8 when running concurrently with TagAwareAdapter v6.1
2 parents 979cd54 + a458015 commit 3ec9897

File tree

7 files changed

+119
-11
lines changed

7 files changed

+119
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ abstract protected function describeCallable($callable, array $options = []);
155155
*/
156156
protected function formatValue($value): string
157157
{
158+
if ($value instanceof \UnitEnum) {
159+
return ltrim(var_export($value, true), '\\');
160+
}
161+
158162
if (\is_object($value)) {
159163
return sprintf('object(%s)', \get_class($value));
160164
}
@@ -163,7 +167,7 @@ protected function formatValue($value): string
163167
return $value;
164168
}
165169

166-
return preg_replace("/\n\s*/s", '', var_export($value, true));
170+
return preg_replace("/\n\s*/s", '', ltrim(var_export($value, true)), '\\');
167171
}
168172

169173
/**
@@ -174,15 +178,15 @@ protected function formatValue($value): string
174178
protected function formatParameter($value): string
175179
{
176180
if ($value instanceof \UnitEnum) {
177-
return var_export($value, true);
181+
return ltrim(var_export($value, true), '\\');
178182
}
179183

180184
// Recursively search for enum values, so we can replace it
181185
// before json_encode (which will not display anything for \UnitEnum otherwise)
182186
if (\is_array($value)) {
183187
array_walk_recursive($value, static function (&$value) {
184188
if ($value instanceof \UnitEnum) {
185-
$value = var_export($value, true);
189+
$value = ltrim(var_export($value, true), '\\');
186190
}
187191
});
188192
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private function writeData(array $data, array $options)
188188
// before json_encode (which will not display anything for \UnitEnum otherwise)
189189
array_walk_recursive($data, static function (&$value) {
190190
if ($value instanceof \UnitEnum) {
191-
$value = var_export($value, true);
191+
$value = ltrim(var_export($value, true), '\\');
192192
}
193193
});
194194

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
349349
} elseif ($argument instanceof Definition) {
350350
$argumentsInformation[] = 'Inlined Service';
351351
} elseif ($argument instanceof \UnitEnum) {
352-
$argumentsInformation[] = var_export($argument, true);
352+
$argumentsInformation[] = ltrim(var_export($argument, true), '\\');
353353
} elseif ($argument instanceof AbstractArgument) {
354354
$argumentsInformation[] = sprintf('Abstract argument (%s)', $argument->getText());
355355
} else {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom): array
421421
}
422422
} elseif ($argument instanceof \UnitEnum) {
423423
$argumentXML->setAttribute('type', 'constant');
424-
$argumentXML->appendChild(new \DOMText(var_export($argument, true)));
424+
$argumentXML->appendChild(new \DOMText(ltrim(var_export($argument, true), '\\')));
425425
} else {
426426
$argumentXML->appendChild(new \DOMText($argument));
427427
}

src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,109 @@ private function getNonPruneableMock(): AdapterInterface
212212
{
213213
return $this->createMock(AdapterInterface::class);
214214
}
215+
216+
/**
217+
* @doesNotPerformAssertions
218+
*/
219+
public function testToleranceForStringsAsTagVersionsCase1()
220+
{
221+
$pool = $this->createCachePool();
222+
$adapter = new FilesystemAdapter();
223+
224+
$itemKey = 'foo';
225+
$tag = $adapter->getItem('bar'.TagAwareAdapter::TAGS_PREFIX);
226+
$adapter->save($tag->set("\x00abc\xff"));
227+
$item = $pool->getItem($itemKey);
228+
$pool->save($item->tag('bar'));
229+
$pool->hasItem($itemKey);
230+
$pool->getItem($itemKey);
231+
}
232+
233+
/**
234+
* @doesNotPerformAssertions
235+
*/
236+
public function testToleranceForStringsAsTagVersionsCase2()
237+
{
238+
$pool = $this->createCachePool();
239+
$adapter = new FilesystemAdapter();
240+
241+
$itemKey = 'foo';
242+
$tag = $adapter->getItem('bar'.TagAwareAdapter::TAGS_PREFIX);
243+
$adapter->save($tag->set("\x00abc\xff"));
244+
$item = $pool->getItem($itemKey);
245+
$pool->save($item->tag('bar'));
246+
sleep(100);
247+
$pool->getItem($itemKey);
248+
$pool->hasItem($itemKey);
249+
}
250+
251+
/**
252+
* @doesNotPerformAssertions
253+
*/
254+
public function testToleranceForStringsAsTagVersionsCase3()
255+
{
256+
$pool = $this->createCachePool();
257+
$adapter = new FilesystemAdapter();
258+
259+
$itemKey = 'foo';
260+
$adapter->deleteItem('bar'.TagAwareAdapter::TAGS_PREFIX);
261+
$item = $pool->getItem($itemKey);
262+
$pool->save($item->tag('bar'));
263+
$pool->getItem($itemKey);
264+
265+
$tag = $adapter->getItem('bar'.TagAwareAdapter::TAGS_PREFIX);
266+
$adapter->save($tag->set("\x00abc\xff"));
267+
268+
$pool->hasItem($itemKey);
269+
$pool->getItem($itemKey);
270+
sleep(100);
271+
$pool->getItem($itemKey);
272+
$pool->hasItem($itemKey);
273+
}
274+
275+
/**
276+
* @doesNotPerformAssertions
277+
*/
278+
public function testToleranceForStringsAsTagVersionsCase4()
279+
{
280+
$pool = $this->createCachePool();
281+
$adapter = new FilesystemAdapter();
282+
283+
$itemKey = 'foo';
284+
$tag = $adapter->getItem('bar'.TagAwareAdapter::TAGS_PREFIX);
285+
$adapter->save($tag->set('abcABC'));
286+
287+
$item = $pool->getItem($itemKey);
288+
$pool->save($item->tag('bar'));
289+
290+
$tag = $adapter->getItem('bar'.TagAwareAdapter::TAGS_PREFIX);
291+
$adapter->save($tag->set('001122'));
292+
293+
$pool->invalidateTags(['bar']);
294+
$pool->getItem($itemKey);
295+
}
296+
297+
/**
298+
* @doesNotPerformAssertions
299+
*/
300+
public function testToleranceForStringsAsTagVersionsCase5()
301+
{
302+
$pool = $this->createCachePool();
303+
$pool2 = $this->createCachePool();
304+
$adapter = new FilesystemAdapter();
305+
306+
$itemKey1 = 'foo';
307+
$item = $pool->getItem($itemKey1);
308+
$pool->save($item->tag('bar'));
309+
310+
$tag = $adapter->getItem('bar'.TagAwareAdapter::TAGS_PREFIX);
311+
$adapter->save($tag->set('abcABC'));
312+
313+
$itemKey2 = 'baz';
314+
$item = $pool2->getItem($itemKey2);
315+
$pool2->save($item->tag('bar'));
316+
foreach ($pool->getItems([$itemKey1, $itemKey2]) as $item) {
317+
// run generator
318+
}
319+
}
215320
}

src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public function __construct($output = null, string $charset = null, int $flags =
4646
{
4747
$this->flags = $flags;
4848
$this->setCharset($charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8');
49-
$this->decimalPoint = localeconv();
50-
$this->decimalPoint = $this->decimalPoint['decimal_point'];
49+
$this->decimalPoint = \PHP_VERSION_ID >= 80000 ? '.' : localeconv()['decimal_point'];
5150
$this->setOutput($output ?: static::$defaultOutput);
5251
if (!$output && \is_string(static::$defaultOutput)) {
5352
static::$defaultOutput = $this->outputStream;
@@ -120,8 +119,7 @@ public function setIndentPad(string $pad)
120119
*/
121120
public function dump(Data $data, $output = null)
122121
{
123-
$this->decimalPoint = localeconv();
124-
$this->decimalPoint = $this->decimalPoint['decimal_point'];
122+
$this->decimalPoint = \PHP_VERSION_ID >= 80000 ? '.' : localeconv()['decimal_point'];
125123

126124
if ($locale = $this->flags & (self::DUMP_COMMA_SEPARATOR | self::DUMP_TRAILING_COMMA) ? setlocale(\LC_NUMERIC, 0) : null) {
127125
setlocale(\LC_NUMERIC, 'C');

src/Symfony/Component/VarExporter/Internal/Exporter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
193193
public static function export($value, string $indent = '')
194194
{
195195
switch (true) {
196-
case \is_int($value) || \is_float($value) || $value instanceof \UnitEnum: return var_export($value, true);
196+
case \is_int($value) || \is_float($value): return var_export($value, true);
197197
case [] === $value: return '[]';
198198
case false === $value: return 'false';
199199
case true === $value: return 'true';
200200
case null === $value: return 'null';
201201
case '' === $value: return "''";
202+
case $value instanceof \UnitEnum: return ltrim(var_export($value, true), '\\');
202203
}
203204

204205
if ($value instanceof Reference) {

0 commit comments

Comments
 (0)