Skip to content

Navigation Menu

Sign in
Appearance settings

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 904d925

Browse filesBrowse files
feature #59035 [VarDumper] Add casters for object-converted resources (alexandre-daubois)
This PR was squashed before being merged into the 7.3 branch. Discussion ---------- [VarDumper] Add casters for object-converted resources | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | yes | Issues | - | License | MIT This PR makes up for the backlog of resources transformed into objects in the latest versions of PHP. ✅ Support added (or already existing with an update in `AbstractCloner`): - ext-curl - `CurlMultiHandle`: **no information to gather** - ext-openssl - `OpenSSLCertificateSigningRequest` - `OpenSSLAsymmetricKey` - ext-finfo - **No information to gather** - ext-sqlite3 - `Sqlite3Result` - ext-sockets - `Sockets` (to rebase on symfony/symfony#59026) - ext-pgsql - `PgSql\Lob` - `PgSql\Connection` - `PgSql\Result` ⚠️ Remaining classes I couldn't test/find enough info yet (introduced in PHP 8.4): - `Odbc\Connection` - `Odbc\Result` - `Soap\Url` - `Soap\Sdl` Commits ------- 7be64835c4b [VarDumper] Add casters for object-converted resources
2 parents b41d4c4 + f396142 commit 904d925
Copy full SHA for 904d925
Expand file treeCollapse file tree

37 files changed

+690
-41
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add casters for `Dba\Connection`, `SQLite3Result`, `OpenSSLAsymmetricKey` and `OpenSSLCertificateSigningRequest`
8+
* Deprecate `ResourceCaster::castCurl()`, `ResourceCaster::castGd()` and `ResourceCaster::castOpensslX509()`
9+
* Mark all casters as `@internal`
10+
411
7.2
512
---
613

‎Caster/AddressInfoCaster.php

Copy file name to clipboardExpand all lines: Caster/AddressInfoCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* @author Nicolas Grekas <p@tchwork.com>
18+
*
19+
* @internal since Symfony 7.3
1820
*/
1921
final class AddressInfoCaster
2022
{

‎Caster/AmqpCaster.php

Copy file name to clipboardExpand all lines: Caster/AmqpCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2020
*
2121
* @final
22+
*
23+
* @internal since Symfony 7.3
2224
*/
2325
class AmqpCaster
2426
{

‎Caster/Caster.php

Copy file name to clipboardExpand all lines: Caster/Caster.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class Caster
4646
* Casts objects to arrays and adds the dynamic property prefix.
4747
*
4848
* @param bool $hasDebugInfo Whether the __debugInfo method exists on $obj or not
49+
*
50+
* @internal since Symfony 7.3
4951
*/
5052
public static function castObject(object $obj, string $class, bool $hasDebugInfo = false, ?string $debugClass = null): array
5153
{
@@ -162,6 +164,9 @@ public static function filter(array $a, int $filter, array $listedProperties = [
162164
return $a;
163165
}
164166

167+
/**
168+
* @internal since Symfony 7.3
169+
*/
165170
public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, bool $isNested): array
166171
{
167172
if (isset($a['__PHP_Incomplete_Class_Name'])) {

‎Caster/CurlCaster.php

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
* @internal
20+
*/
21+
final class CurlCaster
22+
{
23+
public static function castCurl(\CurlHandle $h, array $a, Stub $stub, bool $isNested): array
24+
{
25+
foreach (curl_getinfo($h) as $key => $val) {
26+
$a[Caster::PREFIX_VIRTUAL.$key] = $val;
27+
}
28+
29+
return $a;
30+
}
31+
}

‎Caster/DOMCaster.php

Copy file name to clipboardExpand all lines: Caster/DOMCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*
2121
* @final
22+
*
23+
* @internal since Symfony 7.3
2224
*/
2325
class DOMCaster
2426
{

‎Caster/DateCaster.php

Copy file name to clipboardExpand all lines: Caster/DateCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @author Dany Maillard <danymaillard93b@gmail.com>
2020
*
2121
* @final
22+
*
23+
* @internal since Symfony 7.3
2224
*/
2325
class DateCaster
2426
{

‎Caster/DoctrineCaster.php

Copy file name to clipboardExpand all lines: Caster/DoctrineCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* @author Nicolas Grekas <p@tchwork.com>
2323
*
2424
* @final
25+
*
26+
* @internal since Symfony 7.3
2527
*/
2628
class DoctrineCaster
2729
{

‎Caster/ExceptionCaster.php

Copy file name to clipboardExpand all lines: Caster/ExceptionCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* @author Nicolas Grekas <p@tchwork.com>
2323
*
2424
* @final
25+
*
26+
* @internal since Symfony 7.3
2527
*/
2628
class ExceptionCaster
2729
{

‎Caster/GdCaster.php

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
* @internal
20+
*/
21+
final class GdCaster
22+
{
23+
public static function castGd(\GdImage $gd, array $a, Stub $stub, bool $isNested): array
24+
{
25+
$a[Caster::PREFIX_VIRTUAL.'size'] = imagesx($gd).'x'.imagesy($gd);
26+
$a[Caster::PREFIX_VIRTUAL.'trueColor'] = imageistruecolor($gd);
27+
28+
return $a;
29+
}
30+
}

‎Caster/GmpCaster.php

Copy file name to clipboardExpand all lines: Caster/GmpCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* @author Nicolas Grekas <p@tchwork.com>
2121
*
2222
* @final
23+
*
24+
* @internal since Symfony 7.3
2325
*/
2426
class GmpCaster
2527
{

‎Caster/ImagineCaster.php

Copy file name to clipboardExpand all lines: Caster/ImagineCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
/**
1818
* @author Grégoire Pineau <lyrixx@lyrixx.info>
19+
*
20+
* @internal since Symfony 7.3
1921
*/
2022
final class ImagineCaster
2123
{

‎Caster/IntlCaster.php

Copy file name to clipboardExpand all lines: Caster/IntlCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
1919
*
2020
* @final
21+
*
22+
* @internal since Symfony 7.3
2123
*/
2224
class IntlCaster
2325
{

‎Caster/MemcachedCaster.php

Copy file name to clipboardExpand all lines: Caster/MemcachedCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
1818
*
1919
* @final
20+
*
21+
* @internal since Symfony 7.3
2022
*/
2123
class MemcachedCaster
2224
{

‎Caster/OpenSSLCaster.php

Copy file name to clipboard
+69Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
* @author Alexandre Daubois <alex.daubois@gmail.com>
19+
*
20+
* @internal
21+
*/
22+
final class OpenSSLCaster
23+
{
24+
public static function castOpensslX509(\OpenSSLCertificate $h, array $a, Stub $stub, bool $isNested): array
25+
{
26+
$stub->cut = -1;
27+
$info = openssl_x509_parse($h, false);
28+
29+
$pin = openssl_pkey_get_public($h);
30+
$pin = openssl_pkey_get_details($pin)['key'];
31+
$pin = \array_slice(explode("\n", $pin), 1, -2);
32+
$pin = base64_decode(implode('', $pin));
33+
$pin = base64_encode(hash('sha256', $pin, true));
34+
35+
$a += [
36+
Caster::PREFIX_VIRTUAL.'subject' => new EnumStub(array_intersect_key($info['subject'], ['organizationName' => true, 'commonName' => true])),
37+
Caster::PREFIX_VIRTUAL.'issuer' => new EnumStub(array_intersect_key($info['issuer'], ['organizationName' => true, 'commonName' => true])),
38+
Caster::PREFIX_VIRTUAL.'expiry' => new ConstStub(date(\DateTimeInterface::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
39+
Caster::PREFIX_VIRTUAL.'fingerprint' => new EnumStub([
40+
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
41+
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),
42+
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
43+
'pin-sha256' => new ConstStub($pin),
44+
]),
45+
];
46+
47+
return $a;
48+
}
49+
50+
public static function castOpensslAsymmetricKey(\OpenSSLAsymmetricKey $key, array $a, Stub $stub, bool $isNested): array
51+
{
52+
foreach (openssl_pkey_get_details($key) as $k => $v) {
53+
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
54+
}
55+
56+
unset($a[Caster::PREFIX_VIRTUAL.'rsa']); // binary data
57+
58+
return $a;
59+
}
60+
61+
public static function castOpensslCsr(\OpenSSLCertificateSigningRequest $csr, array $a, Stub $stub, bool $isNested): array
62+
{
63+
foreach (openssl_csr_get_subject($csr, false) as $k => $v) {
64+
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
65+
}
66+
67+
return $a;
68+
}
69+
}

‎Caster/PdoCaster.php

Copy file name to clipboardExpand all lines: Caster/PdoCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*
2121
* @final
22+
*
23+
* @internal since Symfony 7.3
2224
*/
2325
class PdoCaster
2426
{

‎Caster/PgSqlCaster.php

Copy file name to clipboardExpand all lines: Caster/PgSqlCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*
2121
* @final
22+
*
23+
* @internal since Symfony 7.3
2224
*/
2325
class PgSqlCaster
2426
{

‎Caster/ProxyManagerCaster.php

Copy file name to clipboardExpand all lines: Caster/ProxyManagerCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* @author Nicolas Grekas <p@tchwork.com>
1919
*
2020
* @final
21+
*
22+
* @internal since Symfony 7.3
2123
*/
2224
class ProxyManagerCaster
2325
{

‎Caster/RdKafkaCaster.php

Copy file name to clipboardExpand all lines: Caster/RdKafkaCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* Casts RdKafka related classes to array representation.
2929
*
3030
* @author Romain Neutron <imprec@gmail.com>
31+
*
32+
* @internal since Symfony 7.3
3133
*/
3234
class RdKafkaCaster
3335
{

‎Caster/RedisCaster.php

Copy file name to clipboardExpand all lines: Caster/RedisCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* @author Nicolas Grekas <p@tchwork.com>
2121
*
2222
* @final
23+
*
24+
* @internal since Symfony 7.3
2325
*/
2426
class RedisCaster
2527
{

‎Caster/ReflectionCaster.php

Copy file name to clipboardExpand all lines: Caster/ReflectionCaster.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*
2121
* @final
22+
*
23+
* @internal since Symfony 7.3
2224
*/
2325
class ReflectionCaster
2426
{

‎Caster/ResourceCaster.php

Copy file name to clipboardExpand all lines: Caster/ResourceCaster.php
+29-28Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,31 @@
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*
2121
* @final
22+
*
23+
* @internal since Symfony 7.3
2224
*/
2325
class ResourceCaster
2426
{
27+
/**
28+
* @deprecated since Symfony 7.3
29+
*/
2530
public static function castCurl(\CurlHandle $h, array $a, Stub $stub, bool $isNested): array
2631
{
27-
return curl_getinfo($h);
32+
trigger_deprecation('symfony/var-dumper', '7.3', 'The "%s()" method is deprecated without replacement.', __METHOD__, CurlCaster::class);
33+
34+
return CurlCaster::castCurl($h, $a, $stub, $isNested);
2835
}
2936

30-
public static function castDba($dba, array $a, Stub $stub, bool $isNested): array
37+
/**
38+
* @param resource|\Dba\Connection $dba
39+
*/
40+
public static function castDba(mixed $dba, array $a, Stub $stub, bool $isNested): array
3141
{
42+
if (\PHP_VERSION_ID < 80402 && !\is_resource($dba)) {
43+
// @see https://github.com/php/php-src/issues/16990
44+
return $a;
45+
}
46+
3247
$list = dba_list();
3348
$a['file'] = $list[(int) $dba];
3449

@@ -55,37 +70,23 @@ public static function castStreamContext($stream, array $a, Stub $stub, bool $is
5570
return @stream_context_get_params($stream) ?: $a;
5671
}
5772

58-
public static function castGd($gd, array $a, Stub $stub, bool $isNested): array
73+
/**
74+
* @deprecated since Symfony 7.3
75+
*/
76+
public static function castGd(\GdImage $gd, array $a, Stub $stub, bool $isNested): array
5977
{
60-
$a['size'] = imagesx($gd).'x'.imagesy($gd);
61-
$a['trueColor'] = imageistruecolor($gd);
78+
trigger_deprecation('symfony/var-dumper', '7.3', 'The "%s()" method is deprecated without replacement.', __METHOD__, GdCaster::class);
6279

63-
return $a;
80+
return GdCaster::castGd($gd, $a, $stub, $isNested);
6481
}
6582

66-
public static function castOpensslX509($h, array $a, Stub $stub, bool $isNested): array
83+
/**
84+
* @deprecated since Symfony 7.3
85+
*/
86+
public static function castOpensslX509(\OpenSSLCertificate $h, array $a, Stub $stub, bool $isNested): array
6787
{
68-
$stub->cut = -1;
69-
$info = openssl_x509_parse($h, false);
70-
71-
$pin = openssl_pkey_get_public($h);
72-
$pin = openssl_pkey_get_details($pin)['key'];
73-
$pin = \array_slice(explode("\n", $pin), 1, -2);
74-
$pin = base64_decode(implode('', $pin));
75-
$pin = base64_encode(hash('sha256', $pin, true));
76-
77-
$a += [
78-
'subject' => new EnumStub(array_intersect_key($info['subject'], ['organizationName' => true, 'commonName' => true])),
79-
'issuer' => new EnumStub(array_intersect_key($info['issuer'], ['organizationName' => true, 'commonName' => true])),
80-
'expiry' => new ConstStub(date(\DateTimeInterface::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
81-
'fingerprint' => new EnumStub([
82-
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
83-
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),
84-
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
85-
'pin-sha256' => new ConstStub($pin),
86-
]),
87-
];
88+
trigger_deprecation('symfony/var-dumper', '7.3', 'The "%s()" method is deprecated without replacement.', __METHOD__, OpenSSLCaster::class);
8889

89-
return $a;
90+
return OpenSSLCaster::castOpensslX509($h, $a, $stub, $isNested);
9091
}
9192
}

0 commit comments

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