ResourceCaster.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. class ResourceCaster
  18. {
  19. public static function castCurl($h, array $a, Stub $stub, $isNested)
  20. {
  21. return curl_getinfo($h);
  22. }
  23. public static function castDba($dba, array $a, Stub $stub, $isNested)
  24. {
  25. $list = dba_list();
  26. $a['file'] = $list[(int) $dba];
  27. return $a;
  28. }
  29. public static function castProcess($process, array $a, Stub $stub, $isNested)
  30. {
  31. return proc_get_status($process);
  32. }
  33. public static function castStream($stream, array $a, Stub $stub, $isNested)
  34. {
  35. $a = stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested);
  36. if (isset($a['uri'])) {
  37. $a['uri'] = new LinkStub($a['uri']);
  38. }
  39. return $a;
  40. }
  41. public static function castStreamContext($stream, array $a, Stub $stub, $isNested)
  42. {
  43. return @stream_context_get_params($stream) ?: $a;
  44. }
  45. public static function castGd($gd, array $a, Stub $stub, $isNested)
  46. {
  47. $a['size'] = imagesx($gd).'x'.imagesy($gd);
  48. $a['trueColor'] = imageistruecolor($gd);
  49. return $a;
  50. }
  51. public static function castMysqlLink($h, array $a, Stub $stub, $isNested)
  52. {
  53. $a['host'] = mysql_get_host_info($h);
  54. $a['protocol'] = mysql_get_proto_info($h);
  55. $a['server'] = mysql_get_server_info($h);
  56. return $a;
  57. }
  58. }