| 148 |
lars |
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 |
|
|
|
12 |
namespace Symfony\Component\VarDumper\Caster;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\VarDumper\Cloner\Stub;
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Casts common resource types to array representation.
|
|
|
18 |
*
|
|
|
19 |
* @author Nicolas Grekas <p@tchwork.com>
|
|
|
20 |
*
|
|
|
21 |
* @final
|
|
|
22 |
*/
|
|
|
23 |
class ResourceCaster
|
|
|
24 |
{
|
|
|
25 |
public static function castCurl(\CurlHandle $h, array $a, Stub $stub, bool $isNested): array
|
|
|
26 |
{
|
|
|
27 |
return curl_getinfo($h);
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
public static function castDba($dba, array $a, Stub $stub, bool $isNested)
|
|
|
31 |
{
|
|
|
32 |
$list = dba_list();
|
|
|
33 |
$a['file'] = $list[(int) $dba];
|
|
|
34 |
|
|
|
35 |
return $a;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public static function castProcess($process, array $a, Stub $stub, bool $isNested)
|
|
|
39 |
{
|
|
|
40 |
return proc_get_status($process);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public static function castStream($stream, array $a, Stub $stub, bool $isNested)
|
|
|
44 |
{
|
|
|
45 |
$a = stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested);
|
|
|
46 |
if ($a['uri'] ?? false) {
|
|
|
47 |
$a['uri'] = new LinkStub($a['uri']);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
return $a;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
public static function castStreamContext($stream, array $a, Stub $stub, bool $isNested)
|
|
|
54 |
{
|
|
|
55 |
return @stream_context_get_params($stream) ?: $a;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public static function castGd($gd, array $a, Stub $stub, bool $isNested)
|
|
|
59 |
{
|
|
|
60 |
$a['size'] = imagesx($gd).'x'.imagesy($gd);
|
|
|
61 |
$a['trueColor'] = imageistruecolor($gd);
|
|
|
62 |
|
|
|
63 |
return $a;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public static function castOpensslX509($h, array $a, Stub $stub, bool $isNested)
|
|
|
67 |
{
|
|
|
68 |
$stub->cut = -1;
|
|
|
69 |
$info = openssl_x509_parse($h, false);
|
|
|
70 |
|
|
|
71 |
$pin = openssl_pkey_get_public($h);
|
|
|
72 |
$pin = openssl_pkey_get_details($pin)['key'];
|
|
|
73 |
$pin = \array_slice(explode("\n", $pin), 1, -2);
|
|
|
74 |
$pin = base64_decode(implode('', $pin));
|
|
|
75 |
$pin = base64_encode(hash('sha256', $pin, true));
|
|
|
76 |
|
|
|
77 |
$a += [
|
|
|
78 |
'subject' => new EnumStub(array_intersect_key($info['subject'], ['organizationName' => true, 'commonName' => true])),
|
|
|
79 |
'issuer' => new EnumStub(array_intersect_key($info['issuer'], ['organizationName' => true, 'commonName' => true])),
|
|
|
80 |
'expiry' => new ConstStub(date(\DateTimeInterface::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
|
|
|
81 |
'fingerprint' => new EnumStub([
|
|
|
82 |
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
|
|
|
83 |
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),
|
|
|
84 |
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
|
|
|
85 |
'pin-sha256' => new ConstStub($pin),
|
|
|
86 |
]),
|
|
|
87 |
];
|
|
|
88 |
|
|
|
89 |
return $a;
|
|
|
90 |
}
|
|
|
91 |
}
|