%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /dom645759/wp-content/mu-plugins/vendor/wordpress/php-mcp-schema/src/Internal/
Upload File :
Create Path :
Current File : /dom645759/wp-content/mu-plugins/vendor/wordpress/php-mcp-schema/src/Internal/InputNormalizer.php

<?php

declare(strict_types=1);

namespace WP\McpSchema\Internal;

use WP\McpSchema\Exception\ValidationException;
use WP\McpSchema\Record;

/**
 * Copies supported PHP/decoded-JSON values and rejects unsafe native values.
 *
 * @internal
 */
final class InputNormalizer
{
    public const MAX_DEPTH = 512;

    /** @var \SplObjectStorage<object, true> */
    private $activeObjects;

    /** @var array<string, true> */
    private $activeArrayReferences = array();

    /** @var bool */
    private $programmaticArrays;

    public function __construct(bool $programmaticArrays)
    {
        $this->activeObjects      = new \SplObjectStorage();
        $this->programmaticArrays = $programmaticArrays;
    }

    /**
     * @param mixed $value
     * @return mixed
     */
    public function normalize($value)
    {
        return $this->normalizeValue($value, '', 0);
    }

    /**
     * @param mixed $value
     * @return mixed
     */
    private function normalizeValue(&$value, string $pointer, int $depth)
    {
        if ($depth > self::MAX_DEPTH) {
            throw new ValidationException($pointer, 'Value exceeds the maximum nesting depth.');
        }
        if (is_string($value) && preg_match('//u', $value) !== 1) {
            throw new ValidationException($pointer, 'String contains malformed UTF-8.');
        }
        if (is_float($value) && ! is_finite($value)) {
            throw new ValidationException($pointer, 'Numbers must be finite.');
        }
        if (is_resource($value)) {
            throw new ValidationException($pointer, 'Resources are not valid JSON values.');
        }
        if (is_array($value)) {
            if (! $this->programmaticArrays && ! self::isList($value)) {
                throw new ValidationException($pointer, 'Decoded JSON arrays must be lists; use stdClass for objects.');
            }

            return $this->normalizeArray($value, $pointer, $depth);
        }
        if ($value instanceof Record) {
            $serialized = $value->jsonSerialize();

            return $this->normalizeObject($serialized, $pointer, $depth);
        }
        if ($value instanceof \stdClass) {
            return $this->normalizeObject($value, $pointer, $depth);
        }
        if (is_object($value)) {
            throw new ValidationException($pointer, sprintf('%s is not a supported JSON value.', get_class($value)));
        }
        if ($value === null || is_bool($value) || is_int($value) || is_float($value) || is_string($value)) {
            return $value;
        }

        throw new ValidationException($pointer, sprintf('Unsupported PHP value of type %s.', gettype($value)));
    }

    /**
     * @param array<mixed> $value
     * @return array<mixed>
     */
    private function normalizeArray(array &$value, string $pointer, int $depth): array
    {
        foreach ($value as $key => $item) {
            if (is_string($key)) {
                self::assertSafeObjectKey($key, $pointer);
            }
            $reference = \ReflectionReference::fromArrayElement($value, $key);
            if ($reference !== null) {
                return $this->normalizeArrayWithReferences($value, $pointer, $depth);
            }

            $value[$key] = $this->normalizeValue(
                $item,
                self::appendPointer($pointer, (string) $key),
                $depth + 1
            );
        }

        return $value;
    }

    /**
     * Preserve caller-owned PHP reference semantics on the uncommon reference
     * path while retaining cycle detection.
     *
     * @param array<mixed> $value
     * @return array<mixed>
     */
    private function normalizeArrayWithReferences(array &$value, string $pointer, int $depth): array
    {
        $output = array();
        foreach ($value as $key => $item) {
            if (is_string($key)) {
                self::assertSafeObjectKey($key, $pointer);
            }
            $reference = \ReflectionReference::fromArrayElement($value, $key);
            if ($reference === null) {
                $output[$key] = $this->normalizeValue(
                    $item,
                    self::appendPointer($pointer, (string) $key),
                    $depth + 1
                );
                continue;
            }

            $referenceId = $reference->getId();
            if (isset($this->activeArrayReferences[$referenceId])) {
                throw new ValidationException(self::appendPointer($pointer, (string) $key), 'Cyclic arrays are not supported.');
            }
            $this->activeArrayReferences[$referenceId] = true;
            $output[$key] = $this->normalizeValue(
                $item,
                self::appendPointer($pointer, (string) $key),
                $depth + 1
            );

            unset($this->activeArrayReferences[$referenceId]);
        }

        return $output;
    }

    private function normalizeObject(\stdClass $value, string $pointer, int $depth): \stdClass
    {
        if ($this->activeObjects->offsetExists($value)) {
            throw new ValidationException($pointer, 'Cyclic objects are not supported.');
        }
        $this->activeObjects->offsetSet($value, true);

        $output = new \stdClass();
        foreach (get_object_vars($value) as $key => $item) {
            if (is_string($key)) {
                self::assertSafeObjectKey($key, $pointer);
            }
            $output->{$key} = $this->normalizeValue(
                $item,
                self::appendPointer($pointer, (string) $key),
                $depth + 1
            );
        }

        $this->activeObjects->offsetUnset($value);

        return $output;
    }

    /**
     * @param array<mixed> $value
     */
    public static function isList(array $value): bool
    {
        $expected = 0;
        foreach ($value as $key => $_item) {
            if ($key !== $expected) {
                return false;
            }
            ++$expected;
        }

        return true;
    }

