[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/symfony/var-dumper/Caster/ -> SymfonyCaster.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <[email protected]>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\VarDumper\Caster;
  13  
  14  use Symfony\Component\HttpFoundation\Request;
  15  use Symfony\Component\Uid\Ulid;
  16  use Symfony\Component\Uid\Uuid;
  17  use Symfony\Component\VarDumper\Cloner\Stub;
  18  
  19  /**
  20   * @final
  21   */
  22  class SymfonyCaster
  23  {
  24      private const REQUEST_GETTERS = [
  25          'pathInfo' => 'getPathInfo',
  26          'requestUri' => 'getRequestUri',
  27          'baseUrl' => 'getBaseUrl',
  28          'basePath' => 'getBasePath',
  29          'method' => 'getMethod',
  30          'format' => 'getRequestFormat',
  31      ];
  32  
  33      public static function castRequest(Request $request, array $a, Stub $stub, bool $isNested)
  34      {
  35          $clone = null;
  36  
  37          foreach (self::REQUEST_GETTERS as $prop => $getter) {
  38              $key = Caster::PREFIX_PROTECTED.$prop;
  39              if (\array_key_exists($key, $a) && null === $a[$key]) {
  40                  if (null === $clone) {
  41                      $clone = clone $request;
  42                  }
  43                  $a[Caster::PREFIX_VIRTUAL.$prop] = $clone->{$getter}();
  44              }
  45          }
  46  
  47          return $a;
  48      }
  49  
  50      public static function castHttpClient($client, array $a, Stub $stub, bool $isNested)
  51      {
  52          $multiKey = sprintf("\0%s\0multi", \get_class($client));
  53          if (isset($a[$multiKey])) {
  54              $a[$multiKey] = new CutStub($a[$multiKey]);
  55          }
  56  
  57          return $a;
  58      }
  59  
  60      public static function castHttpClientResponse($response, array $a, Stub $stub, bool $isNested)
  61      {
  62          $stub->cut += \count($a);
  63          $a = [];
  64  
  65          foreach ($response->getInfo() as $k => $v) {
  66              $a[Caster::PREFIX_VIRTUAL.$k] = $v;
  67          }
  68  
  69          return $a;
  70      }
  71  
  72      public static function castUuid(Uuid $uuid, array $a, Stub $stub, bool $isNested)
  73      {
  74          $a[Caster::PREFIX_VIRTUAL.'toBase58'] = $uuid->toBase58();
  75          $a[Caster::PREFIX_VIRTUAL.'toBase32'] = $uuid->toBase32();
  76  
  77          // symfony/uid >= 5.3
  78          if (method_exists($uuid, 'getDateTime')) {
  79              $a[Caster::PREFIX_VIRTUAL.'time'] = $uuid->getDateTime()->format('Y-m-d H:i:s.u \U\T\C');
  80          }
  81  
  82          return $a;
  83      }
  84  
  85      public static function castUlid(Ulid $ulid, array $a, Stub $stub, bool $isNested)
  86      {
  87          $a[Caster::PREFIX_VIRTUAL.'toBase58'] = $ulid->toBase58();
  88          $a[Caster::PREFIX_VIRTUAL.'toRfc4122'] = $ulid->toRfc4122();
  89  
  90          // symfony/uid >= 5.3
  91          if (method_exists($ulid, 'getDateTime')) {
  92              $a[Caster::PREFIX_VIRTUAL.'time'] = $ulid->getDateTime()->format('Y-m-d H:i:s.v \U\T\C');
  93          }
  94  
  95          return $a;
  96      }
  97  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer