ResourceCaster.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. return stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested);
  36. }
  37. public static function castStreamContext($stream, array $a, Stub $stub, $isNested)
  38. {
  39. return @stream_context_get_params($stream) ?: $a;
  40. }
  41. public static function castGd($gd, array $a, Stub $stub, $isNested)
  42. {
  43. $a['size'] = imagesx($gd).'x'.imagesy($gd);
  44. $a['trueColor'] = imageistruecolor($gd);
  45. return $a;
  46. }
  47. public static function castMysqlLink($h, array $a, Stub $stub, $isNested)
  48. {
  49. $a['host'] = mysql_get_host_info($h);
  50. $a['protocol'] = mysql_get_proto_info($h);
  51. $a['server'] = mysql_get_server_info($h);
  52. return $a;
  53. }
  54. }