SymfonyCaster.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\HttpFoundation\Request;
  12. use Symfony\Component\VarDumper\Cloner\Stub;
  13. class SymfonyCaster
  14. {
  15. private static $requestGetters = [
  16. 'pathInfo' => 'getPathInfo',
  17. 'requestUri' => 'getRequestUri',
  18. 'baseUrl' => 'getBaseUrl',
  19. 'basePath' => 'getBasePath',
  20. 'method' => 'getMethod',
  21. 'format' => 'getRequestFormat',
  22. ];
  23. public static function castRequest(Request $request, array $a, Stub $stub, $isNested)
  24. {
  25. $clone = null;
  26. foreach (self::$requestGetters as $prop => $getter) {
  27. if (null === $a[Caster::PREFIX_PROTECTED.$prop]) {
  28. if (null === $clone) {
  29. $clone = clone $request;
  30. }
  31. $a[Caster::PREFIX_VIRTUAL.$prop] = $clone->{$getter}();
  32. }
  33. }
  34. return $a;
  35. }
  36. public static function castHttpClient($client, array $a, Stub $stub, $isNested)
  37. {
  38. $multiKey = sprintf("\0%s\0multi", \get_class($client));
  39. $a[$multiKey] = new CutStub($a[$multiKey]);
  40. return $a;
  41. }
  42. }