AmqpCaster.php
2 years ago
ArgsStub.php
1 year ago
Caster.php
1 year ago
ClassStub.php
1 year ago
ConstStub.php
2 years ago
CutArrayStub.php
2 years ago
CutStub.php
1 year ago
DOMCaster.php
1 year ago
DateCaster.php
2 years ago
DoctrineCaster.php
2 years ago
DsCaster.php
2 years ago
DsPairStub.php
2 years ago
EnumStub.php
1 year ago
ExceptionCaster.php
1 year ago
FiberCaster.php
2 years ago
FrameStub.php
1 year ago
GmpCaster.php
2 years ago
ImagineCaster.php
2 years ago
ImgStub.php
2 years ago
IntlCaster.php
2 years ago
LinkStub.php
1 year ago
MemcachedCaster.php
2 years ago
MysqliCaster.php
2 years ago
PdoCaster.php
2 years ago
PgSqlCaster.php
1 year ago
ProxyManagerCaster.php
2 years ago
RdKafkaCaster.php
1 year ago
RedisCaster.php
2 years ago
ReflectionCaster.php
1 year ago
ResourceCaster.php
1 year ago
SplCaster.php
1 year ago
StubCaster.php
2 years ago
SymfonyCaster.php
2 years ago
TraceStub.php
1 year ago
UuidCaster.php
2 years ago
XmlReaderCaster.php
1 year ago
XmlResourceCaster.php
2 years ago
SymfonyCaster.php
75 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace Matomo\Dependencies\Symfony\Component\VarDumper\Caster; |
| 12 | |
| 13 | use Matomo\Dependencies\Symfony\Component\HttpFoundation\Request; |
| 14 | use Symfony\Component\Uid\Ulid; |
| 15 | use Symfony\Component\Uid\Uuid; |
| 16 | use Matomo\Dependencies\Symfony\Component\VarDumper\Cloner\Stub; |
| 17 | /** |
| 18 | * @final |
| 19 | */ |
| 20 | class SymfonyCaster |
| 21 | { |
| 22 | private const REQUEST_GETTERS = ['pathInfo' => 'getPathInfo', 'requestUri' => 'getRequestUri', 'baseUrl' => 'getBaseUrl', 'basePath' => 'getBasePath', 'method' => 'getMethod', 'format' => 'getRequestFormat']; |
| 23 | public static function castRequest(Request $request, array $a, Stub $stub, bool $isNested) |
| 24 | { |
| 25 | $clone = null; |
| 26 | foreach (self::REQUEST_GETTERS as $prop => $getter) { |
| 27 | $key = Caster::PREFIX_PROTECTED . $prop; |
| 28 | if (\array_key_exists($key, $a) && null === $a[$key]) { |
| 29 | if (null === $clone) { |
| 30 | $clone = clone $request; |
| 31 | } |
| 32 | $a[Caster::PREFIX_VIRTUAL . $prop] = $clone->{$getter}(); |
| 33 | } |
| 34 | } |
| 35 | return $a; |
| 36 | } |
| 37 | public static function castHttpClient($client, array $a, Stub $stub, bool $isNested) |
| 38 | { |
| 39 | $multiKey = sprintf("\x00%s\x00multi", \get_class($client)); |
| 40 | if (isset($a[$multiKey])) { |
| 41 | $a[$multiKey] = new CutStub($a[$multiKey]); |
| 42 | } |
| 43 | return $a; |
| 44 | } |
| 45 | public static function castHttpClientResponse($response, array $a, Stub $stub, bool $isNested) |
| 46 | { |
| 47 | $stub->cut += \count($a); |
| 48 | $a = []; |
| 49 | foreach ($response->getInfo() as $k => $v) { |
| 50 | $a[Caster::PREFIX_VIRTUAL . $k] = $v; |
| 51 | } |
| 52 | return $a; |
| 53 | } |
| 54 | public static function castUuid(Uuid $uuid, array $a, Stub $stub, bool $isNested) |
| 55 | { |
| 56 | $a[Caster::PREFIX_VIRTUAL . 'toBase58'] = $uuid->toBase58(); |
| 57 | $a[Caster::PREFIX_VIRTUAL . 'toBase32'] = $uuid->toBase32(); |
| 58 | // symfony/uid >= 5.3 |
| 59 | if (method_exists($uuid, 'getDateTime')) { |
| 60 | $a[Caster::PREFIX_VIRTUAL . 'time'] = $uuid->getDateTime()->format('Y-m-d H:i:s.u \\U\\T\\C'); |
| 61 | } |
| 62 | return $a; |
| 63 | } |
| 64 | public static function castUlid(Ulid $ulid, array $a, Stub $stub, bool $isNested) |
| 65 | { |
| 66 | $a[Caster::PREFIX_VIRTUAL . 'toBase58'] = $ulid->toBase58(); |
| 67 | $a[Caster::PREFIX_VIRTUAL . 'toRfc4122'] = $ulid->toRfc4122(); |
| 68 | // symfony/uid >= 5.3 |
| 69 | if (method_exists($ulid, 'getDateTime')) { |
| 70 | $a[Caster::PREFIX_VIRTUAL . 'time'] = $ulid->getDateTime()->format('Y-m-d H:i:s.v \\U\\T\\C'); |
| 71 | } |
| 72 | return $a; |
| 73 | } |
| 74 | } |
| 75 |