ResourceCaster.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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
  20. */
  21. class ResourceCaster
  22. {
  23. public static function castDba(\Dba\Connection $dba, array $a, Stub $stub, bool $isNested): array
  24. {
  25. if (\PHP_VERSION_ID < 80402) {
  26. // @see https://github.com/php/php-src/issues/16990
  27. return $a;
  28. }
  29. $list = dba_list();
  30. $a['file'] = $list[(int) $dba];
  31. return $a;
  32. }
  33. public static function castProcess($process, array $a, Stub $stub, bool $isNested): array
  34. {
  35. return proc_get_status($process);
  36. }
  37. public static function castStream($stream, array $a, Stub $stub, bool $isNested): array
  38. {
  39. $a = stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested);
  40. if ($a['uri'] ?? false) {
  41. $a['uri'] = new LinkStub($a['uri']);
  42. }
  43. return $a;
  44. }
  45. public static function castStreamContext($stream, array $a, Stub $stub, bool $isNested): array
  46. {
  47. return @stream_context_get_params($stream) ?: $a;
  48. }
  49. }