菜谱项目

ResourceCaster.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. }