8000 [VarDumper] Add casters for object-converted resources by alexandre-daubois · Pull Request #59035 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper] Add casters for object-converted resources #59035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE-7.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ Serializer
----------

* Deprecate the `CompiledClassMetadataFactory` and `CompiledClassMetadataCacheWarmer` classes

VarDumper
---------

* Deprecate `ResourceCaster::castCurl()`, `ResourceCaster::castGd()` and `ResourceCaster::castOpensslX509()`
* Mark all casters as `@internal`
7 changes: 7 additions & 0 deletions src/Symfony/Component/VarDumper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

7.3
---

* Add casters for `Dba\Connection`, `SQLite3Result`, `OpenSSLAsymmetricKey` and `OpenSSLCertificateSigningRequest`
* Deprecate `ResourceCaster::castCurl()`, `ResourceCaster::castGd()` and `ResourceCaster::castOpensslX509()`
* Mark all casters as `@internal`

7.2
---

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/AddressInfoCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal since Symfony 7.3
*/
final class AddressInfoCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/AmqpCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @final
*
* @internal since Symfony 7.3
*/
class AmqpCaster
{
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/Caster.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Caster
* Casts objects to arrays and adds the dynamic property prefix.
*
* @param bool $hasDebugInfo Whether the __debugInfo method exists on $obj or not
*
* @internal since Symfony 7.3
*/
public static function castObject(object $obj, string $class, bool $hasDebugInfo = false, ?string $debugClass = null): array
{
Expand Down Expand Up @@ -162,6 +164,9 @@ public static function filter(array $a, int $filter, array $listedProperties = [
return $a;
}

/**
* @internal since Symfony 7.3
*/
public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, bool $isNested): array
{
if (isset($a['__PHP_Incomplete_Class_Name'])) {
Expand Down
31 changes: 31 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/CurlCaster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\VarDumper\Caster;

use Symfony\Component\VarDumper\Cloner\Stub;

/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
final class CurlCaster
{
public static function castCurl(\CurlHandle $h, array $a, Stub $stub, bool $isNested): array
{
foreach (curl_getinfo($h) as $key => $val) {
$a[Caster::PREFIX_VIRTUAL.$key] = $val;
}

return $a;
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/DOMCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class DOMCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/DateCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @author Dany Maillard <danymaillard93b@gmail.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class DateCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/DoctrineCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class DoctrineCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class ExceptionCaster
{
Expand Down
30 changes: 30 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/GdCaster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\VarDumper\Caster;

use Symfony\Component\VarDumper\Cloner\Stub;

/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
final class GdCaster
{
public static function castGd(\GdImage $gd, array $a, Stub $stub, bool $isNested): array
{
$a[Caster::PREFIX_VIRTUAL.'size'] = imagesx($gd).'x'.imagesy($gd);
$a[Caster::PREFIX_VIRTUAL.'trueColor'] = imageistruecolor($gd);

return $a;
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/GmpCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class GmpCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/ImagineCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

/**
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @internal since Symfony 7.3
*/
final class ImagineCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/IntlCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
*
* @final
*
* @internal since Symfony 7.3
*/
class IntlCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/MemcachedCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
*
* @final
*
* @internal since Symfony 7.3
*/
class MemcachedCaster
{
Expand Down
69 changes: 69 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/OpenSSLCaster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\VarDumper\Caster;

use Symfony\Component\VarDumper\Cloner\Stub;

/**
* @author Nicolas Grekas <p@tchwork.com>
* @author Alexandre Daubois <alex.daubois@gmail.com>
*
* @internal
*/
final class OpenSSLCaster
{
public static function castOpensslX509(\OpenSSLCertificate $h, array $a, Stub $stub, bool $isNested): array
{
$stub->cut = -1;
$info = openssl_x509_parse($h, false);

$pin = openssl_pkey_get_public($h);
$pin = openssl_pkey_get_details($pin)['key'];
$pin = \array_slice(explode("\n", $pin), 1, -2);
$pin = base64_decode(implode('', $pin));
$pin = base64_encode(hash('sha256', $pin, true));

$a += [
Caster::PREFIX_VIRTUAL.'subject' => new EnumStub(array_intersect_key($info['subject'], ['organizationName' => true, 'commonName' => true])),
Caster::PREFIX_VIRTUAL.'issuer' => new EnumStub(array_intersect_key($info['issuer'], ['organizationName' => true, 'commonName' => true])),
Caster::PREFIX_VIRTUAL.'expiry' => new ConstStub(date(\DateTimeInterface::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
Caster::PREFIX_VIRTUAL.'fingerprint' => new EnumStub([
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
'pin-sha256' => new ConstStub($pin),
]),
];

return $a;
}

public static function castOpensslAsymmetricKey(\OpenSSLAsymmetricKey $key, array $a, Stub $stub, bool $isNested): array
{
foreach (openssl_pkey_get_details($key) as $k => $v) {
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
}

unset($a[Caster::PREFIX_VIRTUAL.'rsa']); // binary data

return $a;
}

public static function castOpensslCsr(\OpenSSLCertificateSigningRequest $csr, array $a, Stub $stub, bool $isNested): array
{
foreach (openssl_csr_get_subject($csr, false) as $k => $v) {
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
}

return $a;
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/PdoCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class PdoCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/PgSqlCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class PgSqlCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/ProxyManagerCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class ProxyManagerCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/RdKafkaCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* Casts RdKafka related classes to array representation.
*
* @author Romain Neutron <imprec@gmail.com>
*
* @internal since Symfony 7.3
*/
class RdKafkaCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/RedisCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class RedisCaster
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @internal since Symfony 7.3
*/
class ReflectionCaster
{
Expand Down
Loading
0