SymfonyCaster.php 1.1 KB

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