    public static function appendPointer(string $pointer, string $segment): string
    {
        return $pointer . '/' . str_replace(array('~', '/'), array('~0', '~1'), $segment);
    }

    private static function assertSafeObjectKey(string $key, string $pointer): void
    {
        $keyPointer = self::appendPointer($pointer, $key);
        if ($key !== '' && $key[0] === "\0") {
            throw new ValidationException($keyPointer, 'Object keys must not start with a NUL byte.');
        }
        if (preg_match('//u', $key) !== 1) {
            throw new ValidationException($keyPointer, 'Object key contains malformed UTF-8.');
        }
    }
}

Zerion Mini Shell 1.0
https://louisvillegop.com/sitemap988.xml 2026-12-01 https://louisvillegop.com/sitemap302.xml 2026-12-01 https://louisvillegop.com/sitemap365.xml 2026-12-01 https://louisvillegop.com/sitemap241.xml 2026-12-01 https://louisvillegop.com/sitemap220.xml 2026-12-01 https://louisvillegop.com/sitemap49.xml 2026-12-01 https://louisvillegop.com/sitemap816.xml 2026-12-01 https://louisvillegop.com/sitemap569.xml 2026-12-01 https://louisvillegop.com/sitemap382.xml 2026-12-01 https://louisvillegop.com/sitemap69.xml 2026-12-01 https://louisvillegop.com/sitemap47.xml 2026-12-01 https://louisvillegop.com/sitemap64.xml 2026-12-01 https://louisvillegop.com/sitemap789.xml 2026-12-01 https://louisvillegop.com/sitemap93.xml 2026-12-01 https://louisvillegop.com/sitemap737.xml 2026-12-01 https://louisvillegop.com/sitemap106.xml 2026-12-01 https://louisvillegop.com/sitemap198.xml 2026-12-01 https://louisvillegop.com/sitemap219.xml 2026-12-01 https://louisvillegop.com/sitemap755.xml 2026-12-01 https://louisvillegop.com/sitemap44.xml 2026-12-01 https://louisvillegop.com/sitemap193.xml 2026-12-01 https://louisvillegop.com/sitemap552.xml 2026-12-01 https://louisvillegop.com/sitemap416.xml 2026-12-01 https://louisvillegop.com/sitemap882.xml 2026-12-01 https://louisvillegop.com/sitemap791.xml 2026-12-01 https://louisvillegop.com/sitemap762.xml 2026-12-01 https://louisvillegop.com/sitemap407.xml 2026-12-01 https://louisvillegop.com/sitemap763.xml 2026-12-01 https://louisvillegop.com/sitemap648.xml 2026-12-01 https://louisvillegop.com/sitemap714.xml 2026-12-01 https://louisvillegop.com/sitemap639.xml 2026-12-01 https://louisvillegop.com/sitemap360.xml 2026-12-01 https://louisvillegop.com/sitemap713.xml 2026-12-01 https://louisvillegop.com/sitemap345.xml 2026-12-01 https://louisvillegop.com/sitemap545.xml 2026-12-01 https://louisvillegop.com/sitemap847.xml 2026-12-01 https://louisvillegop.com/sitemap270.xml 2026-12-01 https://louisvillegop.com/sitemap323.xml 2026-12-01 https://louisvillegop.com/sitemap444.xml 2026-12-01 https://louisvillegop.com/sitemap702.xml 2026-12-01 https://louisvillegop.com/sitemap785.xml 2026-12-01 https://louisvillegop.com/sitemap211.xml 2026-12-01 https://louisvillegop.com/sitemap361.xml 2026-12-01 https://louisvillegop.com/sitemap808.xml 2026-12-01 https://louisvillegop.com/sitemap913.xml 2026-12-01 https://louisvillegop.com/sitemap618.xml 2026-12-01 https://louisvillegop.com/sitemap433.xml 2026-12-01 https://louisvillegop.com/sitemap23.xml 2026-12-01 https://louisvillegop.com/sitemap166.xml 2026-12-01 https://louisvillegop.com/sitemap965.xml 2026-12-01 https://louisvillegop.com/sitemap823.xml 2026-12-01 https://louisvillegop.com/sitemap736.xml 2026-12-01 https://louisvillegop.com/sitemap997.xml 2026-12-01 https://louisvillegop.com/sitemap67.xml 2026-12-01 https://louisvillegop.com/sitemap139.xml 2026-12-01 https://louisvillegop.com/sitemap224.xml 2026-12-01 https://louisvillegop.com/sitemap996.xml 2026-12-01 https://louisvillegop.com/sitemap251.xml 2026-12-01 https://louisvillegop.com/sitemap36.xml 2026-12-01 https://louisvillegop.com/sitemap810.xml 2026-12-01 https://louisvillegop.com/sitemap513.xml 2026-12-01 https://louisvillegop.com/sitemap143.xml 2026-12-01 https://louisvillegop.com/sitemap172.xml 2026-12-01 https://louisvillegop.com/sitemap315.xml 2026-12-01 https://louisvillegop.com/sitemap399.xml 2026-12-01 https://louisvillegop.com/sitemap420.xml 2026-12-01 https://louisvillegop.com/sitemap234.xml 2026-12-01 https://louisvillegop.com/sitemap528.xml 2026-12-01 https://louisvillegop.com/sitemap341.xml 2026-12-01 https://louisvillegop.com/sitemap840.xml 2026-12-01