Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3232f55

Browse filesBrowse files
[VarDumper] Add caster for Socket instances
1 parent baf98b9 commit 3232f55
Copy full SHA for 3232f55

File tree

2 files changed

+43
-0
lines changed
Filter options

2 files changed

+43
-0
lines changed
+42Lines 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 <fabien@symfony.com>
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 <p@tchwork.com>
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
+1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.