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

Skip to content

Commit 1ff8865

Browse files
[VarDumper] Fix SocketCaster
1 parent 036e3a0 commit 1ff8865

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

src/Symfony/Component/VarDumper/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add `CurlCaster`, `OpenSslCaster`, `SqliteCaster`, `SocketCaster` and `DbaCaster`
8+
49
7.2
510
---
611

src/Symfony/Component/VarDumper/Caster/DbaCaster.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class DbaCaster
2020
{
2121
public static function castDbaConnection(\Dba\Connection $dba, array $a, Stub $stub, bool $isNested): array
2222
{
23+
// not yet possible to gather information about the connection object
24+
2325
return $a;
2426
}
2527

src/Symfony/Component/VarDumper/Caster/SocketCaster.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,26 @@ class SocketCaster
2121
public static function castSocket(\Socket $h, array $a, Stub $stub, bool $isNested): array
2222
{
2323
socket_getsockname($h, $addr, $port);
24-
$info = socket_get_status(socket_export_stream($h));
24+
$info = stream_get_meta_data(socket_export_stream($h));
2525

2626
$a += [
2727
Caster::PREFIX_VIRTUAL.'address' => $addr,
2828
Caster::PREFIX_VIRTUAL.'port' => $port,
29-
Caster::PREFIX_VIRTUAL.'info' => new EnumStub([
30-
'timed_out' => new ConstStub($info['timed_out'] ? 'true' : 'false'),
31-
'blocked' => new ConstStub($info['blocked'] ? 'true' : 'false'),
32-
'eof' => new ConstStub($info['eof'] ? 'true' : 'false'),
33-
'unread_bytes' => new ScalarStub($info['unread_bytes']),
34-
'stream_type' => new ConstStub($info['stream_type']),
35-
'wrapper_type' => new ConstStub($info['wrapper_type'] ?? '?'),
36-
'wrapper_data' => new ConstStub($info['wrapper_data'] ?? '?'),
37-
'mode' => new ConstStub($info['mode']),
38-
'seekable' => new ConstStub($info['seekable'] ? 'true' : 'false'),
39-
'uri' => new ConstStub($info['uri']),
40-
]),
29+
Caster::PREFIX_VIRTUAL.'info' => new EnumStub(array_intersect_key(
30+
$info,
31+
[
32+
'timed_out' => new ConstStub($info['timed_out'] ? 'true' : 'false'),
33+
'blocked' => new ConstStub($info['blocked'] ? 'true' : 'false'),
34+
'eof' => new ConstStub($info['eof'] ? 'true' : 'false'),
35+
'unread_bytes' => new ScalarStub($info['unread_bytes']),
36+
'stream_type' => new ConstStub($info['stream_type']),
37+
'wrapper_type' => new ConstStub($info['wrapper_type'] ?? ''),
38+
'wrapper_data' => new ConstStub($info['wrapper_data'] ?? ''),
39+
'mode' => new ConstStub($info['mode']),
40+
'seekable' => new ConstStub($info['seekable'] ? 'true' : 'false'),
41+
'uri' => new ConstStub($info['uri'] ?? ''),
42+
]
43+
)),
4144
];
4245

4346
return $a;

src/Symfony/Component/VarDumper/Tests/Caster/OpenSslCasterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testAsymmetricKey()
2525
{
2626
$key = openssl_pkey_new([
2727
'private_key_bits' => 1024,
28-
'private_key_type' => OPENSSL_KEYTYPE_RSA,
28+
'private_key_type' => \OPENSSL_KEYTYPE_RSA,
2929
]);
3030

3131
$this->assertDumpMatchesFormat(

src/Symfony/Component/VarDumper/Tests/Caster/SocketCasterTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SocketCasterTest extends TestCase
2323

2424
public function testCastSocket()
2525
{
26-
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
26+
$socket = socket_create(\AF_INET, \SOCK_DGRAM, \SOL_UDP);
2727
@socket_connect($socket, '127.0.0.1', 80);
2828

2929
$this->assertDumpMatchesFormat(
@@ -35,14 +35,11 @@ public function testCastSocket()
3535
timed_out: false
3636
blocked: true
3737
eof: false
38+
stream_type: "udp_socket"
39+
mode: "r+"
3840
unread_bytes: 0
39-
stream_type: udp_socket
40-
wrapper_type: ?
41-
wrapper_data: ?
42-
mode: r+
4341
seekable: false
44-
uri: udp://
45-
}
42+
%A}
4643
}
4744
EODUMP, $socket);
4845
}

0 commit comments

Comments
 (0)