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

Skip to content

Commit 2d1838a

Browse files
committed
feature #59026 [VarDumper] Add caster for Socket instances (nicolas-grekas)
This PR was merged into the 7.3 branch. Discussion ---------- [VarDumper] Add caster for Socket instances | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT Commits ------- 3232f55 [VarDumper] Add caster for Socket instances
2 parents 73d4904 + 3232f55 commit 2d1838a

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Caster;
13+
14+
use Symfony\Component\VarDumper\Cloner\Stub;
15+
16+
/**
17+
* @author Nicolas Grekas <[email protected]>
18+
*/
19+
final class SocketCaster
20+
{
21+
public static function castSocket(\Socket $h, array $a, Stub $stub, bool $isNested): array
22+
{
23+
if (\PHP_VERSION_ID >= 80300 && socket_atmark($h)) {
24+
$a[Caster::PREFIX_VIRTUAL.'atmark'] = true;
25+
}
26+
27+
if (!$lastError = socket_last_error($h)) {
28+
return $a;
29+
}
30+
31+
static $errors;
32+
33+
if (!$errors) {
34+
$errors = get_defined_constants(true)['sockets'] ?? [];
35+
$errors = array_flip(array_filter($errors, static fn ($k) => str_starts_with($k, 'SOCKET_E'), \ARRAY_FILTER_USE_KEY));
36+
}
37+
38+
$a[Caster::PREFIX_VIRTUAL.'last_error'] = new ConstStub($errors[$lastError], socket_strerror($lastError));
39+
40+
return $a;
41+
}
42+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ abstract class AbstractCloner implements ClonerInterface
2525
'__PHP_Incomplete_Class' => ['Symfony\Component\VarDumper\Caster\Caster', 'castPhpIncompleteClass'],
2626

2727
'AddressInfo' => ['Symfony\Component\VarDumper\Caster\AddressInfoCaster', 'castAddressInfo'],
28+
'Socket' => ['Symfony\Component\VarDumper\Caster\SocketCaster', 'castSocket'],
2829

2930
'Symfony\Component\VarDumper\Caster\CutStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'],
3031
'Symfony\Component\VarDumper\Caster\CutArrayStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castCutArray'],

0 commit comments

Comments
 (0)