diff --git a/src/Symfony/Component/VarDumper/Caster/AddressInfoCaster.php b/src/Symfony/Component/VarDumper/Caster/AddressInfoCaster.php new file mode 100644 index 0000000000000..4ef58960bba44 --- /dev/null +++ b/src/Symfony/Component/VarDumper/Caster/AddressInfoCaster.php @@ -0,0 +1,80 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\VarDumper\Caster; + +use Symfony\Component\VarDumper\Cloner\Stub; + +/** + * @author Nicolas Grekas
+ */
+final class AddressInfoCaster
+{
+ private const MAPS = [
+ 'ai_flags' => [
+ 1 => 'AI_PASSIVE',
+ 2 => 'AI_CANONNAME',
+ 4 => 'AI_NUMERICHOST',
+ 8 => 'AI_V4MAPPED',
+ 16 => 'AI_ALL',
+ 32 => 'AI_ADDRCONFIG',
+ 64 => 'AI_IDN',
+ 128 => 'AI_CANONIDN',
+ 1024 => 'AI_NUMERICSERV',
+ ],
+ 'ai_family' => [
+ 1 => 'AF_UNIX',
+ 2 => 'AF_INET',
+ 10 => 'AF_INET6',
+ 44 => 'AF_DIVERT',
+ ],
+ 'ai_socktype' => [
+ 1 => 'SOCK_STREAM',
+ 2 => 'SOCK_DGRAM',
+ 3 => 'SOCK_RAW',
+ 4 => 'SOCK_RDM',
+ 5 => 'SOCK_SEQPACKET',
+ ],
+ 'ai_protocol' => [
+ 1 => 'SOL_SOCKET',
+ 6 => 'SOL_TCP',
+ 17 => 'SOL_UDP',
+ 136 => 'SOL_UDPLITE',
+ ],
+ ];
+
+ public static function castAddressInfo(\AddressInfo $h, array $a, Stub $stub, bool $isNested): array
+ {
+ static $resolvedMaps;
+
+ if (!$resolvedMaps) {
+ foreach (self::MAPS as $k => $map) {
+ foreach ($map as $v => $name) {
+ if (\defined($name)) {
+ $resolvedMaps[$k][\constant($name)] = $name;
+ } elseif (!isset($resolvedMaps[$k][$v])) {
+ $resolvedMaps[$k][$v] = $name;
+ }
+ }
+ }
+ }
+
+ foreach (socket_addrinfo_explain($h) as $k => $v) {
+ $a[Caster::PREFIX_VIRTUAL.$k] = match (true) {
+ 'ai_flags' === $k => ConstStub::fromBitfield($v, $resolvedMaps[$k]),
+ isset($resolvedMaps[$k][$v]) => new ConstStub($resolvedMaps[$k][$v], $v),
+ default => $v,
+ };
+ }
+
+ return $a;
+ }
+}
diff --git a/src/Symfony/Component/VarDumper/Caster/ConstStub.php b/src/Symfony/Component/VarDumper/Caster/ConstStub.php
index 587c6c39867a6..adea7860d19a6 100644
--- a/src/Symfony/Component/VarDumper/Caster/ConstStub.php
+++ b/src/Symfony/Component/VarDumper/Caster/ConstStub.php
@@ -30,4 +30,23 @@ public function __toString(): string
{
return (string) $this->value;
}
+
+ /**
+ * @param array Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages. Alternative Proxies:Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.