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 8ec4800

Browse filesBrowse files
[VarDumper] Simplify things
1 parent 1ff8865 commit 8ec4800
Copy full SHA for 8ec4800

13 files changed

+159
-352
lines changed

‎src/Symfony/Component/VarDumper/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/CHANGELOG.md
+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
7.3
55
---
66

7-
* Add `CurlCaster`, `OpenSslCaster`, `SqliteCaster`, `SocketCaster` and `DbaCaster`
7+
* Add casters for `Dba\Connection`, `SQLite3Result`, `OpenSSLAsymmetricKey` and `OpenSSLCertificateSigningRequest`
88

99
7.2
1010
---

‎src/Symfony/Component/VarDumper/Caster/CurlCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/CurlCaster.php
-30
This file was deleted.

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/DbaCaster.php
-35
This file was deleted.

‎src/Symfony/Component/VarDumper/Caster/OpenSslCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/OpenSslCaster.php
-92
This file was deleted.

‎src/Symfony/Component/VarDumper/Caster/ResourceCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ResourceCaster.php
+78
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@
2222
*/
2323
class ResourceCaster
2424
{
25+
public static function castCurl(\CurlHandle $h, array $a, Stub $stub, bool $isNested): array
26+
{
27+
$info = curl_getinfo($h);
28+
foreach ($info as $key => $val) {
29+
$a[Caster::PREFIX_VIRTUAL.$key] = $val;
30+
}
31+
32+
return $a;
33+
}
34+
35+
/**
36+
* @param resource|\Dba\Connection $dba
37+
*/
38+
public static function castDba($dba, array $a, Stub $stub, bool $isNested): array
39+
{
40+
if (\PHP_VERSION_ID < 80402 && !\is_resource($dba)) {
41+
// @see https://github.com/php/php-src/issues/16990
42+
return $a;
43+
}
44+
45+
$list = dba_list();
46+
$a['file'] = $list[(int) $dba];
47+
48+
return $a;
49+
}
50+
2551
public static function castProcess($process, array $a, Stub $stub, bool $isNested): array
2652
{
2753
return proc_get_status($process);
@@ -42,11 +68,63 @@ public static function castStreamContext($stream, array $a, Stub $stub, bool $is
4268
return @stream_context_get_params($stream) ?: $a;
4369
}
4470

71+
/**
72+
* @param \GdImage $gd
73+
*/
4574
public static function castGd($gd, array $a, Stub $stub, bool $isNested): array
4675
{
4776
$a['size'] = imagesx($gd).'x'.imagesy($gd);
4877
$a['trueColor'] = imageistruecolor($gd);
4978

5079
return $a;
5180
}
81+
82+
/**
83+
* @param \OpenSSLCertificate $h
84+
*/
85+
public static function castOpensslX509($h, array $a, Stub $stub, bool $isNested): array
86+
{
87+
$stub->cut = -1;
88+
$info = openssl_x509_parse($h, false);
89+
90+
$pin = openssl_pkey_get_public($h);
91+
$pin = openssl_pkey_get_details($pin)['key'];
92+
$pin = \array_slice(explode("\n", $pin), 1, -2);
93+
$pin = base64_decode(implode('', $pin));
94+
$pin = base64_encode(hash('sha256', $pin, true));
95+
96+
$a += [
97+
'subject' => new EnumStub(array_intersect_key($info['subject'], ['organizationName' => true, 'commonName' => true])),
98+
'issuer' => new EnumStub(array_intersect_key($info['issuer'], ['organizationName' => true, 'commonName' => true])),
99+
'expiry' => new ConstStub(date(\DateTimeInterface::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
100+
'fingerprint' => new EnumStub([
101+
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
102+
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),
103+
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
104+
'pin-sha256' => new ConstStub($pin),
105+
]),
106+
];
107+
108+
return $a;
109+
}
110+
111+
public static function castOpensslAsymmetricKey(\OpenSSLAsymmetricKey $key, array $a, Stub $stub, bool $isNested): array
112+
{
113+
foreach (openssl_pkey_get_details($key) as $k => $v) {
114+
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
115+
}
116+
117+
unset($a[Caster::PREFIX_VIRTUAL.'rsa']); // binary data
118+
119+
return $a;
120+
}
121+
122+
public static function castOpensslCsr(\OpenSSLCertificateSigningRequest $csr, array $a, Stub $stub, bool $isNested): array
123+
{
124+
foreach (openssl_csr_get_subject($csr, false) as $k => $v) {
125+
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
126+
}
127+
128+
return $a;
129+
}
52130
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/SocketCaster.php
+8-22
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,22 @@
1313

1414
use Symfony\Component\VarDumper\Cloner\Stub;
1515

16-
/**
17-
* @author Alexandre Daubois <alex.daubois@gmail.com>
18-
*/
19-
class SocketCaster
16+
final class SocketCaster
2017
{
21-
public static function castSocket(\Socket $h, array $a, Stub $stub, bool $isNested): array
18+
public static function castSocket(\Socket $socket, array $a, Stub $stub, bool $isNested): array
2219
{
23-
socket_getsockname($h, $addr, $port);
24-
$info = stream_get_meta_data(socket_export_stream($h));
20+
socket_getsockname($socket, $addr, $port);
21+
$info = stream_get_meta_data(socket_export_stream($socket));
2522

2623
$a += [
2724
Caster::PREFIX_VIRTUAL.'address' => $addr,
2825
Caster::PREFIX_VIRTUAL.'port' => $port,
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-
)),
4426
];
4527

28+
foreach ($info as $key => $val) {
29+
$a[Caster::PREFIX_VIRTUAL.$key] = $val;
30+
}
31+
4632
return $a;
4733
}
4834
}

‎src/Symfony/Component/VarDumper/Caster/SqliteCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/SqliteCaster.php
+7-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616
/**
1717
* @author Alexandre Daubois <alex.daubois@gmail.com>
1818
*/
19-
class SqliteCaster
19+
final class SqliteCaster
2020
{
21-
public static function castSqlite3Result(\SQLite3Result $c, array $a, Stub $stub, bool $isNested): array
21+
public static function castSqlite3Result(\SQLite3Result $result, array $a, Stub $stub, bool $isNested): array
2222
{
2323
$a += [
24-
Caster::PREFIX_VIRTUAL.'numColumns' => $c->numColumns(),
25-
Caster::PREFIX_VIRTUAL.'result' => $c->fetchArray(\SQLITE3_ASSOC),
24+
Caster::PREFIX_VIRTUAL.'numColumns' => $result->numColumns(),
2625
];
2726

27+
for ($i = 0; $i < $result->numColumns(); ++$i) {
28+
$a[Caster::PREFIX_VIRTUAL.'columnName'][$i] = $result->columnName($i);
29+
}
30+
2831
return $a;
2932
}
3033
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
+7-15
Original file line numberDiff line numberDiff line change
@@ -176,39 +176,31 @@ abstract class AbstractCloner implements ClonerInterface
176176

177177
'mysqli_driver' => ['Symfony\Component\VarDumper\Caster\MysqliCaster', 'castMysqliDriver'],
178178

179-
'CurlHandle' => ['Symfony\Component\VarDumper\Caster\CurlCaster', 'castCurl'],
180-
'CurlMultiHandle' => ['Symfony\Component\VarDumper\Caster\CurlCaster', 'castCurlMulti'],
179+
'CurlHandle' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
181180

182-
'Dba\Connection' => ['Symfony\Component\VarDumper\Caster\DbaCaster', 'castDbaConnection'],
183-
':dba' => ['Symfony\Component\VarDumper\Caster\DbaCaster', 'castDbaResource'],
184-
':dba persistent' => ['Symfony\Component\VarDumper\Caster\DbaCaster', 'castDbaResource'],
181+
'Dba\Connection' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
182+
':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
183+
':dba persistent' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
185184

186185
'GdImage' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'],
187-
':gd' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'],
188186

189187
'SQLite3Result' => ['Symfony\Component\VarDumper\Caster\SqliteCaster', 'castSqlite3Result'],
190188

191189
'PgSql\Lob' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLargeObject'],
192-
':pgsql large object' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLargeObject'],
193190
'PgSql\Connection' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'],
194-
':pgsql link' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'],
195-
':pgsql link persistent' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'],
196191
'PgSql\Result' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'],
197-
':pgsql result' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'],
198192

199193
':process' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'],
200194
':stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'],
201195

202-
'OpenSSLAsymmetricKey' => ['Symfony\Component\VarDumper\Caster\OpenSslCaster', 'castOpensslAsymmetricKey'],
203-
'OpenSSLCertificateSigningRequest' => ['Symfony\Component\VarDumper\Caster\OpenSslCaster', 'castOpensslCsr'],
204-
'OpenSSLCertificate' => ['Symfony\Component\VarDumper\Caster\OpenSslCaster', 'castOpensslX509'],
205-
':OpenSSL X.509' => ['Symfony\Component\VarDumper\Caster\OpenSslCaster', 'castOpensslX509'],
196+
'OpenSSLAsymmetricKey' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslAsymmetricKey'],
197+
'OpenSSLCertificateSigningRequest' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslCsr'],
198+
'OpenSSLCertificate' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'],
206199

207200
':persistent stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'],
208201
':stream-context' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'],
209202

210203
'XmlParser' => ['Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'],
211-
':xml' => ['Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'],
212204

213205
'Socket' => ['Symfony\Component\VarDumper\Caster\SocketCaster', 'castSocket'],
214206

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.