PHP 8.3.31
Preview: JsonDecoder.php Size: 3.44 KB
/proc/thread-self/root/home/getspomw/royalsquad.us/vendor/nikic/php-parser/lib/PhpParser/JsonDecoder.php

<?php declare(strict_types=1);

namespace PhpParser;

class JsonDecoder {
    /** @var \ReflectionClass<Node>[] Node type to reflection class map */
    private array $reflectionClassCache;

    /** @return mixed */
    public function decode(string $json) {
        $value = json_decode($json, true);
        if (json_last_error()) {
            throw new \RuntimeException('JSON decoding error: ' . json_last_error_msg());
        }

        return $this->decodeRecursive($value);
    }

    /**
     * @param mixed $value
     * @return mixed
     */
    private function decodeRecursive($value) {
        if (\is_array($value)) {
            if (isset($value['nodeType'])) {
                if ($value['nodeType'] === 'Comment' || $value['nodeType'] === 'Comment_Doc') {
                    return $this->decodeComment($value);
                }
                return $this->decodeNode($value);
            }
            return $this->decodeArray($value);
        }
        return $value;
    }

    private function decodeArray(array $array): array {
        $decodedArray = [];
        foreach ($array as $key => $value) {
            $decodedArray[$key] = $this->decodeRecursive($value);
        }
        return $decodedArray;
    }

    private function decodeNode(array $value): Node {
        $nodeType = $value['nodeType'];
        if (!\is_string($nodeType)) {
            throw new \RuntimeException('Node type must be a string');
        }

        $reflectionClass = $this->reflectionClassFromNodeType($nodeType);
        $node = $reflectionClass->newInstanceWithoutConstructor();

        if (isset($value['attributes'])) {
            if (!\is_array($value['attributes'])) {
                throw new \RuntimeException('Attributes must be an array');
            }

            $node->setAttributes($this->decodeArray($value['attributes']));
        }

        foreach ($value as $name => $subNode) {
            if ($name === 'nodeType' || $name === 'attributes') {
                continue;
            }

            $node->$name = $this->decodeRecursive($subNode);
        }

        return $node;
    }

    private function decodeComment(array $value): Comment {
        $className = $value['nodeType'] === 'Comment' ? Comment::class : Comment\Doc::class;
        if (!isset($value['text'])) {
            throw new \RuntimeException('Comment must have text');
        }

        return new $className(
            $value['text'],
            $value['line'] ?? -1, $value['filePos'] ?? -1, $value['tokenPos'] ?? -1,
            $value['endLine'] ?? -1, $value['endFilePos'] ?? -1, $value['endTokenPos'] ?? -1
        );
    }

    /** @return \ReflectionClass<Node> */
    private function reflectionClassFromNodeType(string $nodeType): \ReflectionClass {
        if (!isset($this->reflectionClassCache[$nodeType])) {
            $className = $this->classNameFromNodeType($nodeType);
            $this->reflectionClassCache[$nodeType] = new \ReflectionClass($className);
        }
        return $this->reflectionClassCache[$nodeType];
    }

    /** @return class-string<Node> */
    private function classNameFromNodeType(string $nodeType): string {
        $className = 'PhpParser\\Node\\' . strtr($nodeType, '_', '\\');
        if (class_exists($className)) {
            return $className;
        }

        $className .= '_';
        if (class_exists($className)) {
            return $className;
        }

        throw new \RuntimeException("Unknown node type \"$nodeType\"");
    }
}

Directory Contents

Dirs: 9 × Files: 29

Name Size Perms Modified Actions
Builder DIR
- drwxrwxrwx 2026-04-19 15:02:12
Edit Download
Comment DIR
- drwxrwxrwx 2026-04-19 14:58:42
Edit Download
- drwxrwxrwx 2026-04-19 15:00:31
Edit Download
Internal DIR
- drwxrwxrwx 2025-09-17 06:53:34
Edit Download
Lexer DIR
- drwxrwxrwx 2025-09-17 06:53:34
Edit Download
Node DIR
- drwxrwxrwx 2025-09-17 06:53:35
Edit Download
- drwxrwxrwx 2026-04-19 15:04:48
Edit Download
Parser DIR
- drwxrwxrwx 2026-04-19 15:06:25
Edit Download
- drwxrwxrwx 2026-04-19 15:03:08
Edit Download
202 B lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
10.30 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
9.73 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
6.75 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
2.39 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
112 B lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
9.21 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
4.84 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
300 B lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
6.10 KB lrw-r--r-- 2026-04-26 09:59:47
Edit Download
3.44 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
4.26 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
2.71 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
9.82 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
4.03 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
5.24 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
10.25 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
2.55 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
10.09 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
598 B lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
4.08 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
447 B lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
765 B lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
49.81 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
1.41 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
4.47 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
1.66 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
70.32 KB lrw-rw-rw- 2025-09-17 06:53:34
Edit Download
487 B lrw-rw-rw- 2025-09-17 06:53:34
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).