ResourceCaster.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\VarDumper\Caster;
  11. use Symfony\Component\VarDumper\Cloner\Stub;
  12. /**
  13. * Casts common resource types to array representation.
  14. *
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. *
  17. * @final
  18. *
  19. * @internal since Symfony 7.3
  20. */
  21. class ResourceCaster
  22. {
  23. /**
  24. * @deprecated since Symfony 7.3
  25. */
  26. public static function castCurl(\CurlHandle $h, array $a, Stub $stub, bool $isNested): array
  27. {
  28. trigger_deprecation('symfony/var-dumper', '7.3', 'The "%s()" method is deprecated without replacement.', __METHOD__);
  29. return CurlCaster::castCurl($h, $a, $stub, $isNested);
  30. }
  31. /**
  32. * @param resource|\Dba\Connection $dba
  33. */
  34. public static function castDba(mixed $dba, array $a, Stub $stub, bool $isNested): array
  35. {
  36. if (\PHP_VERSION_ID < 80402 && !\is_resource($dba)) {
  37. // @see https://github.com/php/php-src/issues/16990
  38. return $a;
  39. }
  40. $list = dba_list();
  41. $a['file'] = $list[(int) $dba];
  42. return $a;
  43. }
  44. public static function castProcess($process, array $a, Stub $stub, bool $isNested): array
  45. {
  46. return proc_get_status($process);
  47. }
  48. public static function castStream($stream, array $a, Stub $stub, bool $isNested): array
  49. {
  50. $a = stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested);
  51. if ($a['uri'] ?? false) {
  52. $a['uri'] = new LinkStub($a['uri']);
  53. }
  54. return $a;
  55. }
  56. public static function castStreamContext($stream, array $a, Stub $stub, bool $isNested): array
  57. {
  58. return @stream_context_get_params($stream) ?: $a;
  59. }
  60. /**
  61. * @deprecated since Symfony 7.3
  62. */
  63. public static function castGd(\GdImage $gd, array $a, Stub $stub, bool $isNested): array
  64. {
  65. trigger_deprecation('symfony/var-dumper', '7.3', 'The "%s()" method is deprecated without replacement.', __METHOD__);
  66. return GdCaster::castGd($gd, $a, $stub, $isNested);
  67. }
  68. /**
  69. * @deprecated since Symfony 7.3
  70. */
  71. public static function castOpensslX509(\OpenSSLCertificate $h, array $a, Stub $stub, bool $isNested): array
  72. {
  73. trigger_deprecation('symfony/var-dumper', '7.3', 'The "%s()" method is deprecated without replacement.', __METHOD__);
  74. return OpenSSLCaster::castOpensslX509($h, $a, $stub, $isNested);
  75. }
  76. }