the middle of the idiots
This commit is contained in:
		
							
								
								
									
										22
									
								
								qwen/php/vendor/slim/psr7/LICENSE.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								qwen/php/vendor/slim/psr7/LICENSE.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
The MIT License (MIT)
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2015 Slim Framework
 | 
			
		||||
 | 
			
		||||
Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
in the Software without restriction, including without limitation the rights
 | 
			
		||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
furnished to do so, subject to the following conditions:
 | 
			
		||||
 | 
			
		||||
The above copyright notice and this permission notice shall be included in all
 | 
			
		||||
copies or substantial portions of the Software.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | 
			
		||||
SOFTWARE.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										76
									
								
								qwen/php/vendor/slim/psr7/composer.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								qwen/php/vendor/slim/psr7/composer.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,76 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "slim/psr7",
 | 
			
		||||
  "type": "library",
 | 
			
		||||
  "description": "Strict PSR-7 implementation",
 | 
			
		||||
  "keywords": ["psr7","psr-7","http"],
 | 
			
		||||
  "homepage": "https://www.slimframework.com",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "authors": [
 | 
			
		||||
    {
 | 
			
		||||
      "name": "Josh Lockhart",
 | 
			
		||||
      "email": "hello@joshlockhart.com",
 | 
			
		||||
      "homepage": "https://joshlockhart.com"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "name": "Andrew Smith",
 | 
			
		||||
      "email": "a.smith@silentworks.co.uk",
 | 
			
		||||
      "homepage": "https://silentworks.co.uk"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "name": "Rob Allen",
 | 
			
		||||
      "email": "rob@akrabat.com",
 | 
			
		||||
      "homepage": "https://akrabat.com"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "name": "Pierre Berube",
 | 
			
		||||
      "email": "pierre@lgse.com",
 | 
			
		||||
      "homepage": "https://www.lgse.com"
 | 
			
		||||
    }
 | 
			
		||||
  ],
 | 
			
		||||
  "require": {
 | 
			
		||||
    "php": "^8.0",
 | 
			
		||||
    "fig/http-message-util": "^1.1.5",
 | 
			
		||||
    "psr/http-factory": "^1.1",
 | 
			
		||||
    "psr/http-message": "^1.0 || ^2.0",
 | 
			
		||||
    "ralouphie/getallheaders": "^3.0",
 | 
			
		||||
    "symfony/polyfill-php80": "^1.29"
 | 
			
		||||
  },
 | 
			
		||||
  "require-dev": {
 | 
			
		||||
    "ext-json": "*",
 | 
			
		||||
    "adriansuter/php-autoload-override": "^1.4",
 | 
			
		||||
    "http-interop/http-factory-tests": "^1.0 || ^2.0",
 | 
			
		||||
    "php-http/psr7-integration-tests": "^1.4",
 | 
			
		||||
    "phpspec/prophecy": "^1.19",
 | 
			
		||||
    "phpspec/prophecy-phpunit": "^2.2",
 | 
			
		||||
    "phpstan/phpstan": "^2.1",
 | 
			
		||||
    "phpunit/phpunit": "^9.6 || ^10",
 | 
			
		||||
    "squizlabs/php_codesniffer": "^3.10"
 | 
			
		||||
  },
 | 
			
		||||
  "provide": {
 | 
			
		||||
    "psr/http-message-implementation": "^1.0 || ^2.0",
 | 
			
		||||
    "psr/http-factory-implementation": "^1.0"
 | 
			
		||||
  },
 | 
			
		||||
  "autoload": {
 | 
			
		||||
    "psr-4": {
 | 
			
		||||
      "Slim\\Psr7\\": "src"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "autoload-dev": {
 | 
			
		||||
    "psr-4": {
 | 
			
		||||
      "Slim\\Tests\\Psr7\\": "tests"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "test": [
 | 
			
		||||
      "@phpunit",
 | 
			
		||||
      "@phpcs",
 | 
			
		||||
      "@phpstan"
 | 
			
		||||
    ],
 | 
			
		||||
    "phpunit": "@php phpunit",
 | 
			
		||||
    "phpcs": "@php phpcs",
 | 
			
		||||
    "phpstan": "@php phpstan --memory-limit=-1"
 | 
			
		||||
  },
 | 
			
		||||
  "config": {
 | 
			
		||||
    "sort-packages": true
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								qwen/php/vendor/slim/psr7/phpunit.xml.dist
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								qwen/php/vendor/slim/psr7/phpunit.xml.dist
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
 | 
			
		||||
         backupGlobals="true"
 | 
			
		||||
         beStrictAboutOutputDuringTests="true"
 | 
			
		||||
         colors="true"
 | 
			
		||||
         bootstrap="tests/bootstrap.php"
 | 
			
		||||
>
 | 
			
		||||
    <testsuites>
 | 
			
		||||
        <testsuite name="Slim-Psr7 Test Suite">
 | 
			
		||||
            <directory>tests</directory>
 | 
			
		||||
        </testsuite>
 | 
			
		||||
    </testsuites>
 | 
			
		||||
 | 
			
		||||
    <coverage processUncoveredFiles="true">
 | 
			
		||||
        <include>
 | 
			
		||||
            <directory suffix=".php">src</directory>
 | 
			
		||||
        </include>
 | 
			
		||||
        <report>
 | 
			
		||||
            <html outputDirectory="coverage" lowUpperBound="20" highLowerBound="50"/>
 | 
			
		||||
        </report>
 | 
			
		||||
    </coverage>
 | 
			
		||||
</phpunit>
 | 
			
		||||
							
								
								
									
										218
									
								
								qwen/php/vendor/slim/psr7/src/Cookies.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										218
									
								
								qwen/php/vendor/slim/psr7/src/Cookies.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,218 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
 | 
			
		||||
use function array_key_exists;
 | 
			
		||||
use function array_replace;
 | 
			
		||||
use function count;
 | 
			
		||||
use function explode;
 | 
			
		||||
use function gmdate;
 | 
			
		||||
use function in_array;
 | 
			
		||||
use function is_array;
 | 
			
		||||
use function is_string;
 | 
			
		||||
use function preg_split;
 | 
			
		||||
use function rtrim;
 | 
			
		||||
use function strtolower;
 | 
			
		||||
use function strtotime;
 | 
			
		||||
use function urldecode;
 | 
			
		||||
use function urlencode;
 | 
			
		||||
 | 
			
		||||
class Cookies
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Cookies from HTTP request
 | 
			
		||||
     */
 | 
			
		||||
    protected array $requestCookies = [];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Cookies for HTTP response
 | 
			
		||||
     */
 | 
			
		||||
    protected array $responseCookies = [];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Default cookie properties
 | 
			
		||||
     */
 | 
			
		||||
    protected array $defaults = [
 | 
			
		||||
        'value' => '',
 | 
			
		||||
        'domain' => null,
 | 
			
		||||
        'hostonly' => null,
 | 
			
		||||
        'path' => null,
 | 
			
		||||
        'expires' => null,
 | 
			
		||||
        'secure' => false,
 | 
			
		||||
        'httponly' => false,
 | 
			
		||||
        'samesite' => null
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array $cookies
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(array $cookies = [])
 | 
			
		||||
    {
 | 
			
		||||
        $this->requestCookies = $cookies;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set default cookie properties
 | 
			
		||||
     *
 | 
			
		||||
     * @param array $settings
 | 
			
		||||
     *
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function setDefaults(array $settings): self
 | 
			
		||||
    {
 | 
			
		||||
        $this->defaults = array_replace($this->defaults, $settings);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get cookie
 | 
			
		||||
     *
 | 
			
		||||
     * @param string            $name
 | 
			
		||||
     * @param string|array|null $default
 | 
			
		||||
     * @return mixed|null
 | 
			
		||||
     */
 | 
			
		||||
    public function get(string $name, $default = null)
 | 
			
		||||
    {
 | 
			
		||||
        return array_key_exists($name, $this->requestCookies) ? $this->requestCookies[$name] : $default;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set cookie
 | 
			
		||||
     *
 | 
			
		||||
     * @param string       $name
 | 
			
		||||
     * @param string|array $value
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function set(string $name, $value): self
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_array($value)) {
 | 
			
		||||
            $value = ['value' => $value];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->responseCookies[$name] = array_replace($this->defaults, $value);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Convert all response cookies into an associate array of header values
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function toHeaders(): array
 | 
			
		||||
    {
 | 
			
		||||
        $headers = [];
 | 
			
		||||
 | 
			
		||||
        foreach ($this->responseCookies as $name => $properties) {
 | 
			
		||||
            $headers[] = $this->toHeader($name, $properties);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $headers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Convert to `Set-Cookie` header
 | 
			
		||||
     *
 | 
			
		||||
     * @param  string $name       Cookie name
 | 
			
		||||
     * @param  array  $properties Cookie properties
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    protected function toHeader(string $name, array $properties): string
 | 
			
		||||
    {
 | 
			
		||||
        $result = urlencode($name) . '=' . urlencode($properties['value']);
 | 
			
		||||
 | 
			
		||||
        if (isset($properties['domain'])) {
 | 
			
		||||
            $result .= '; domain=' . $properties['domain'];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (isset($properties['path'])) {
 | 
			
		||||
            $result .= '; path=' . $properties['path'];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (isset($properties['expires'])) {
 | 
			
		||||
            if (is_string($properties['expires'])) {
 | 
			
		||||
                $timestamp = strtotime($properties['expires']);
 | 
			
		||||
            } else {
 | 
			
		||||
                $timestamp = (int) $properties['expires'];
 | 
			
		||||
            }
 | 
			
		||||
            if ($timestamp && $timestamp !== 0) {
 | 
			
		||||
                $result .= '; expires=' . gmdate('D, d-M-Y H:i:s e', $timestamp);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (isset($properties['secure']) && $properties['secure']) {
 | 
			
		||||
            $result .= '; secure';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (isset($properties['hostonly']) && $properties['hostonly']) {
 | 
			
		||||
            $result .= '; HostOnly';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (isset($properties['httponly']) && $properties['httponly']) {
 | 
			
		||||
            $result .= '; HttpOnly';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (
 | 
			
		||||
            isset($properties['samesite'])
 | 
			
		||||
            && in_array(strtolower($properties['samesite']), ['lax', 'strict', 'none'], true)
 | 
			
		||||
        ) {
 | 
			
		||||
            // While strtolower is needed for correct comparison, the RFC doesn't care about case
 | 
			
		||||
            $result .= '; SameSite=' . $properties['samesite'];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Parse cookie values from header value
 | 
			
		||||
     *
 | 
			
		||||
     * Returns an associative array of cookie names and values
 | 
			
		||||
     *
 | 
			
		||||
     * @param string|array $header
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public static function parseHeader($header): array
 | 
			
		||||
    {
 | 
			
		||||
        if (is_array($header)) {
 | 
			
		||||
            $header = $header[0] ?? '';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!is_string($header)) {
 | 
			
		||||
            throw new InvalidArgumentException('Cannot parse Cookie data. Header value must be a string.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $header = rtrim($header, "\r\n");
 | 
			
		||||
        $pieces = preg_split('@[;]\s*@', $header);
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
 | 
			
		||||
        if (is_array($pieces)) {
 | 
			
		||||
            foreach ($pieces as $cookie) {
 | 
			
		||||
                $cookie = explode('=', $cookie, 2);
 | 
			
		||||
 | 
			
		||||
                if (count($cookie) === 2) {
 | 
			
		||||
                    $key = urldecode($cookie[0]);
 | 
			
		||||
                    $value = urldecode($cookie[1]);
 | 
			
		||||
 | 
			
		||||
                    if (!isset($cookies[$key])) {
 | 
			
		||||
                        $cookies[$key] = $value;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $cookies;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										55
									
								
								qwen/php/vendor/slim/psr7/src/Environment.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								qwen/php/vendor/slim/psr7/src/Environment.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use function array_merge;
 | 
			
		||||
use function microtime;
 | 
			
		||||
use function time;
 | 
			
		||||
 | 
			
		||||
class Environment
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @param  array $data Array of custom environment keys and values
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public static function mock(array $data = []): array
 | 
			
		||||
    {
 | 
			
		||||
        if (
 | 
			
		||||
            (isset($data['HTTPS']) && $data['HTTPS'] !== 'off')
 | 
			
		||||
            || ((isset($data['REQUEST_SCHEME']) && $data['REQUEST_SCHEME'] === 'https'))
 | 
			
		||||
        ) {
 | 
			
		||||
            $scheme = 'https';
 | 
			
		||||
            $port = 443;
 | 
			
		||||
        } else {
 | 
			
		||||
            $scheme = 'http';
 | 
			
		||||
            $port = 80;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return array_merge([
 | 
			
		||||
            'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
 | 
			
		||||
            'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
 | 
			
		||||
            'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8',
 | 
			
		||||
            'HTTP_USER_AGENT' => 'Slim Framework',
 | 
			
		||||
            'QUERY_STRING' => '',
 | 
			
		||||
            'REMOTE_ADDR' => '127.0.0.1',
 | 
			
		||||
            'REQUEST_METHOD' => 'GET',
 | 
			
		||||
            'REQUEST_SCHEME' => $scheme,
 | 
			
		||||
            'REQUEST_TIME' => time(),
 | 
			
		||||
            'REQUEST_TIME_FLOAT' => microtime(true),
 | 
			
		||||
            'REQUEST_URI' => '',
 | 
			
		||||
            'SCRIPT_NAME' => '',
 | 
			
		||||
            'SERVER_NAME' => 'localhost',
 | 
			
		||||
            'SERVER_PORT' => $port,
 | 
			
		||||
            'SERVER_PROTOCOL' => 'HTTP/1.1',
 | 
			
		||||
        ], $data);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										59
									
								
								qwen/php/vendor/slim/psr7/src/Factory/RequestFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								qwen/php/vendor/slim/psr7/src/Factory/RequestFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\RequestFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\RequestInterface;
 | 
			
		||||
use Psr\Http\Message\StreamFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\UriFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Request;
 | 
			
		||||
 | 
			
		||||
use function is_string;
 | 
			
		||||
 | 
			
		||||
class RequestFactory implements RequestFactoryInterface
 | 
			
		||||
{
 | 
			
		||||
    protected StreamFactoryInterface $streamFactory;
 | 
			
		||||
 | 
			
		||||
    protected UriFactoryInterface $uriFactory;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param StreamFactoryInterface|null $streamFactory
 | 
			
		||||
     * @param UriFactoryInterface|null    $uriFactory
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(?StreamFactoryInterface $streamFactory = null, ?UriFactoryInterface $uriFactory = null)
 | 
			
		||||
    {
 | 
			
		||||
        $this->streamFactory = $streamFactory ?? new StreamFactory();
 | 
			
		||||
        $this->uriFactory = $uriFactory ?? new UriFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function createRequest(string $method, $uri): RequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        if (is_string($uri)) {
 | 
			
		||||
            $uri = $this->uriFactory->createUri($uri);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!$uri instanceof UriInterface) {
 | 
			
		||||
            throw new InvalidArgumentException(
 | 
			
		||||
                'Parameter 2 of RequestFactory::createRequest() must be a string or a compatible UriInterface.'
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $body = $this->streamFactory->createStream();
 | 
			
		||||
 | 
			
		||||
        return new Request($method, $uri, new Headers(), [], [], $body);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								qwen/php/vendor/slim/psr7/src/Factory/ResponseFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								qwen/php/vendor/slim/psr7/src/Factory/ResponseFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use Fig\Http\Message\StatusCodeInterface;
 | 
			
		||||
use Psr\Http\Message\ResponseFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\ResponseInterface;
 | 
			
		||||
use Slim\Psr7\Response;
 | 
			
		||||
 | 
			
		||||
class ResponseFactory implements ResponseFactoryInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function createResponse(
 | 
			
		||||
        int $code = StatusCodeInterface::STATUS_OK,
 | 
			
		||||
        string $reasonPhrase = ''
 | 
			
		||||
    ): ResponseInterface {
 | 
			
		||||
        $res = new Response($code);
 | 
			
		||||
 | 
			
		||||
        if ($reasonPhrase !== '') {
 | 
			
		||||
            $res = $res->withStatus($code, $reasonPhrase);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $res;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										111
									
								
								qwen/php/vendor/slim/psr7/src/Factory/ServerRequestFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								qwen/php/vendor/slim/psr7/src/Factory/ServerRequestFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,111 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\ServerRequestFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\ServerRequestInterface;
 | 
			
		||||
use Psr\Http\Message\StreamFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\UriFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Cookies;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Request;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
 | 
			
		||||
use function current;
 | 
			
		||||
use function explode;
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function in_array;
 | 
			
		||||
use function is_string;
 | 
			
		||||
 | 
			
		||||
class ServerRequestFactory implements ServerRequestFactoryInterface
 | 
			
		||||
{
 | 
			
		||||
    protected StreamFactoryInterface $streamFactory;
 | 
			
		||||
 | 
			
		||||
    protected UriFactoryInterface $uriFactory;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param StreamFactoryInterface|null $streamFactory
 | 
			
		||||
     * @param UriFactoryInterface|null    $uriFactory
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(?StreamFactoryInterface $streamFactory = null, ?UriFactoryInterface $uriFactory = null)
 | 
			
		||||
    {
 | 
			
		||||
        $this->streamFactory = $streamFactory ?? new StreamFactory();
 | 
			
		||||
        $this->uriFactory = $uriFactory ?? new UriFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        if (is_string($uri)) {
 | 
			
		||||
            $uri = $this->uriFactory->createUri($uri);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!$uri instanceof UriInterface) {
 | 
			
		||||
            throw new InvalidArgumentException('URI must either be string or instance of ' . UriInterface::class);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $body = $this->streamFactory->createStream();
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
 | 
			
		||||
        if (!empty($serverParams)) {
 | 
			
		||||
            $headers = Headers::createFromGlobals();
 | 
			
		||||
            $cookies = Cookies::parseHeader($headers->getHeader('Cookie', []));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Request($method, $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create new ServerRequest from environment.
 | 
			
		||||
     *
 | 
			
		||||
     * @internal This method is not part of PSR-17
 | 
			
		||||
     *
 | 
			
		||||
     * @return Request
 | 
			
		||||
     */
 | 
			
		||||
    public static function createFromGlobals(): Request
 | 
			
		||||
    {
 | 
			
		||||
        /** @var string $method */
 | 
			
		||||
        $method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
 | 
			
		||||
        $uri = (new UriFactory())->createFromGlobals($_SERVER);
 | 
			
		||||
 | 
			
		||||
        $headers = Headers::createFromGlobals();
 | 
			
		||||
        $cookies = Cookies::parseHeader($headers->getHeader('Cookie', []));
 | 
			
		||||
 | 
			
		||||
        // Cache the php://input stream as it cannot be re-read
 | 
			
		||||
        $cacheResource = fopen('php://temp', 'wb+');
 | 
			
		||||
        $cache = $cacheResource ? new Stream($cacheResource) : null;
 | 
			
		||||
 | 
			
		||||
        $body = (new StreamFactory())->createStreamFromFile('php://input', 'r', $cache);
 | 
			
		||||
        $uploadedFiles = UploadedFile::createFromGlobals($_SERVER);
 | 
			
		||||
 | 
			
		||||
        $request = new Request($method, $uri, $headers, $cookies, $_SERVER, $body, $uploadedFiles);
 | 
			
		||||
        $contentTypes = $request->getHeader('Content-Type');
 | 
			
		||||
 | 
			
		||||
        $parsedContentType = '';
 | 
			
		||||
        foreach ($contentTypes as $contentType) {
 | 
			
		||||
            $fragments = explode(';', $contentType);
 | 
			
		||||
            $parsedContentType = current($fragments);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $contentTypesWithParsedBodies = ['application/x-www-form-urlencoded', 'multipart/form-data'];
 | 
			
		||||
        if ($method === 'POST' && in_array($parsedContentType, $contentTypesWithParsedBodies)) {
 | 
			
		||||
            return $request->withParsedBody($_POST);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $request;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										95
									
								
								qwen/php/vendor/slim/psr7/src/Factory/StreamFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								qwen/php/vendor/slim/psr7/src/Factory/StreamFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,95 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\StreamFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use ValueError;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function is_resource;
 | 
			
		||||
use function restore_error_handler;
 | 
			
		||||
use function rewind;
 | 
			
		||||
use function set_error_handler;
 | 
			
		||||
 | 
			
		||||
class StreamFactory implements StreamFactoryInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @throws RuntimeException
 | 
			
		||||
     */
 | 
			
		||||
    public function createStream(string $content = ''): StreamInterface
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'rw+');
 | 
			
		||||
 | 
			
		||||
        if (!is_resource($resource)) {
 | 
			
		||||
            throw new RuntimeException('StreamFactory::createStream() could not open temporary file stream.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        fwrite($resource, $content);
 | 
			
		||||
        rewind($resource);
 | 
			
		||||
 | 
			
		||||
        return $this->createStreamFromResource($resource);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function createStreamFromFile(
 | 
			
		||||
        string $filename,
 | 
			
		||||
        string $mode = 'r',
 | 
			
		||||
        ?StreamInterface $cache = null
 | 
			
		||||
    ): StreamInterface {
 | 
			
		||||
        set_error_handler(
 | 
			
		||||
            static function (int $errno, string $errstr) use ($filename, $mode): void {
 | 
			
		||||
                throw new RuntimeException(
 | 
			
		||||
                    "Unable to open $filename using mode $mode: $errstr",
 | 
			
		||||
                    $errno
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            $resource = fopen($filename, $mode);
 | 
			
		||||
        } catch (ValueError $exception) {
 | 
			
		||||
            throw new RuntimeException("Unable to open $filename using mode $mode: " . $exception->getMessage());
 | 
			
		||||
        } finally {
 | 
			
		||||
            restore_error_handler();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!is_resource($resource)) {
 | 
			
		||||
            throw new RuntimeException(
 | 
			
		||||
                "StreamFactory::createStreamFromFile() could not create resource from file `$filename`"
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Stream($resource, $cache);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function createStreamFromResource($resource, ?StreamInterface $cache = null): StreamInterface
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_resource($resource)) {
 | 
			
		||||
            throw new InvalidArgumentException(
 | 
			
		||||
                'Parameter 1 of StreamFactory::createStreamFromResource() must be a resource.'
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Stream($resource, $cache);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										47
									
								
								qwen/php/vendor/slim/psr7/src/Factory/UploadedFileFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								qwen/php/vendor/slim/psr7/src/Factory/UploadedFileFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Psr\Http\Message\UploadedFileFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\UploadedFileInterface;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
 | 
			
		||||
use function is_string;
 | 
			
		||||
 | 
			
		||||
use const UPLOAD_ERR_OK;
 | 
			
		||||
 | 
			
		||||
class UploadedFileFactory implements UploadedFileFactoryInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function createUploadedFile(
 | 
			
		||||
        StreamInterface $stream,
 | 
			
		||||
        ?int $size = null,
 | 
			
		||||
        int $error = UPLOAD_ERR_OK,
 | 
			
		||||
        ?string $clientFilename = null,
 | 
			
		||||
        ?string $clientMediaType = null
 | 
			
		||||
    ): UploadedFileInterface {
 | 
			
		||||
        $file = $stream->getMetadata('uri');
 | 
			
		||||
 | 
			
		||||
        if (!is_string($file) || !$stream->isReadable()) {
 | 
			
		||||
            throw new InvalidArgumentException('File is not readable.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($size === null) {
 | 
			
		||||
            $size = $stream->getSize();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new UploadedFile($stream, $clientFilename, $clientMediaType, $size, $error);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										113
									
								
								qwen/php/vendor/slim/psr7/src/Factory/UriFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								qwen/php/vendor/slim/psr7/src/Factory/UriFactory.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,113 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\UriFactoryInterface;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Uri;
 | 
			
		||||
 | 
			
		||||
use function count;
 | 
			
		||||
use function explode;
 | 
			
		||||
use function parse_url;
 | 
			
		||||
use function preg_match;
 | 
			
		||||
use function strpos;
 | 
			
		||||
use function strstr;
 | 
			
		||||
use function substr;
 | 
			
		||||
 | 
			
		||||
use const PHP_URL_QUERY;
 | 
			
		||||
 | 
			
		||||
class UriFactory implements UriFactoryInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function createUri(string $uri = ''): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        $parts = parse_url($uri);
 | 
			
		||||
 | 
			
		||||
        if ($parts === false) {
 | 
			
		||||
            throw new InvalidArgumentException('URI cannot be parsed');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $scheme = $parts['scheme'] ?? '';
 | 
			
		||||
        $user = $parts['user'] ?? '';
 | 
			
		||||
        $pass = $parts['pass'] ?? '';
 | 
			
		||||
        $host = $parts['host'] ?? '';
 | 
			
		||||
        $port = $parts['port'] ?? null;
 | 
			
		||||
        $path = $parts['path'] ?? '';
 | 
			
		||||
        $query = $parts['query'] ?? '';
 | 
			
		||||
        $fragment = $parts['fragment'] ?? '';
 | 
			
		||||
 | 
			
		||||
        return new Uri($scheme, $host, $port, $path, $query, $fragment, $user, $pass);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create new Uri from environment.
 | 
			
		||||
     *
 | 
			
		||||
     * @internal This method is not part of PSR-17
 | 
			
		||||
     *
 | 
			
		||||
     * @param array $globals The global server variables.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Uri
 | 
			
		||||
     */
 | 
			
		||||
    public function createFromGlobals(array $globals): Uri
 | 
			
		||||
    {
 | 
			
		||||
        // Scheme
 | 
			
		||||
        $https = $globals['HTTPS'] ?? false;
 | 
			
		||||
        $scheme = !$https || $https === 'off' ? 'http' : 'https';
 | 
			
		||||
 | 
			
		||||
        // Authority: Username and password
 | 
			
		||||
        $username = $globals['PHP_AUTH_USER'] ?? '';
 | 
			
		||||
        $password = $globals['PHP_AUTH_PW'] ?? '';
 | 
			
		||||
 | 
			
		||||
        // Authority: Host
 | 
			
		||||
        $host = '';
 | 
			
		||||
        if (isset($globals['HTTP_HOST'])) {
 | 
			
		||||
            $host = $globals['HTTP_HOST'];
 | 
			
		||||
        } elseif (isset($globals['SERVER_NAME'])) {
 | 
			
		||||
            $host = $globals['SERVER_NAME'];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Authority: Port
 | 
			
		||||
        $port = !empty($globals['SERVER_PORT']) ? (int)$globals['SERVER_PORT'] : ($scheme === 'https' ? 443 : 80);
 | 
			
		||||
        if (preg_match('/^(\[[a-fA-F0-9:.]+])(:\d+)?\z/', $host, $matches)) {
 | 
			
		||||
            $host = $matches[1];
 | 
			
		||||
 | 
			
		||||
            if (isset($matches[2])) {
 | 
			
		||||
                $port = (int) substr($matches[2], 1);
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            $pos = strpos($host, ':');
 | 
			
		||||
            if ($pos !== false) {
 | 
			
		||||
                $port = (int) substr($host, $pos + 1);
 | 
			
		||||
                $host = strstr($host, ':', true);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Query string
 | 
			
		||||
        $queryString = $globals['QUERY_STRING'] ?? '';
 | 
			
		||||
 | 
			
		||||
        // Request URI
 | 
			
		||||
        $requestUri = '';
 | 
			
		||||
        if (isset($globals['REQUEST_URI'])) {
 | 
			
		||||
            $uriFragments = explode('?', $globals['REQUEST_URI']);
 | 
			
		||||
            $requestUri = $uriFragments[0];
 | 
			
		||||
 | 
			
		||||
            if ($queryString === '' && count($uriFragments) > 1) {
 | 
			
		||||
                $queryString = parse_url('https://www.example.com' . $globals['REQUEST_URI'], PHP_URL_QUERY) ?? '';
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Build Uri and return
 | 
			
		||||
        return new Uri($scheme, $host, $port, $requestUri, $queryString, '', $username, $password);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										63
									
								
								qwen/php/vendor/slim/psr7/src/Header.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								qwen/php/vendor/slim/psr7/src/Header.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use function array_merge;
 | 
			
		||||
use function is_string;
 | 
			
		||||
 | 
			
		||||
class Header
 | 
			
		||||
{
 | 
			
		||||
    private string $originalName;
 | 
			
		||||
 | 
			
		||||
    private string $normalizedName;
 | 
			
		||||
 | 
			
		||||
    private array $values;
 | 
			
		||||
 | 
			
		||||
    public function __construct(string $originalName, string $normalizedName, array $values)
 | 
			
		||||
    {
 | 
			
		||||
        $this->originalName = $originalName;
 | 
			
		||||
        $this->normalizedName = $normalizedName;
 | 
			
		||||
        $this->values = $values;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getOriginalName(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->originalName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getNormalizedName(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->normalizedName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function addValue(string $value): self
 | 
			
		||||
    {
 | 
			
		||||
        $this->values[] = $value;
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function addValues(array|string $values): self
 | 
			
		||||
    {
 | 
			
		||||
        if (is_string($values)) {
 | 
			
		||||
            return $this->addValue($values);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->values = array_merge($this->values, $values);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getValues(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->values;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										318
									
								
								qwen/php/vendor/slim/psr7/src/Headers.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										318
									
								
								qwen/php/vendor/slim/psr7/src/Headers.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,318 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Slim\Psr7\Interfaces\HeadersInterface;
 | 
			
		||||
 | 
			
		||||
use function base64_encode;
 | 
			
		||||
use function function_exists;
 | 
			
		||||
use function getallheaders;
 | 
			
		||||
use function is_array;
 | 
			
		||||
use function is_numeric;
 | 
			
		||||
use function is_string;
 | 
			
		||||
use function preg_match;
 | 
			
		||||
use function strpos;
 | 
			
		||||
use function strtolower;
 | 
			
		||||
use function strtr;
 | 
			
		||||
use function substr;
 | 
			
		||||
use function trim;
 | 
			
		||||
 | 
			
		||||
class Headers implements HeadersInterface
 | 
			
		||||
{
 | 
			
		||||
    protected array $globals;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var Header[]
 | 
			
		||||
     */
 | 
			
		||||
    protected array $headers;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array      $headers
 | 
			
		||||
     * @param array|null $globals
 | 
			
		||||
     */
 | 
			
		||||
    final public function __construct(array $headers = [], ?array $globals = null)
 | 
			
		||||
    {
 | 
			
		||||
        $this->globals = $globals ?? $_SERVER;
 | 
			
		||||
        $this->setHeaders($headers);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function addHeader($name, $value): HeadersInterface
 | 
			
		||||
    {
 | 
			
		||||
        [$values, $originalName, $normalizedName] = $this->prepareHeader($name, $value);
 | 
			
		||||
 | 
			
		||||
        if (isset($this->headers[$normalizedName])) {
 | 
			
		||||
            $header = $this->headers[$normalizedName];
 | 
			
		||||
            $header->addValues($values);
 | 
			
		||||
        } else {
 | 
			
		||||
            $this->headers[$normalizedName] = new Header($originalName, $normalizedName, $values);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function removeHeader(string $name): HeadersInterface
 | 
			
		||||
    {
 | 
			
		||||
        $name = $this->normalizeHeaderName($name);
 | 
			
		||||
        unset($this->headers[$name]);
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getHeader(string $name, $default = []): array
 | 
			
		||||
    {
 | 
			
		||||
        $name = $this->normalizeHeaderName($name);
 | 
			
		||||
 | 
			
		||||
        if (isset($this->headers[$name])) {
 | 
			
		||||
            $header = $this->headers[$name];
 | 
			
		||||
            return $header->getValues();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (empty($default)) {
 | 
			
		||||
            return $default;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->validateHeader($name, $default);
 | 
			
		||||
        return $this->trimHeaderValue($default);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function setHeader($name, $value): HeadersInterface
 | 
			
		||||
    {
 | 
			
		||||
        [$values, $originalName, $normalizedName] = $this->prepareHeader($name, $value);
 | 
			
		||||
 | 
			
		||||
        // Ensure we preserve original case if the header already exists in the stack
 | 
			
		||||
        if (isset($this->headers[$normalizedName])) {
 | 
			
		||||
            $existingHeader = $this->headers[$normalizedName];
 | 
			
		||||
            $originalName = $existingHeader->getOriginalName();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->headers[$normalizedName] = new Header($originalName, $normalizedName, $values);
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function setHeaders(array $headers): HeadersInterface
 | 
			
		||||
    {
 | 
			
		||||
        $this->headers = [];
 | 
			
		||||
 | 
			
		||||
        foreach ($this->parseAuthorizationHeader($headers) as $name => $value) {
 | 
			
		||||
            $this->addHeader($name, $value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function hasHeader(string $name): bool
 | 
			
		||||
    {
 | 
			
		||||
        $name = $this->normalizeHeaderName($name);
 | 
			
		||||
        return isset($this->headers[$name]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getHeaders(bool $originalCase = false): array
 | 
			
		||||
    {
 | 
			
		||||
        $headers = [];
 | 
			
		||||
 | 
			
		||||
        foreach ($this->headers as $header) {
 | 
			
		||||
            $name = $originalCase ? $header->getOriginalName() : $header->getNormalizedName();
 | 
			
		||||
            $headers[$name] = $header->getValues();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $headers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $name
 | 
			
		||||
     * @param bool   $preserveCase
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    protected function normalizeHeaderName(string $name, bool $preserveCase = false): string
 | 
			
		||||
    {
 | 
			
		||||
        $name = strtr($name, '_', '-');
 | 
			
		||||
 | 
			
		||||
        if (!$preserveCase) {
 | 
			
		||||
            $name = strtolower($name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (strpos(strtolower($name), 'http-') === 0) {
 | 
			
		||||
            $name = substr($name, 5);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Parse incoming headers and determine Authorization header from original headers
 | 
			
		||||
     *
 | 
			
		||||
     * @param array $headers
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    protected function parseAuthorizationHeader(array $headers): array
 | 
			
		||||
    {
 | 
			
		||||
        $hasAuthorizationHeader = false;
 | 
			
		||||
        foreach ($headers as $name => $value) {
 | 
			
		||||
            if (strtolower((string) $name) === 'authorization') {
 | 
			
		||||
                $hasAuthorizationHeader = true;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!$hasAuthorizationHeader) {
 | 
			
		||||
            if (isset($this->globals['REDIRECT_HTTP_AUTHORIZATION'])) {
 | 
			
		||||
                $headers['Authorization'] = $this->globals['REDIRECT_HTTP_AUTHORIZATION'];
 | 
			
		||||
            } elseif (isset($this->globals['PHP_AUTH_USER'])) {
 | 
			
		||||
                $pw = $this->globals['PHP_AUTH_PW'] ?? '';
 | 
			
		||||
                $headers['Authorization'] = 'Basic ' . base64_encode($this->globals['PHP_AUTH_USER'] . ':' . $pw);
 | 
			
		||||
            } elseif (isset($this->globals['PHP_AUTH_DIGEST'])) {
 | 
			
		||||
                $headers['Authorization'] = $this->globals['PHP_AUTH_DIGEST'];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $headers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array|string $value
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    protected function trimHeaderValue($value): array
 | 
			
		||||
    {
 | 
			
		||||
        $items = is_array($value) ? $value : [$value];
 | 
			
		||||
        $result = [];
 | 
			
		||||
        foreach ($items as $item) {
 | 
			
		||||
            $result[] = trim((string) $item, " \t");
 | 
			
		||||
        }
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string       $name
 | 
			
		||||
     * @param array|string $value
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    protected function prepareHeader($name, $value): array
 | 
			
		||||
    {
 | 
			
		||||
        $this->validateHeader($name, $value);
 | 
			
		||||
        $values = $this->trimHeaderValue($value);
 | 
			
		||||
        $originalName = $this->normalizeHeaderName($name, true);
 | 
			
		||||
        $normalizedName = $this->normalizeHeaderName($name);
 | 
			
		||||
        return [$values, $originalName, $normalizedName];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Make sure the header complies with RFC 7230.
 | 
			
		||||
     *
 | 
			
		||||
     * Header names must be a non-empty string consisting of token characters.
 | 
			
		||||
     *
 | 
			
		||||
     * Header values must be strings consisting of visible characters with all optional
 | 
			
		||||
     * leading and trailing whitespace stripped. This method will always strip such
 | 
			
		||||
     * optional whitespace. Note that the method does not allow folding whitespace within
 | 
			
		||||
     * the values as this was deprecated for almost all instances by the RFC.
 | 
			
		||||
     *
 | 
			
		||||
     * header-field = field-name ":" OWS field-value OWS
 | 
			
		||||
     * field-name   = 1*( "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^"
 | 
			
		||||
     *              / "_" / "`" / "|" / "~" / %x30-39 / ( %x41-5A / %x61-7A ) )
 | 
			
		||||
     * OWS          = *( SP / HTAB )
 | 
			
		||||
     * field-value  = *( ( %x21-7E / %x80-FF ) [ 1*( SP / HTAB ) ( %x21-7E / %x80-FF ) ] )
 | 
			
		||||
     *
 | 
			
		||||
     * @see https://tools.ietf.org/html/rfc7230#section-3.2.4
 | 
			
		||||
     *
 | 
			
		||||
     * @param string        $name
 | 
			
		||||
     * @param array|string  $value
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException
 | 
			
		||||
     */
 | 
			
		||||
    protected function validateHeader($name, $value): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->validateHeaderName($name);
 | 
			
		||||
        $this->validateHeaderValue($value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param mixed $name
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException
 | 
			
		||||
     */
 | 
			
		||||
    protected function validateHeaderName($name): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_string($name) || preg_match("@^[!#$%&'*+.^_`|~0-9A-Za-z-]+$@D", $name) !== 1) {
 | 
			
		||||
            throw new InvalidArgumentException('Header name must be an RFC 7230 compatible string.');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param mixed $value
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException
 | 
			
		||||
     */
 | 
			
		||||
    protected function validateHeaderValue($value): void
 | 
			
		||||
    {
 | 
			
		||||
        $items = is_array($value) ? $value : [$value];
 | 
			
		||||
 | 
			
		||||
        if (empty($items)) {
 | 
			
		||||
            throw new InvalidArgumentException(
 | 
			
		||||
                'Header values must be a string or an array of strings, empty array given.'
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $pattern = "@^[ \t\x21-\x7E\x80-\xFF]*$@D";
 | 
			
		||||
        foreach ($items as $item) {
 | 
			
		||||
            $hasInvalidType = !is_numeric($item) && !is_string($item);
 | 
			
		||||
            $rejected = $hasInvalidType || preg_match($pattern, (string) $item) !== 1;
 | 
			
		||||
            if ($rejected) {
 | 
			
		||||
                throw new InvalidArgumentException(
 | 
			
		||||
                    'Header values must be RFC 7230 compatible strings.'
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public static function createFromGlobals()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = null;
 | 
			
		||||
 | 
			
		||||
        if (function_exists('getallheaders')) {
 | 
			
		||||
            $headers = getallheaders();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!is_array($headers)) {
 | 
			
		||||
            $headers = [];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new static($headers);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										90
									
								
								qwen/php/vendor/slim/psr7/src/Interfaces/HeadersInterface.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								qwen/php/vendor/slim/psr7/src/Interfaces/HeadersInterface.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,90 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7\Interfaces;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
 | 
			
		||||
interface HeadersInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Add header value
 | 
			
		||||
     *
 | 
			
		||||
     * This method appends the value to the existing array of values
 | 
			
		||||
     *
 | 
			
		||||
     * @param string       $name
 | 
			
		||||
     * @param array|string $value
 | 
			
		||||
     *
 | 
			
		||||
     * @return HeadersInterface
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException
 | 
			
		||||
     */
 | 
			
		||||
    public function addHeader($name, $value): HeadersInterface;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remove header value
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $name
 | 
			
		||||
     * @return HeadersInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function removeHeader(string $name): HeadersInterface;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get header value or values.
 | 
			
		||||
     * If the array has a single value it will return that single value.
 | 
			
		||||
     * If the array has multiple values, it will return an array of values.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string   $name
 | 
			
		||||
     * @param string[] $default
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function getHeader(string $name, $default = []): array;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Replaces the existing header value with the new value.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string       $name
 | 
			
		||||
     * @param array|string $value
 | 
			
		||||
     *
 | 
			
		||||
     * @return HeadersInterface
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException
 | 
			
		||||
     */
 | 
			
		||||
    public function setHeader($name, $value): HeadersInterface;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Replaces all existing headers with the new values.
 | 
			
		||||
     *
 | 
			
		||||
     * @param array $headers
 | 
			
		||||
     *
 | 
			
		||||
     * @return HeadersInterface
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException
 | 
			
		||||
     */
 | 
			
		||||
    public function setHeaders(array $headers): HeadersInterface;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is the header present in the stack.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $name
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function hasHeader(string $name): bool;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Return all headers in the stack.
 | 
			
		||||
     *
 | 
			
		||||
     * @param bool $originalCase
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function getHeaders(bool $originalCase): array;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										185
									
								
								qwen/php/vendor/slim/psr7/src/Message.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										185
									
								
								qwen/php/vendor/slim/psr7/src/Message.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,185 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\MessageInterface;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Slim\Psr7\Interfaces\HeadersInterface;
 | 
			
		||||
 | 
			
		||||
use function array_keys;
 | 
			
		||||
use function header;
 | 
			
		||||
use function header_remove;
 | 
			
		||||
use function implode;
 | 
			
		||||
use function sprintf;
 | 
			
		||||
 | 
			
		||||
abstract class Message implements MessageInterface
 | 
			
		||||
{
 | 
			
		||||
    protected string $protocolVersion = '1.1';
 | 
			
		||||
 | 
			
		||||
    protected static array $validProtocolVersions = [
 | 
			
		||||
        '1.0' => true,
 | 
			
		||||
        '1.1' => true,
 | 
			
		||||
        '2.0' => true,
 | 
			
		||||
        '2' => true,
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var HeadersInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $headers;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var StreamInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $body;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Disable magic setter to ensure immutability
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $name  The property name
 | 
			
		||||
     * @param mixed  $value The property value
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function __set($name, $value): void
 | 
			
		||||
    {
 | 
			
		||||
        // Do nothing
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getProtocolVersion(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->protocolVersion;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return static
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function withProtocolVersion($version): MessageInterface
 | 
			
		||||
    {
 | 
			
		||||
        if (!isset(self::$validProtocolVersions[$version])) {
 | 
			
		||||
            throw new InvalidArgumentException(
 | 
			
		||||
                'Invalid HTTP version. Must be one of: '
 | 
			
		||||
                . implode(', ', array_keys(self::$validProtocolVersions))
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->protocolVersion = $version;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getHeaders(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->headers->getHeaders(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function hasHeader($name): bool
 | 
			
		||||
    {
 | 
			
		||||
        return $this->headers->hasHeader($name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getHeader($name): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->headers->getHeader($name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getHeaderLine($name): string
 | 
			
		||||
    {
 | 
			
		||||
        $values = $this->headers->getHeader($name);
 | 
			
		||||
        return implode(',', $values);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return static
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function withHeader($name, $value): MessageInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->headers->setHeader($name, $value);
 | 
			
		||||
 | 
			
		||||
        if ($this instanceof Response && $this->body instanceof NonBufferedBody) {
 | 
			
		||||
            header(sprintf('%s: %s', $name, $clone->getHeaderLine($name)));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return static
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function withAddedHeader($name, $value): MessageInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->headers->addHeader($name, $value);
 | 
			
		||||
 | 
			
		||||
        if ($this instanceof Response && $this->body instanceof NonBufferedBody) {
 | 
			
		||||
            header(sprintf('%s: %s', $name, $clone->getHeaderLine($name)));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return static
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function withoutHeader($name): MessageInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->headers->removeHeader($name);
 | 
			
		||||
 | 
			
		||||
        if ($this instanceof Response && $this->body instanceof NonBufferedBody) {
 | 
			
		||||
            header_remove($name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getBody(): StreamInterface
 | 
			
		||||
    {
 | 
			
		||||
        return $this->body;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return static
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function withBody(StreamInterface $body): MessageInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->body = $body;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										153
									
								
								qwen/php/vendor/slim/psr7/src/NonBufferedBody.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								qwen/php/vendor/slim/psr7/src/NonBufferedBody.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,153 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
 | 
			
		||||
use function flush;
 | 
			
		||||
use function ob_get_clean;
 | 
			
		||||
use function ob_get_level;
 | 
			
		||||
use function strlen;
 | 
			
		||||
 | 
			
		||||
use const SEEK_SET;
 | 
			
		||||
 | 
			
		||||
class NonBufferedBody implements StreamInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function __toString(): string
 | 
			
		||||
    {
 | 
			
		||||
        return '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function close(): void
 | 
			
		||||
    {
 | 
			
		||||
        throw new RuntimeException('A NonBufferedBody is not closable.');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function detach()
 | 
			
		||||
    {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getSize(): ?int
 | 
			
		||||
    {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function tell(): int
 | 
			
		||||
    {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function eof(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function isSeekable(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function seek($offset, $whence = SEEK_SET): void
 | 
			
		||||
    {
 | 
			
		||||
        throw new RuntimeException('A NonBufferedBody is not seekable.');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function rewind(): void
 | 
			
		||||
    {
 | 
			
		||||
        throw new RuntimeException('A NonBufferedBody is not rewindable.');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function isWritable(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function write($string): int
 | 
			
		||||
    {
 | 
			
		||||
        $buffered = '';
 | 
			
		||||
        while (0 < ob_get_level()) {
 | 
			
		||||
            $buffered = ob_get_clean() . $buffered;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        echo $buffered . $string;
 | 
			
		||||
 | 
			
		||||
        flush();
 | 
			
		||||
 | 
			
		||||
        return strlen($string) + strlen($buffered);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function isReadable(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function read($length): string
 | 
			
		||||
    {
 | 
			
		||||
        throw new RuntimeException('A NonBufferedBody is not readable.');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getContents(): string
 | 
			
		||||
    {
 | 
			
		||||
        return '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getMetadata($key = null): ?array
 | 
			
		||||
    {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										382
									
								
								qwen/php/vendor/slim/psr7/src/Request.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										382
									
								
								qwen/php/vendor/slim/psr7/src/Request.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,382 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\RequestInterface;
 | 
			
		||||
use Psr\Http\Message\ServerRequestInterface;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Psr\Http\Message\UploadedFileInterface;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Interfaces\HeadersInterface;
 | 
			
		||||
 | 
			
		||||
use function get_class;
 | 
			
		||||
use function gettype;
 | 
			
		||||
use function is_array;
 | 
			
		||||
use function is_null;
 | 
			
		||||
use function is_object;
 | 
			
		||||
use function is_string;
 | 
			
		||||
use function ltrim;
 | 
			
		||||
use function parse_str;
 | 
			
		||||
use function preg_match;
 | 
			
		||||
use function sprintf;
 | 
			
		||||
use function str_replace;
 | 
			
		||||
 | 
			
		||||
class Request extends Message implements ServerRequestInterface
 | 
			
		||||
{
 | 
			
		||||
    protected string $method;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var UriInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $uri;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    protected $requestTarget;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var ?array
 | 
			
		||||
     */
 | 
			
		||||
    protected $queryParams;
 | 
			
		||||
 | 
			
		||||
    protected array $cookies;
 | 
			
		||||
 | 
			
		||||
    protected array $serverParams;
 | 
			
		||||
 | 
			
		||||
    protected array $attributes;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var null|array|object
 | 
			
		||||
     */
 | 
			
		||||
    protected $parsedBody;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var UploadedFileInterface[]
 | 
			
		||||
     */
 | 
			
		||||
    protected array $uploadedFiles;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string           $method        The request method
 | 
			
		||||
     * @param UriInterface     $uri           The request URI object
 | 
			
		||||
     * @param HeadersInterface $headers       The request headers collection
 | 
			
		||||
     * @param array            $cookies       The request cookies collection
 | 
			
		||||
     * @param array            $serverParams  The server environment variables
 | 
			
		||||
     * @param StreamInterface  $body          The request body object
 | 
			
		||||
     * @param array            $uploadedFiles The request uploadedFiles collection
 | 
			
		||||
     * @throws InvalidArgumentException on invalid HTTP method
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(
 | 
			
		||||
        $method,
 | 
			
		||||
        UriInterface $uri,
 | 
			
		||||
        HeadersInterface $headers,
 | 
			
		||||
        array $cookies,
 | 
			
		||||
        array $serverParams,
 | 
			
		||||
        StreamInterface $body,
 | 
			
		||||
        array $uploadedFiles = []
 | 
			
		||||
    ) {
 | 
			
		||||
        $this->method = $this->filterMethod($method);
 | 
			
		||||
        $this->uri = $uri;
 | 
			
		||||
        $this->headers = $headers;
 | 
			
		||||
        $this->cookies = $cookies;
 | 
			
		||||
        $this->serverParams = $serverParams;
 | 
			
		||||
        $this->attributes = [];
 | 
			
		||||
        $this->body = $body;
 | 
			
		||||
        $this->uploadedFiles = $uploadedFiles;
 | 
			
		||||
 | 
			
		||||
        if (isset($serverParams['SERVER_PROTOCOL'])) {
 | 
			
		||||
            $this->protocolVersion = str_replace('HTTP/', '', $serverParams['SERVER_PROTOCOL']);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!$this->headers->hasHeader('Host') || $this->uri->getHost() !== '') {
 | 
			
		||||
            $this->headers->setHeader('Host', $this->uri->getHost());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is applied to the cloned object after PHP performs an initial shallow-copy.
 | 
			
		||||
     * This method completes a deep-copy by creating new objects for the cloned object's internal reference pointers.
 | 
			
		||||
     */
 | 
			
		||||
    public function __clone()
 | 
			
		||||
    {
 | 
			
		||||
        $this->headers = clone $this->headers;
 | 
			
		||||
        $this->body = clone $this->body;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getMethod(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->method;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withMethod($method): RequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        $method = $this->filterMethod($method);
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->method = $method;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Validate the HTTP method
 | 
			
		||||
     *
 | 
			
		||||
     * @param  string $method
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException on invalid HTTP method.
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterMethod($method): string
 | 
			
		||||
    {
 | 
			
		||||
        /** @var mixed $method */
 | 
			
		||||
        if (!is_string($method)) {
 | 
			
		||||
            throw new InvalidArgumentException(sprintf(
 | 
			
		||||
                'Unsupported HTTP method; must be a string, received %s',
 | 
			
		||||
                (is_object($method) ? get_class($method) : gettype($method))
 | 
			
		||||
            ));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (preg_match("/^[!#$%&'*+.^_`|~0-9a-z-]+$/i", $method) !== 1) {
 | 
			
		||||
            throw new InvalidArgumentException(sprintf(
 | 
			
		||||
                'Unsupported HTTP method "%s" provided',
 | 
			
		||||
                $method
 | 
			
		||||
            ));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $method;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getRequestTarget(): string
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->requestTarget) {
 | 
			
		||||
            return $this->requestTarget;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($this->uri === null) {
 | 
			
		||||
            return '/';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $path = $this->uri->getPath();
 | 
			
		||||
        $path = '/' . ltrim($path, '/');
 | 
			
		||||
 | 
			
		||||
        $query = $this->uri->getQuery();
 | 
			
		||||
        if ($query) {
 | 
			
		||||
            $path .= '?' . $query;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $path;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withRequestTarget($requestTarget): RequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_string($requestTarget) || preg_match('#\s#', $requestTarget)) {
 | 
			
		||||
            throw new InvalidArgumentException(
 | 
			
		||||
                'Invalid request target provided; must be a string and cannot contain whitespace'
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->requestTarget = $requestTarget;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getUri(): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        return $this->uri;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->uri = $uri;
 | 
			
		||||
 | 
			
		||||
        if (!$preserveHost && $uri->getHost() !== '') {
 | 
			
		||||
            $clone->headers->setHeader('Host', $uri->getHost());
 | 
			
		||||
            return $clone;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (($uri->getHost() !== '' && !$this->hasHeader('Host') || $this->getHeaderLine('Host') === '')) {
 | 
			
		||||
            $clone->headers->setHeader('Host', $uri->getHost());
 | 
			
		||||
            return $clone;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getCookieParams(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->cookies;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withCookieParams(array $cookies): ServerRequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->cookies = $cookies;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getQueryParams(): array
 | 
			
		||||
    {
 | 
			
		||||
        if (is_array($this->queryParams)) {
 | 
			
		||||
            return $this->queryParams;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($this->uri === null) {
 | 
			
		||||
            return [];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Decode URL data
 | 
			
		||||
        parse_str($this->uri->getQuery(), $this->queryParams);
 | 
			
		||||
 | 
			
		||||
        return is_array($this->queryParams) ? $this->queryParams : [];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withQueryParams(array $query): ServerRequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->queryParams = $query;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getUploadedFiles(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->uploadedFiles;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->uploadedFiles = $uploadedFiles;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getServerParams(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->serverParams;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getAttributes(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->attributes;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return mixed
 | 
			
		||||
     */
 | 
			
		||||
    public function getAttribute($name, $default = null)
 | 
			
		||||
    {
 | 
			
		||||
        return $this->attributes[$name] ?? $default;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withAttribute($name, $value): ServerRequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->attributes[$name] = $value;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withoutAttribute($name): ServerRequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
 | 
			
		||||
        unset($clone->attributes[$name]);
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getParsedBody()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->parsedBody;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withParsedBody($data): ServerRequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        /** @var mixed $data */
 | 
			
		||||
        if (!is_null($data) && !is_object($data) && !is_array($data)) {
 | 
			
		||||
            throw new InvalidArgumentException('Parsed body value must be an array, an object, or null');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->parsedBody = $data;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										216
									
								
								qwen/php/vendor/slim/psr7/src/Response.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										216
									
								
								qwen/php/vendor/slim/psr7/src/Response.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,216 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use Fig\Http\Message\StatusCodeInterface;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\ResponseInterface;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
use Slim\Psr7\Interfaces\HeadersInterface;
 | 
			
		||||
 | 
			
		||||
use function is_integer;
 | 
			
		||||
use function is_object;
 | 
			
		||||
use function is_string;
 | 
			
		||||
use function method_exists;
 | 
			
		||||
 | 
			
		||||
class Response extends Message implements ResponseInterface
 | 
			
		||||
{
 | 
			
		||||
    protected int $status = StatusCodeInterface::STATUS_OK;
 | 
			
		||||
 | 
			
		||||
    protected string $reasonPhrase = '';
 | 
			
		||||
 | 
			
		||||
    protected static array $messages = [
 | 
			
		||||
        // Informational 1xx
 | 
			
		||||
        StatusCodeInterface::STATUS_CONTINUE => 'Continue',
 | 
			
		||||
        StatusCodeInterface::STATUS_SWITCHING_PROTOCOLS => 'Switching Protocols',
 | 
			
		||||
        StatusCodeInterface::STATUS_PROCESSING => 'Processing',
 | 
			
		||||
 | 
			
		||||
        // Successful 2xx
 | 
			
		||||
        StatusCodeInterface::STATUS_OK => 'OK',
 | 
			
		||||
        StatusCodeInterface::STATUS_CREATED => 'Created',
 | 
			
		||||
        StatusCodeInterface::STATUS_ACCEPTED => 'Accepted',
 | 
			
		||||
        StatusCodeInterface::STATUS_NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information',
 | 
			
		||||
        StatusCodeInterface::STATUS_NO_CONTENT => 'No Content',
 | 
			
		||||
        StatusCodeInterface::STATUS_RESET_CONTENT => 'Reset Content',
 | 
			
		||||
        StatusCodeInterface::STATUS_PARTIAL_CONTENT => 'Partial Content',
 | 
			
		||||
        StatusCodeInterface::STATUS_MULTI_STATUS => 'Multi-Status',
 | 
			
		||||
        StatusCodeInterface::STATUS_ALREADY_REPORTED => 'Already Reported',
 | 
			
		||||
        StatusCodeInterface::STATUS_IM_USED => 'IM Used',
 | 
			
		||||
 | 
			
		||||
        // Redirection 3xx
 | 
			
		||||
        StatusCodeInterface::STATUS_MULTIPLE_CHOICES => 'Multiple Choices',
 | 
			
		||||
        StatusCodeInterface::STATUS_MOVED_PERMANENTLY => 'Moved Permanently',
 | 
			
		||||
        StatusCodeInterface::STATUS_FOUND => 'Found',
 | 
			
		||||
        StatusCodeInterface::STATUS_SEE_OTHER => 'See Other',
 | 
			
		||||
        StatusCodeInterface::STATUS_NOT_MODIFIED => 'Not Modified',
 | 
			
		||||
        StatusCodeInterface::STATUS_USE_PROXY => 'Use Proxy',
 | 
			
		||||
        StatusCodeInterface::STATUS_RESERVED => '(Unused)',
 | 
			
		||||
        StatusCodeInterface::STATUS_TEMPORARY_REDIRECT => 'Temporary Redirect',
 | 
			
		||||
        StatusCodeInterface::STATUS_PERMANENT_REDIRECT => 'Permanent Redirect',
 | 
			
		||||
 | 
			
		||||
        // Client Error 4xx
 | 
			
		||||
        StatusCodeInterface::STATUS_BAD_REQUEST => 'Bad Request',
 | 
			
		||||
        StatusCodeInterface::STATUS_UNAUTHORIZED => 'Unauthorized',
 | 
			
		||||
        StatusCodeInterface::STATUS_PAYMENT_REQUIRED => 'Payment Required',
 | 
			
		||||
        StatusCodeInterface::STATUS_FORBIDDEN => 'Forbidden',
 | 
			
		||||
        StatusCodeInterface::STATUS_NOT_FOUND => 'Not Found',
 | 
			
		||||
        StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED => 'Method Not Allowed',
 | 
			
		||||
        StatusCodeInterface::STATUS_NOT_ACCEPTABLE => 'Not Acceptable',
 | 
			
		||||
        StatusCodeInterface::STATUS_PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required',
 | 
			
		||||
        StatusCodeInterface::STATUS_REQUEST_TIMEOUT => 'Request Timeout',
 | 
			
		||||
        StatusCodeInterface::STATUS_CONFLICT => 'Conflict',
 | 
			
		||||
        StatusCodeInterface::STATUS_GONE => 'Gone',
 | 
			
		||||
        StatusCodeInterface::STATUS_LENGTH_REQUIRED => 'Length Required',
 | 
			
		||||
        StatusCodeInterface::STATUS_PRECONDITION_FAILED => 'Precondition Failed',
 | 
			
		||||
        StatusCodeInterface::STATUS_PAYLOAD_TOO_LARGE => 'Request Entity Too Large',
 | 
			
		||||
        StatusCodeInterface::STATUS_URI_TOO_LONG => 'Request-URI Too Long',
 | 
			
		||||
        StatusCodeInterface::STATUS_UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type',
 | 
			
		||||
        StatusCodeInterface::STATUS_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable',
 | 
			
		||||
        StatusCodeInterface::STATUS_EXPECTATION_FAILED => 'Expectation Failed',
 | 
			
		||||
        StatusCodeInterface::STATUS_IM_A_TEAPOT => 'I\'m a teapot',
 | 
			
		||||
        StatusCodeInterface::STATUS_MISDIRECTED_REQUEST => 'Misdirected Request',
 | 
			
		||||
        StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY => 'Unprocessable Entity',
 | 
			
		||||
        StatusCodeInterface::STATUS_LOCKED => 'Locked',
 | 
			
		||||
        StatusCodeInterface::STATUS_FAILED_DEPENDENCY => 'Failed Dependency',
 | 
			
		||||
        StatusCodeInterface::STATUS_UPGRADE_REQUIRED => 'Upgrade Required',
 | 
			
		||||
        StatusCodeInterface::STATUS_PRECONDITION_REQUIRED => 'Precondition Required',
 | 
			
		||||
        StatusCodeInterface::STATUS_TOO_MANY_REQUESTS => 'Too Many Requests',
 | 
			
		||||
        StatusCodeInterface::STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large',
 | 
			
		||||
        444 => 'Connection Closed Without Response',
 | 
			
		||||
        StatusCodeInterface::STATUS_UNAVAILABLE_FOR_LEGAL_REASONS => 'Unavailable For Legal Reasons',
 | 
			
		||||
        499 => 'Client Closed Request',
 | 
			
		||||
 | 
			
		||||
        // Server Error 5xx
 | 
			
		||||
        StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR => 'Internal Server Error',
 | 
			
		||||
        StatusCodeInterface::STATUS_NOT_IMPLEMENTED => 'Not Implemented',
 | 
			
		||||
        StatusCodeInterface::STATUS_BAD_GATEWAY => 'Bad Gateway',
 | 
			
		||||
        StatusCodeInterface::STATUS_SERVICE_UNAVAILABLE => 'Service Unavailable',
 | 
			
		||||
        StatusCodeInterface::STATUS_GATEWAY_TIMEOUT => 'Gateway Timeout',
 | 
			
		||||
        StatusCodeInterface::STATUS_VERSION_NOT_SUPPORTED => 'HTTP Version Not Supported',
 | 
			
		||||
        StatusCodeInterface::STATUS_VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates',
 | 
			
		||||
        StatusCodeInterface::STATUS_INSUFFICIENT_STORAGE => 'Insufficient Storage',
 | 
			
		||||
        StatusCodeInterface::STATUS_LOOP_DETECTED => 'Loop Detected',
 | 
			
		||||
        StatusCodeInterface::STATUS_NOT_EXTENDED => 'Not Extended',
 | 
			
		||||
        StatusCodeInterface::STATUS_NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required',
 | 
			
		||||
        599 => 'Network Connect Timeout Error',
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param int                   $status  The response status code.
 | 
			
		||||
     * @param HeadersInterface|null $headers The response headers.
 | 
			
		||||
     * @param StreamInterface|null  $body    The response body.
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(
 | 
			
		||||
        int $status = StatusCodeInterface::STATUS_OK,
 | 
			
		||||
        ?HeadersInterface $headers = null,
 | 
			
		||||
        ?StreamInterface $body = null
 | 
			
		||||
    ) {
 | 
			
		||||
        $this->status = $this->filterStatus($status);
 | 
			
		||||
        $this->headers = $headers ?: new Headers([], []);
 | 
			
		||||
        $this->body = $body ?: (new StreamFactory())->createStream();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is applied to the cloned object after PHP performs an initial shallow-copy.
 | 
			
		||||
     * This method completes a deep-copy by creating new objects for the cloned object's internal reference pointers.
 | 
			
		||||
     */
 | 
			
		||||
    public function __clone()
 | 
			
		||||
    {
 | 
			
		||||
        $this->headers = clone $this->headers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getStatusCode(): int
 | 
			
		||||
    {
 | 
			
		||||
        return $this->status;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withStatus($code, $reasonPhrase = ''): ResponseInterface
 | 
			
		||||
    {
 | 
			
		||||
        $code = $this->filterStatus($code);
 | 
			
		||||
        $reasonPhrase = $this->filterReasonPhrase($reasonPhrase);
 | 
			
		||||
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->status = $code;
 | 
			
		||||
        $clone->reasonPhrase = $reasonPhrase;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getReasonPhrase(): string
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->reasonPhrase !== '') {
 | 
			
		||||
            return $this->reasonPhrase;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (isset(static::$messages[$this->status])) {
 | 
			
		||||
            return static::$messages[$this->status];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Filter HTTP status code.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  int $status HTTP status code.
 | 
			
		||||
     *
 | 
			
		||||
     * @return int
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException If an invalid HTTP status code is provided.
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterStatus($status): int
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_integer($status) || $status < StatusCodeInterface::STATUS_CONTINUE || $status > 599) {
 | 
			
		||||
            throw new InvalidArgumentException('Invalid HTTP status code.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $status;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Filter Reason Phrase
 | 
			
		||||
     *
 | 
			
		||||
     * @param mixed $reasonPhrase
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterReasonPhrase($reasonPhrase = ''): string
 | 
			
		||||
    {
 | 
			
		||||
        if (is_object($reasonPhrase) && method_exists($reasonPhrase, '__toString')) {
 | 
			
		||||
            $reasonPhrase = (string) $reasonPhrase;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!is_string($reasonPhrase)) {
 | 
			
		||||
            throw new InvalidArgumentException('Response reason phrase must be a string.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (strpos($reasonPhrase, "\r") !== false || strpos($reasonPhrase, "\n") !== false) {
 | 
			
		||||
            throw new InvalidArgumentException(
 | 
			
		||||
                'Reason phrase contains one of the following prohibited characters: \r \n'
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $reasonPhrase;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										396
									
								
								qwen/php/vendor/slim/psr7/src/Stream.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										396
									
								
								qwen/php/vendor/slim/psr7/src/Stream.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,396 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
 | 
			
		||||
use function fclose;
 | 
			
		||||
use function feof;
 | 
			
		||||
use function fread;
 | 
			
		||||
use function fseek;
 | 
			
		||||
use function fstat;
 | 
			
		||||
use function ftell;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function is_array;
 | 
			
		||||
use function is_resource;
 | 
			
		||||
use function is_string;
 | 
			
		||||
use function pclose;
 | 
			
		||||
use function rewind;
 | 
			
		||||
use function stream_get_contents;
 | 
			
		||||
use function stream_get_meta_data;
 | 
			
		||||
use function strstr;
 | 
			
		||||
 | 
			
		||||
use const SEEK_SET;
 | 
			
		||||
 | 
			
		||||
class Stream implements StreamInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Bit mask to determine if the stream is a pipe
 | 
			
		||||
     *
 | 
			
		||||
     * This is octal as per header stat.h
 | 
			
		||||
     */
 | 
			
		||||
    public const FSTAT_MODE_S_IFIFO = 0010000;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The underlying stream resource
 | 
			
		||||
     *
 | 
			
		||||
     * @var resource|null
 | 
			
		||||
     */
 | 
			
		||||
    protected $stream;
 | 
			
		||||
 | 
			
		||||
    protected ?array $meta;
 | 
			
		||||
 | 
			
		||||
    protected ?bool $readable = null;
 | 
			
		||||
 | 
			
		||||
    protected ?bool $writable = null;
 | 
			
		||||
 | 
			
		||||
    protected ?bool $seekable = null;
 | 
			
		||||
 | 
			
		||||
    protected ?int $size = null;
 | 
			
		||||
 | 
			
		||||
    protected ?bool $isPipe = null;
 | 
			
		||||
 | 
			
		||||
    protected bool $finished = false;
 | 
			
		||||
 | 
			
		||||
    protected ?StreamInterface $cache;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param resource             $stream A PHP resource handle.
 | 
			
		||||
     * @param StreamInterface|null $cache  A stream to cache $stream (useful for non-seekable streams)
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException If argument is not a resource.
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct($stream, ?StreamInterface $cache = null)
 | 
			
		||||
    {
 | 
			
		||||
        $this->attach($stream);
 | 
			
		||||
 | 
			
		||||
        if ($cache && (!$cache->isSeekable() || !$cache->isWritable())) {
 | 
			
		||||
            throw new RuntimeException('Cache stream must be seekable and writable');
 | 
			
		||||
        }
 | 
			
		||||
        $this->cache = $cache;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return array|mixed
 | 
			
		||||
     */
 | 
			
		||||
    public function getMetadata($key = null)
 | 
			
		||||
    {
 | 
			
		||||
        if (!$this->stream) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->meta = stream_get_meta_data($this->stream);
 | 
			
		||||
 | 
			
		||||
        if (!$key) {
 | 
			
		||||
            return $this->meta;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->meta[$key] ?? null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Attach new resource to this object.
 | 
			
		||||
     *
 | 
			
		||||
     * @internal This method is not part of the PSR-7 standard.
 | 
			
		||||
     *
 | 
			
		||||
     * @param resource $stream A PHP resource handle.
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException If argument is not a valid PHP resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    protected function attach($stream): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_resource($stream)) {
 | 
			
		||||
            throw new InvalidArgumentException(__METHOD__ . ' argument must be a valid PHP resource');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($this->stream) {
 | 
			
		||||
            $this->detach();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->stream = $stream;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function detach()
 | 
			
		||||
    {
 | 
			
		||||
        $oldResource = $this->stream;
 | 
			
		||||
        $this->stream = null;
 | 
			
		||||
        $this->meta = null;
 | 
			
		||||
        $this->readable = null;
 | 
			
		||||
        $this->writable = null;
 | 
			
		||||
        $this->seekable = null;
 | 
			
		||||
        $this->size = null;
 | 
			
		||||
        $this->isPipe = null;
 | 
			
		||||
 | 
			
		||||
        $this->cache = null;
 | 
			
		||||
        $this->finished = false;
 | 
			
		||||
 | 
			
		||||
        return $oldResource;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function __toString(): string
 | 
			
		||||
    {
 | 
			
		||||
        if (!$this->stream) {
 | 
			
		||||
            return '';
 | 
			
		||||
        }
 | 
			
		||||
        if ($this->cache && $this->finished) {
 | 
			
		||||
            $this->cache->rewind();
 | 
			
		||||
            return $this->cache->getContents();
 | 
			
		||||
        }
 | 
			
		||||
        if ($this->isSeekable()) {
 | 
			
		||||
            $this->rewind();
 | 
			
		||||
        }
 | 
			
		||||
        return $this->getContents();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function close(): void
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->stream) {
 | 
			
		||||
            if ($this->isPipe()) {
 | 
			
		||||
                pclose($this->stream);
 | 
			
		||||
            } else {
 | 
			
		||||
                fclose($this->stream);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->detach();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getSize(): ?int
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->stream && !$this->size) {
 | 
			
		||||
            $stats = fstat($this->stream);
 | 
			
		||||
 | 
			
		||||
            if ($stats) {
 | 
			
		||||
                $this->size = !$this->isPipe() ? $stats['size'] : null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function tell(): int
 | 
			
		||||
    {
 | 
			
		||||
        $position = false;
 | 
			
		||||
 | 
			
		||||
        if ($this->stream) {
 | 
			
		||||
            $position = ftell($this->stream);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($position === false || $this->isPipe()) {
 | 
			
		||||
            throw new RuntimeException('Could not get the position of the pointer in stream.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $position;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function eof(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return !$this->stream || feof($this->stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function isReadable(): bool
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->readable !== null) {
 | 
			
		||||
            return $this->readable;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->readable = false;
 | 
			
		||||
 | 
			
		||||
        if ($this->stream) {
 | 
			
		||||
            $mode = $this->getMetadata('mode');
 | 
			
		||||
 | 
			
		||||
            if (is_string($mode) && (strstr($mode, 'r') !== false || strstr($mode, '+') !== false)) {
 | 
			
		||||
                $this->readable = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->readable;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function isWritable(): bool
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->writable === null) {
 | 
			
		||||
            $this->writable = false;
 | 
			
		||||
 | 
			
		||||
            if ($this->stream) {
 | 
			
		||||
                $mode = $this->getMetadata('mode');
 | 
			
		||||
 | 
			
		||||
                if (is_string($mode) && (strstr($mode, 'w') !== false || strstr($mode, '+') !== false)) {
 | 
			
		||||
                    $this->writable = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->writable;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function isSeekable(): bool
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->seekable === null) {
 | 
			
		||||
            $this->seekable = false;
 | 
			
		||||
 | 
			
		||||
            if ($this->stream) {
 | 
			
		||||
                $this->seekable = !$this->isPipe() && $this->getMetadata('seekable');
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->seekable;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function seek($offset, $whence = SEEK_SET): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!$this->isSeekable() || $this->stream && fseek($this->stream, $offset, $whence) === -1) {
 | 
			
		||||
            throw new RuntimeException('Could not seek in stream.');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function rewind(): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!$this->isSeekable() || $this->stream && rewind($this->stream) === false) {
 | 
			
		||||
            throw new RuntimeException('Could not rewind stream.');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function read($length): string
 | 
			
		||||
    {
 | 
			
		||||
        $data = false;
 | 
			
		||||
 | 
			
		||||
        if ($this->isReadable() && $this->stream && $length > 0) {
 | 
			
		||||
            $data = fread($this->stream, $length);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (is_string($data)) {
 | 
			
		||||
            if ($this->cache) {
 | 
			
		||||
                $this->cache->write($data);
 | 
			
		||||
            }
 | 
			
		||||
            if ($this->eof()) {
 | 
			
		||||
                $this->finished = true;
 | 
			
		||||
            }
 | 
			
		||||
            return $data;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        throw new RuntimeException('Could not read from stream.');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return int
 | 
			
		||||
     */
 | 
			
		||||
    public function write($string): int
 | 
			
		||||
    {
 | 
			
		||||
        $written = false;
 | 
			
		||||
 | 
			
		||||
        if ($this->isWritable() && $this->stream) {
 | 
			
		||||
            $written = fwrite($this->stream, $string);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($written !== false) {
 | 
			
		||||
            $this->size = null;
 | 
			
		||||
            return $written;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        throw new RuntimeException('Could not write to stream.');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getContents(): string
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->cache && $this->finished) {
 | 
			
		||||
            $this->cache->rewind();
 | 
			
		||||
            return $this->cache->getContents();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $contents = false;
 | 
			
		||||
 | 
			
		||||
        if ($this->stream) {
 | 
			
		||||
            $contents = stream_get_contents($this->stream);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (is_string($contents)) {
 | 
			
		||||
            if ($this->cache) {
 | 
			
		||||
                $this->cache->write($contents);
 | 
			
		||||
            }
 | 
			
		||||
            if ($this->eof()) {
 | 
			
		||||
                $this->finished = true;
 | 
			
		||||
            }
 | 
			
		||||
            return $contents;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        throw new RuntimeException('Could not get contents of stream.');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns whether or not the stream is a pipe.
 | 
			
		||||
     *
 | 
			
		||||
     * @internal This method is not part of the PSR-7 standard.
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function isPipe(): bool
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->isPipe === null) {
 | 
			
		||||
            $this->isPipe = false;
 | 
			
		||||
 | 
			
		||||
            if ($this->stream) {
 | 
			
		||||
                $stats = fstat($this->stream);
 | 
			
		||||
 | 
			
		||||
                if (is_array($stats)) {
 | 
			
		||||
                    $this->isPipe = ($stats['mode'] & self::FSTAT_MODE_S_IFIFO) !== 0;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->isPipe;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										279
									
								
								qwen/php/vendor/slim/psr7/src/UploadedFile.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										279
									
								
								qwen/php/vendor/slim/psr7/src/UploadedFile.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,279 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Psr\Http\Message\UploadedFileInterface;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
 | 
			
		||||
use function copy;
 | 
			
		||||
use function dirname;
 | 
			
		||||
use function is_array;
 | 
			
		||||
use function is_string;
 | 
			
		||||
use function is_uploaded_file;
 | 
			
		||||
use function is_writable;
 | 
			
		||||
use function move_uploaded_file;
 | 
			
		||||
use function rename;
 | 
			
		||||
use function sprintf;
 | 
			
		||||
use function strpos;
 | 
			
		||||
use function unlink;
 | 
			
		||||
 | 
			
		||||
use const UPLOAD_ERR_OK;
 | 
			
		||||
 | 
			
		||||
class UploadedFile implements UploadedFileInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The client-provided full path to the file
 | 
			
		||||
     */
 | 
			
		||||
    protected string $file;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The client-provided file name.
 | 
			
		||||
     */
 | 
			
		||||
    protected ?string $name;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The client-provided media type of the file.
 | 
			
		||||
     */
 | 
			
		||||
    protected ?string $type;
 | 
			
		||||
 | 
			
		||||
    protected ?int $size;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * A valid PHP UPLOAD_ERR_xxx code for the file upload.
 | 
			
		||||
     */
 | 
			
		||||
    protected int $error = UPLOAD_ERR_OK;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Indicates if the upload is from a SAPI environment.
 | 
			
		||||
     */
 | 
			
		||||
    protected bool $sapi = false;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var StreamInterface|null
 | 
			
		||||
     */
 | 
			
		||||
    protected $stream;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Indicates if the uploaded file has already been moved.
 | 
			
		||||
     */
 | 
			
		||||
    protected bool $moved = false;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string|StreamInterface $fileNameOrStream The full path to the uploaded file provided by the client,
 | 
			
		||||
     *                                                 or a StreamInterface instance.
 | 
			
		||||
     * @param string|null            $name             The file name.
 | 
			
		||||
     * @param string|null            $type             The file media type.
 | 
			
		||||
     * @param int|null               $size             The file size in bytes.
 | 
			
		||||
     * @param int                    $error            The UPLOAD_ERR_XXX code representing the status of the upload.
 | 
			
		||||
     * @param bool                   $sapi             Indicates if the upload is in a SAPI environment.
 | 
			
		||||
     */
 | 
			
		||||
    final public function __construct(
 | 
			
		||||
        $fileNameOrStream,
 | 
			
		||||
        ?string $name = null,
 | 
			
		||||
        ?string $type = null,
 | 
			
		||||
        ?int $size = null,
 | 
			
		||||
        int $error = UPLOAD_ERR_OK,
 | 
			
		||||
        bool $sapi = false
 | 
			
		||||
    ) {
 | 
			
		||||
        if ($fileNameOrStream instanceof StreamInterface) {
 | 
			
		||||
            $file = $fileNameOrStream->getMetadata('uri');
 | 
			
		||||
            if (!is_string($file)) {
 | 
			
		||||
                throw new InvalidArgumentException('No URI associated with the stream.');
 | 
			
		||||
            }
 | 
			
		||||
            $this->file = $file;
 | 
			
		||||
            $this->stream = $fileNameOrStream;
 | 
			
		||||
        } elseif (is_string($fileNameOrStream)) {
 | 
			
		||||
            $this->file = $fileNameOrStream;
 | 
			
		||||
        } else {
 | 
			
		||||
            throw new InvalidArgumentException(
 | 
			
		||||
                'Please provide a string (full path to the uploaded file) or an instance of StreamInterface.'
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        $this->name = $name;
 | 
			
		||||
        $this->type = $type;
 | 
			
		||||
        $this->size = $size;
 | 
			
		||||
        $this->error = $error;
 | 
			
		||||
        $this->sapi = $sapi;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return StreamInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function getStream(): StreamInterface
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->moved) {
 | 
			
		||||
            throw new RuntimeException(sprintf('Uploaded file %s has already been moved', $this->name));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!$this->stream) {
 | 
			
		||||
            $this->stream = (new StreamFactory())->createStreamFromFile($this->file);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->stream;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function moveTo($targetPath): void
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->moved) {
 | 
			
		||||
            throw new RuntimeException('Uploaded file already moved');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $targetIsStream = strpos($targetPath, '://') > 0;
 | 
			
		||||
        if (!$targetIsStream && !is_writable(dirname($targetPath))) {
 | 
			
		||||
            throw new InvalidArgumentException('Upload target path is not writable');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($targetIsStream) {
 | 
			
		||||
            if (!copy($this->file, $targetPath)) {
 | 
			
		||||
                throw new RuntimeException(sprintf('Error moving uploaded file %s to %s', $this->name, $targetPath));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!unlink($this->file)) {
 | 
			
		||||
                throw new RuntimeException(sprintf('Error removing uploaded file %s', $this->name));
 | 
			
		||||
            }
 | 
			
		||||
        } elseif ($this->sapi) {
 | 
			
		||||
            if (!is_uploaded_file($this->file)) {
 | 
			
		||||
                throw new RuntimeException(sprintf('%s is not a valid uploaded file', $this->file));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!move_uploaded_file($this->file, $targetPath)) {
 | 
			
		||||
                throw new RuntimeException(sprintf('Error moving uploaded file %s to %s', $this->name, $targetPath));
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            if (!rename($this->file, $targetPath)) {
 | 
			
		||||
                throw new RuntimeException(sprintf('Error moving uploaded file %s to %s', $this->name, $targetPath));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->moved = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getError(): int
 | 
			
		||||
    {
 | 
			
		||||
        return $this->error;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getClientFilename(): ?string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getClientMediaType(): ?string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getSize(): ?int
 | 
			
		||||
    {
 | 
			
		||||
        return $this->size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the client-provided full path to the file
 | 
			
		||||
     *
 | 
			
		||||
     * @internal This method is not part of the PSR-7 standard
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    public function getFilePath(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->file;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a normalized tree of UploadedFile instances from the Environment.
 | 
			
		||||
     *
 | 
			
		||||
     * @internal This method is not part of the PSR-7 standard.
 | 
			
		||||
     *
 | 
			
		||||
     * @param array $globals The global server variables.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array A normalized tree of UploadedFile instances or null if none are provided.
 | 
			
		||||
     */
 | 
			
		||||
    public static function createFromGlobals(array $globals): array
 | 
			
		||||
    {
 | 
			
		||||
        if (isset($globals['slim.files']) && is_array($globals['slim.files'])) {
 | 
			
		||||
            return $globals['slim.files'];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!empty($_FILES)) {
 | 
			
		||||
            return self::parseUploadedFiles($_FILES);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return [];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Parse a non-normalized, i.e. $_FILES superglobal, tree of uploaded file data.
 | 
			
		||||
     *
 | 
			
		||||
     * @internal This method is not part of the PSR-7 standard.
 | 
			
		||||
     *
 | 
			
		||||
     * @param array $uploadedFiles The non-normalized tree of uploaded file data.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array A normalized tree of UploadedFile instances.
 | 
			
		||||
     */
 | 
			
		||||
    private static function parseUploadedFiles(array $uploadedFiles): array
 | 
			
		||||
    {
 | 
			
		||||
        $parsed = [];
 | 
			
		||||
        foreach ($uploadedFiles as $field => $uploadedFile) {
 | 
			
		||||
            if (!isset($uploadedFile['error'])) {
 | 
			
		||||
                if (is_array($uploadedFile)) {
 | 
			
		||||
                    $parsed[$field] = self::parseUploadedFiles($uploadedFile);
 | 
			
		||||
                }
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $parsed[$field] = [];
 | 
			
		||||
            if (!is_array($uploadedFile['error'])) {
 | 
			
		||||
                $parsed[$field] = new static(
 | 
			
		||||
                    $uploadedFile['tmp_name'],
 | 
			
		||||
                    $uploadedFile['name'] ?? null,
 | 
			
		||||
                    $uploadedFile['type'] ?? null,
 | 
			
		||||
                    $uploadedFile['size'] ?? null,
 | 
			
		||||
                    $uploadedFile['error'],
 | 
			
		||||
                    true
 | 
			
		||||
                );
 | 
			
		||||
            } else {
 | 
			
		||||
                $subArray = [];
 | 
			
		||||
                foreach ($uploadedFile['error'] as $fileIdx => $error) {
 | 
			
		||||
                    // Normalize sub array and re-parse to move the input's key name up a level
 | 
			
		||||
                    $subArray[$fileIdx]['name'] = $uploadedFile['name'][$fileIdx];
 | 
			
		||||
                    $subArray[$fileIdx]['type'] = $uploadedFile['type'][$fileIdx];
 | 
			
		||||
                    $subArray[$fileIdx]['tmp_name'] = $uploadedFile['tmp_name'][$fileIdx];
 | 
			
		||||
                    $subArray[$fileIdx]['error'] = $uploadedFile['error'][$fileIdx];
 | 
			
		||||
                    $subArray[$fileIdx]['size'] = $uploadedFile['size'][$fileIdx];
 | 
			
		||||
 | 
			
		||||
                    $parsed[$field] = self::parseUploadedFiles($subArray);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $parsed;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										505
									
								
								qwen/php/vendor/slim/psr7/src/Uri.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										505
									
								
								qwen/php/vendor/slim/psr7/src/Uri.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,505 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
 | 
			
		||||
use function filter_var;
 | 
			
		||||
use function is_integer;
 | 
			
		||||
use function is_null;
 | 
			
		||||
use function is_object;
 | 
			
		||||
use function is_string;
 | 
			
		||||
use function ltrim;
 | 
			
		||||
use function method_exists;
 | 
			
		||||
use function preg_replace_callback;
 | 
			
		||||
use function rawurlencode;
 | 
			
		||||
use function str_replace;
 | 
			
		||||
use function str_starts_with;
 | 
			
		||||
use function strtolower;
 | 
			
		||||
 | 
			
		||||
use const FILTER_FLAG_IPV6;
 | 
			
		||||
use const FILTER_VALIDATE_IP;
 | 
			
		||||
 | 
			
		||||
class Uri implements UriInterface
 | 
			
		||||
{
 | 
			
		||||
    public const SUPPORTED_SCHEMES = [
 | 
			
		||||
        '' => null,
 | 
			
		||||
        'http' => 80,
 | 
			
		||||
        'https' => 443
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Uri scheme (without "://" suffix)
 | 
			
		||||
     */
 | 
			
		||||
    protected string $scheme = '';
 | 
			
		||||
 | 
			
		||||
    protected string $user = '';
 | 
			
		||||
 | 
			
		||||
    protected string $password = '';
 | 
			
		||||
 | 
			
		||||
    protected string $host = '';
 | 
			
		||||
 | 
			
		||||
    protected ?int $port;
 | 
			
		||||
 | 
			
		||||
    protected string $path = '';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Uri query string (without "?" prefix)
 | 
			
		||||
     */
 | 
			
		||||
    protected string $query = '';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Uri fragment string (without "#" prefix)
 | 
			
		||||
     */
 | 
			
		||||
    protected string $fragment = '';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string   $scheme   Uri scheme.
 | 
			
		||||
     * @param string   $host     Uri host.
 | 
			
		||||
     * @param int|null $port     Uri port number.
 | 
			
		||||
     * @param string   $path     Uri path.
 | 
			
		||||
     * @param string   $query    Uri query string.
 | 
			
		||||
     * @param string   $fragment Uri fragment.
 | 
			
		||||
     * @param string   $user     Uri user.
 | 
			
		||||
     * @param string   $password Uri password.
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(
 | 
			
		||||
        string $scheme,
 | 
			
		||||
        string $host,
 | 
			
		||||
        ?int $port = null,
 | 
			
		||||
        string $path = '/',
 | 
			
		||||
        string $query = '',
 | 
			
		||||
        string $fragment = '',
 | 
			
		||||
        string $user = '',
 | 
			
		||||
        string $password = ''
 | 
			
		||||
    ) {
 | 
			
		||||
        $this->scheme = $this->filterScheme($scheme);
 | 
			
		||||
        $this->host = $this->filterHost($host);
 | 
			
		||||
        $this->port = $this->filterPort($port);
 | 
			
		||||
        $this->path = $this->filterPath($path);
 | 
			
		||||
        $this->query = $this->filterQuery($query);
 | 
			
		||||
        $this->fragment = $this->filterFragment($fragment);
 | 
			
		||||
        $this->user = $this->filterUserInfo($user);
 | 
			
		||||
        $this->password = $this->filterUserInfo($password);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getScheme(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->scheme;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withScheme($scheme): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        $scheme = $this->filterScheme($scheme);
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->scheme = $scheme;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Filter Uri scheme.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  mixed $scheme Raw Uri scheme.
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException If the Uri scheme is not a string.
 | 
			
		||||
     * @throws InvalidArgumentException If Uri scheme is not exists in SUPPORTED_SCHEMES
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterScheme($scheme): string
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_string($scheme)) {
 | 
			
		||||
            throw new InvalidArgumentException('Uri scheme must be a string.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $scheme = str_replace('://', '', strtolower($scheme));
 | 
			
		||||
        if (!key_exists($scheme, static::SUPPORTED_SCHEMES)) {
 | 
			
		||||
            throw new InvalidArgumentException(
 | 
			
		||||
                'Uri scheme must be one of: "' . implode('", "', array_keys(static::SUPPORTED_SCHEMES)) . '"'
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $scheme;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getAuthority(): string
 | 
			
		||||
    {
 | 
			
		||||
        $userInfo = $this->getUserInfo();
 | 
			
		||||
        $host = $this->getHost();
 | 
			
		||||
        $port = $this->getPort();
 | 
			
		||||
 | 
			
		||||
        return ($userInfo !== '' ? $userInfo . '@' : '') . $host . ($port !== null ? ':' . $port : '');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getUserInfo(): string
 | 
			
		||||
    {
 | 
			
		||||
        $info = $this->user;
 | 
			
		||||
 | 
			
		||||
        if ($this->password !== '') {
 | 
			
		||||
            $info .= ':' . $this->password;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $info;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withUserInfo($user, $password = null): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->user = $this->filterUserInfo($user);
 | 
			
		||||
 | 
			
		||||
        if ($clone->user !== '') {
 | 
			
		||||
            $clone->password = $this->filterUserInfo($password);
 | 
			
		||||
        } else {
 | 
			
		||||
            $clone->password = '';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Filters the user info string.
 | 
			
		||||
     *
 | 
			
		||||
     * Returns the percent-encoded query string.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string|null $info The raw uri query string.
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterUserInfo(?string $info = null): string
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_string($info)) {
 | 
			
		||||
            return '';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $match =  preg_replace_callback(
 | 
			
		||||
            '/(?:[^%a-zA-Z0-9_\-\.~\pL!\$&\'\(\)\*\+,;=]+|%(?![A-Fa-f0-9]{2}))/',
 | 
			
		||||
            function ($match) {
 | 
			
		||||
                return rawurlencode($match[0]);
 | 
			
		||||
            },
 | 
			
		||||
            $info
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        return is_string($match) ? $match : '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getHost(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->host;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withHost($host): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->host = $this->filterHost($host);
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Filter Uri host.
 | 
			
		||||
     *
 | 
			
		||||
     * If the supplied host is an IPv6 address, then it is converted to a reference
 | 
			
		||||
     * as per RFC 2373.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  mixed $host The host to filter.
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException for invalid host names.
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterHost($host): string
 | 
			
		||||
    {
 | 
			
		||||
        if (is_object($host) && method_exists($host, '__toString')) {
 | 
			
		||||
            $host = (string) $host;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!is_string($host)) {
 | 
			
		||||
            throw new InvalidArgumentException('Uri host must be a string');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
 | 
			
		||||
            $host = '[' . $host . ']';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return strtolower($host);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getPort(): ?int
 | 
			
		||||
    {
 | 
			
		||||
        return $this->port && !$this->hasStandardPort() ? $this->port : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withPort($port): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        $port = $this->filterPort($port);
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->port = $port;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Does this Uri use a standard port?
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    protected function hasStandardPort(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return static::SUPPORTED_SCHEMES[$this->scheme] === $this->port;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Filter Uri port.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  int|string|null $port The Uri port number.
 | 
			
		||||
     *
 | 
			
		||||
     * @return int|null
 | 
			
		||||
     *
 | 
			
		||||
     * @throws InvalidArgumentException If the port is invalid.
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterPort($port): ?int
 | 
			
		||||
    {
 | 
			
		||||
        if (is_null($port)) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $port = (int) $port;
 | 
			
		||||
 | 
			
		||||
        if ($port >= 1 && $port <= 65535) {
 | 
			
		||||
            return $port;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        throw new InvalidArgumentException('Uri port must be null or an integer between 1 and 65535 (inclusive)');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getPath(): string
 | 
			
		||||
    {
 | 
			
		||||
        if (str_starts_with($this->path, '/')) {
 | 
			
		||||
            // Use only one leading slash to prevent XSS attempts.
 | 
			
		||||
            return '/' . ltrim($this->path, '/');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->path;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withPath($path): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_string($path)) {
 | 
			
		||||
            throw new InvalidArgumentException('Uri path must be a string');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->path = $this->filterPath($path);
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Filter Uri path.
 | 
			
		||||
     *
 | 
			
		||||
     * This method percent-encodes all reserved characters in the provided path string.
 | 
			
		||||
     * This method will NOT double-encode characters that are already percent-encoded.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  string $path The raw uri path.
 | 
			
		||||
     *
 | 
			
		||||
     * @return string       The RFC 3986 percent-encoded uri path.
 | 
			
		||||
     *
 | 
			
		||||
     * @link   http://www.faqs.org/rfcs/rfc3986.html
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterPath($path): string
 | 
			
		||||
    {
 | 
			
		||||
        $match = preg_replace_callback(
 | 
			
		||||
            '/(?:[^a-zA-Z0-9_\-\.~:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
 | 
			
		||||
            fn (array $match) => rawurlencode($match[0]),
 | 
			
		||||
            $path
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        return is_string($match) ? $match : '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getQuery(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->query;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withQuery($query): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        $query = ltrim($this->filterQuery($query), '?');
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->query = $query;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Filters the query string of a URI.
 | 
			
		||||
     *
 | 
			
		||||
     * Returns the percent-encoded query string.
 | 
			
		||||
     *
 | 
			
		||||
     * @param mixed $query The raw uri query string.
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterQuery($query): string
 | 
			
		||||
    {
 | 
			
		||||
        if (is_object($query) && method_exists($query, '__toString')) {
 | 
			
		||||
            $query = (string) $query;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!is_string($query)) {
 | 
			
		||||
            throw new InvalidArgumentException('Uri query must be a string.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $match = preg_replace_callback(
 | 
			
		||||
            '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
 | 
			
		||||
            function ($match) {
 | 
			
		||||
                return rawurlencode($match[0]);
 | 
			
		||||
            },
 | 
			
		||||
            $query
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        return is_string($match) ? $match : '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function getFragment(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->fragment;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     * @return static
 | 
			
		||||
     */
 | 
			
		||||
    public function withFragment($fragment): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        $fragment = $this->filterFragment($fragment);
 | 
			
		||||
        $clone = clone $this;
 | 
			
		||||
        $clone->fragment = $fragment;
 | 
			
		||||
 | 
			
		||||
        return $clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Filters fragment of a URI.
 | 
			
		||||
     *
 | 
			
		||||
     * Returns the percent-encoded fragment.
 | 
			
		||||
     *
 | 
			
		||||
     * @param mixed $fragment The raw uri query string.
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    protected function filterFragment($fragment): string
 | 
			
		||||
    {
 | 
			
		||||
        if (is_object($fragment) && method_exists($fragment, '__toString')) {
 | 
			
		||||
            $fragment = (string) $fragment;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!is_string($fragment)) {
 | 
			
		||||
            throw new InvalidArgumentException('Uri fragment must be a string.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $fragment = ltrim($fragment, '#');
 | 
			
		||||
 | 
			
		||||
        $match = preg_replace_callback(
 | 
			
		||||
            '/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
 | 
			
		||||
            function ($match) {
 | 
			
		||||
                return rawurlencode($match[0]);
 | 
			
		||||
            },
 | 
			
		||||
            $fragment
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        return is_string($match) ? $match : '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
    public function __toString(): string
 | 
			
		||||
    {
 | 
			
		||||
        $scheme = $this->getScheme();
 | 
			
		||||
        $authority = $this->getAuthority();
 | 
			
		||||
        $path = $this->path;
 | 
			
		||||
        $query = $this->getQuery();
 | 
			
		||||
        $fragment = $this->getFragment();
 | 
			
		||||
 | 
			
		||||
        if ($path !== '') {
 | 
			
		||||
            if ($path[0] !== '/') {
 | 
			
		||||
                if ($authority !== '') {
 | 
			
		||||
                    // If the path is rootless and an authority is present, the path MUST be prefixed by "/".
 | 
			
		||||
                    $path = '/' . $path;
 | 
			
		||||
                }
 | 
			
		||||
            } elseif (isset($path[1]) && $path[1] === '/') {
 | 
			
		||||
                if ($authority === '') {
 | 
			
		||||
                    // If the path is starting with more than one "/" and no authority is present,
 | 
			
		||||
                    // the starting slashes MUST be reduced to one.
 | 
			
		||||
                    $path = ltrim($path, '/');
 | 
			
		||||
                    $path = '/' . $path;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ($scheme !== '' ? $scheme . ':' : '')
 | 
			
		||||
            . ($authority !== '' ? '//' . $authority : '')
 | 
			
		||||
            . $path
 | 
			
		||||
            . ($query !== '' ? '?' . $query : '')
 | 
			
		||||
            . ($fragment !== '' ? '#' . $fragment : '');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										95
									
								
								qwen/php/vendor/slim/psr7/tests/Assets/HeaderStack.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								qwen/php/vendor/slim/psr7/tests/Assets/HeaderStack.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,95 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This is a direct copy of zend-diactoros/test/TestAsset/Functions.php and is used to override
 | 
			
		||||
 * header() and headers_sent() so we can test that they do the right thing.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Assets;
 | 
			
		||||
 | 
			
		||||
use function strpos;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Zend Framework (http://framework.zend.com/)
 | 
			
		||||
 *
 | 
			
		||||
 * This file exists to allow overriding the various output-related functions
 | 
			
		||||
 * in order to test what happens during the `Server::listen()` cycle.
 | 
			
		||||
 *
 | 
			
		||||
 * These functions include:
 | 
			
		||||
 *
 | 
			
		||||
 * - headers_sent(): we want to always return false so that headers will be
 | 
			
		||||
 *   emitted, and we can test to see their values.
 | 
			
		||||
 * - header(): we want to aggregate calls to this function.
 | 
			
		||||
 *
 | 
			
		||||
 * The HeaderStack class then aggregates that information for us, and the test
 | 
			
		||||
 * harness resets the values pre and post test.
 | 
			
		||||
 *
 | 
			
		||||
 * @see       http://github.com/zendframework/zend-diactoros for the canonical source repository
 | 
			
		||||
 * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
 | 
			
		||||
 * @license   https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class HeaderStack
 | 
			
		||||
{
 | 
			
		||||
    private static array $data = [];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Reset state
 | 
			
		||||
     */
 | 
			
		||||
    public static function reset()
 | 
			
		||||
    {
 | 
			
		||||
        self::$data = [];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Push a header on the stack
 | 
			
		||||
     *
 | 
			
		||||
     * @param string[] $header
 | 
			
		||||
     */
 | 
			
		||||
    public static function push(array $header)
 | 
			
		||||
    {
 | 
			
		||||
        self::$data[] = $header;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Return the current header stack
 | 
			
		||||
     *
 | 
			
		||||
     * @return string[][]
 | 
			
		||||
     */
 | 
			
		||||
    public static function stack(): array
 | 
			
		||||
    {
 | 
			
		||||
        return self::$data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Verify if there's a header line on the stack
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $header
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public static function has($header): bool
 | 
			
		||||
    {
 | 
			
		||||
        foreach (self::$data as $item) {
 | 
			
		||||
            if ($item['header'] === $header) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remove occurrences of $header
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $header
 | 
			
		||||
     */
 | 
			
		||||
    public static function remove($header): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (self::$data as $key => $item) {
 | 
			
		||||
            if (false !== strpos($item['header'], "$header:")) {
 | 
			
		||||
                unset(self::$data[$key]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										422
									
								
								qwen/php/vendor/slim/psr7/tests/BodyTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										422
									
								
								qwen/php/vendor/slim/psr7/tests/BodyTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,422 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
 | 
			
		||||
use function fclose;
 | 
			
		||||
use function feof;
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fread;
 | 
			
		||||
use function fseek;
 | 
			
		||||
use function ftell;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function is_array;
 | 
			
		||||
use function is_resource;
 | 
			
		||||
use function mb_strlen;
 | 
			
		||||
use function rewind;
 | 
			
		||||
use function substr;
 | 
			
		||||
 | 
			
		||||
class BodyTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    // @codingStandardsIgnoreStart
 | 
			
		||||
    protected string $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
 | 
			
		||||
    // @codingStandardsIgnoreEnd
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var resource
 | 
			
		||||
     */
 | 
			
		||||
    protected $stream;
 | 
			
		||||
 | 
			
		||||
    protected function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        if (is_resource($this->stream) === true) {
 | 
			
		||||
            fclose($this->stream);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $mode
 | 
			
		||||
     *
 | 
			
		||||
     * @return resource
 | 
			
		||||
     */
 | 
			
		||||
    public function resourceFactory(string $mode = 'r+')
 | 
			
		||||
    {
 | 
			
		||||
        $stream = fopen('php://temp', $mode);
 | 
			
		||||
        fwrite($stream, $this->text);
 | 
			
		||||
        rewind($stream);
 | 
			
		||||
 | 
			
		||||
        return $stream;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructorAttachesStream()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($this->stream, $bodyStream->getValue($body));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructorInvalidStream()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = 'foo';
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMetadata()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue(is_array($body->getMetadata()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMetadataKey()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('php://temp', $body->getMetadata('uri'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMetadataKeyNotFound()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($body->getMetadata('foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDetach()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyMetadata = new ReflectionProperty($body, 'meta');
 | 
			
		||||
        $bodyMetadata->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyReadable = new ReflectionProperty($body, 'readable');
 | 
			
		||||
        $bodyReadable->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyWritable = new ReflectionProperty($body, 'writable');
 | 
			
		||||
        $bodyWritable->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodySeekable = new ReflectionProperty($body, 'seekable');
 | 
			
		||||
        $bodySeekable->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $result = $body->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($this->stream, $result);
 | 
			
		||||
        $this->assertNull($bodyStream->getValue($body));
 | 
			
		||||
        $this->assertNull($bodyMetadata->getValue($body));
 | 
			
		||||
        $this->assertNull($bodyReadable->getValue($body));
 | 
			
		||||
        $this->assertNull($bodyWritable->getValue($body));
 | 
			
		||||
        $this->assertNull($bodySeekable->getValue($body));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToStringAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($this->text, (string) $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToStringAttachedRewindsFirst()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($this->text, (string) $body);
 | 
			
		||||
        $this->assertEquals($this->text, (string) $body);
 | 
			
		||||
        $this->assertEquals($this->text, (string) $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToStringDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
        $bodyStream->setValue($body, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', (string) $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testClose()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->close();
 | 
			
		||||
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($bodyStream->getValue($body));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetSizeAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(mb_strlen($this->text), $body->getSize());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetSizeDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
        $bodyStream->setValue($body, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($body->getSize());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testTellAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        fseek($this->stream, 10);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(10, $body->tell());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testTellDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
        $bodyStream->setValue($body, null);
 | 
			
		||||
 | 
			
		||||
        $body->tell();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testEofAttachedFalse()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        fseek($this->stream, 10);
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->eof());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testEofAttachedTrue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        while (feof($this->stream) === false) {
 | 
			
		||||
            fread($this->stream, 1024);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->eof());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testEofDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $bodyStream = new ReflectionProperty($body, 'stream');
 | 
			
		||||
        $bodyStream->setAccessible(true);
 | 
			
		||||
        $bodyStream->setValue($body, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->eof());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isReadableAttachedTrue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->isReadable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isReadableAttachedFalse()
 | 
			
		||||
    {
 | 
			
		||||
        $stream = fopen('php://temp', 'w');
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isReadable());
 | 
			
		||||
        fclose($stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsReadableDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isReadable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isWritableAttachedTrue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->isWritable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isWritableAttachedFalse()
 | 
			
		||||
    {
 | 
			
		||||
        $stream = fopen('php://temp', 'r');
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isWritable());
 | 
			
		||||
        fclose($stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsWritableDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isWritable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function isSeekableAttachedTrue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($body->isSeekable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: Is seekable is false when attached... how?
 | 
			
		||||
 | 
			
		||||
    public function testIsSeekableDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($body->isSeekable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSeekAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->seek(10);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(10, ftell($this->stream));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSeekDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->seek(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRewindAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        fseek($this->stream, 10);
 | 
			
		||||
        $body->rewind();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(0, ftell($this->stream));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRewindDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->rewind();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReadAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(substr($this->text, 0, 10), $body->read(10));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReadDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->read(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWriteAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        while (feof($this->stream) === false) {
 | 
			
		||||
            fread($this->stream, 1024);
 | 
			
		||||
        }
 | 
			
		||||
        $body->write('foo');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($this->text . 'foo', (string) $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWriteDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->write('foo');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetContentsAttached()
 | 
			
		||||
    {
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        fseek($this->stream, 10);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(substr($this->text, 10), $body->getContents());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetContentsDetachedThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->stream = $this->resourceFactory();
 | 
			
		||||
        $body = new Stream($this->stream);
 | 
			
		||||
        $body->detach();
 | 
			
		||||
 | 
			
		||||
        $body->getContents();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										283
									
								
								qwen/php/vendor/slim/psr7/tests/CookiesTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										283
									
								
								qwen/php/vendor/slim/psr7/tests/CookiesTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,283 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use ReflectionClass;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use Slim\Psr7\Cookies;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
use function gmdate;
 | 
			
		||||
use function json_decode;
 | 
			
		||||
use function strtotime;
 | 
			
		||||
use function time;
 | 
			
		||||
 | 
			
		||||
class CookiesTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testConstructor()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies([
 | 
			
		||||
            'test' => 'Works',
 | 
			
		||||
        ]);
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'requestCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $this->assertNotEmpty($prop->getValue($cookies)['test']);
 | 
			
		||||
        $this->assertEquals('Works', $prop->getValue($cookies)['test']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetDefaults()
 | 
			
		||||
    {
 | 
			
		||||
        $defaults = [
 | 
			
		||||
            'value' => 'toast',
 | 
			
		||||
            'domain' => null,
 | 
			
		||||
            'hostonly' => null,
 | 
			
		||||
            'path' => null,
 | 
			
		||||
            'expires' => null,
 | 
			
		||||
            'secure' => true,
 | 
			
		||||
            'httponly' => true,
 | 
			
		||||
            'samesite' => null
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'defaults');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $origDefaults = $prop->getValue($cookies);
 | 
			
		||||
 | 
			
		||||
        $cookies->setDefaults($defaults);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($defaults, $prop->getValue($cookies));
 | 
			
		||||
        $this->assertNotEquals($origDefaults, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetCookieValues()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $cookies->set('foo', 'bar');
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'responseCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $expectedValue = [
 | 
			
		||||
            'foo' => [
 | 
			
		||||
                'value' => 'bar',
 | 
			
		||||
                'domain' => null,
 | 
			
		||||
                'hostonly' => null,
 | 
			
		||||
                'path' => null,
 | 
			
		||||
                'expires' => null,
 | 
			
		||||
                'secure' => false,
 | 
			
		||||
                'httponly' => false,
 | 
			
		||||
                'samesite' => null
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedValue, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetCookieValuesContainDefaults()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $defaults = [
 | 
			
		||||
            'value' => 'toast',
 | 
			
		||||
            'domain' => null,
 | 
			
		||||
            'hostonly' => null,
 | 
			
		||||
            'path' => null,
 | 
			
		||||
            'expires' => null,
 | 
			
		||||
            'secure' => true,
 | 
			
		||||
            'httponly' => true,
 | 
			
		||||
            'samesite' => 'lax'
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $cookies->setDefaults($defaults);
 | 
			
		||||
        $cookies->set('foo', 'bar');
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'responseCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $expectedValue = [
 | 
			
		||||
            'foo' => [
 | 
			
		||||
                'value' => 'bar',
 | 
			
		||||
                'domain' => null,
 | 
			
		||||
                'hostonly' => null,
 | 
			
		||||
                'path' => null,
 | 
			
		||||
                'expires' => null,
 | 
			
		||||
                'secure' => true,
 | 
			
		||||
                'httponly' => true,
 | 
			
		||||
                'samesite' => 'lax'
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedValue, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetCookieValuesCanOverrideDefaults()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $defaults = [
 | 
			
		||||
            'value' => 'toast',
 | 
			
		||||
            'domain' => null,
 | 
			
		||||
            'hostonly' => null,
 | 
			
		||||
            'path' => null,
 | 
			
		||||
            'expires' => null,
 | 
			
		||||
            'secure' => true,
 | 
			
		||||
            'httponly' => true,
 | 
			
		||||
            'samesite' => 'lax'
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $cookies->setDefaults($defaults);
 | 
			
		||||
        $cookies->set('foo', ['value' => 'bar', 'secure' => false, 'samesite' => 'strict']);
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'responseCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $expectedValue = [
 | 
			
		||||
            'foo' => [
 | 
			
		||||
                'value' => 'bar',
 | 
			
		||||
                'domain' => null,
 | 
			
		||||
                'hostonly' => null,
 | 
			
		||||
                'path' => null,
 | 
			
		||||
                'expires' => null,
 | 
			
		||||
                'secure' => false,
 | 
			
		||||
                'httponly' => true,
 | 
			
		||||
                'samesite' => 'strict'
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedValue, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetSameSiteCookieValuesAreCaseInsensitive()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $defaults = [
 | 
			
		||||
            'value' => 'bacon',
 | 
			
		||||
            'samesite' => 'lax'
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $cookies->setDefaults($defaults);
 | 
			
		||||
        $cookies->set('breakfast', ['samesite' => 'StricT']);
 | 
			
		||||
 | 
			
		||||
        $prop = new ReflectionProperty($cookies, 'responseCookies');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $expectedValue = [
 | 
			
		||||
            'breakfast' => [
 | 
			
		||||
                'value' => 'bacon',
 | 
			
		||||
                'domain' => null,
 | 
			
		||||
                'hostonly' => null,
 | 
			
		||||
                'path' => null,
 | 
			
		||||
                'expires' => null,
 | 
			
		||||
                'secure' => false,
 | 
			
		||||
                'httponly' => false,
 | 
			
		||||
                'samesite' => 'StricT',
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedValue, $prop->getValue($cookies));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGet()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies(['foo' => 'bar', 'baz' => null]);
 | 
			
		||||
        $this->assertEquals('bar', $cookies->get('foo'));
 | 
			
		||||
        $this->assertNull($cookies->get('baz', 'defaultValue'));
 | 
			
		||||
        $this->assertNull($cookies->get('missing'));
 | 
			
		||||
        $this->assertEquals('defaultValue', $cookies->get('missing', 'defaultValue'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParseHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = Cookies::parseHeader('foo=bar; name=Josh');
 | 
			
		||||
        $this->assertEquals('bar', $cookies['foo']);
 | 
			
		||||
        $this->assertEquals('Josh', $cookies['name']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParseHeaderWithJsonArray()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = Cookies::parseHeader('foo=bar; testarray=["someVar1","someVar2","someVar3"]');
 | 
			
		||||
        $this->assertEquals('bar', $cookies['foo']);
 | 
			
		||||
        $this->assertContains('someVar3', json_decode($cookies['testarray']));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $cookies->set('test', 'Works');
 | 
			
		||||
        $cookies->set('test_array', ['value' => 'bar', 'domain' => 'example.com']);
 | 
			
		||||
        $this->assertEquals('test=Works', $cookies->toHeaders()[0]);
 | 
			
		||||
        $this->assertEquals('test_array=bar; domain=example.com', $cookies->toHeaders()[1]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $class = new ReflectionClass($cookies);
 | 
			
		||||
        $method = $class->getMethod('toHeader');
 | 
			
		||||
        $method->setAccessible(true);
 | 
			
		||||
        $properties = [
 | 
			
		||||
            'name' => 'test',
 | 
			
		||||
            'properties' => [
 | 
			
		||||
                'value' => 'Works'
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
        $time = time();
 | 
			
		||||
        $formattedDate = gmdate('D, d-M-Y H:i:s e', $time);
 | 
			
		||||
        $propertiesComplex = [
 | 
			
		||||
            'name' => 'test_complex',
 | 
			
		||||
            'properties' => [
 | 
			
		||||
                'value' => 'Works',
 | 
			
		||||
                'domain' => 'example.com',
 | 
			
		||||
                'expires' => $time,
 | 
			
		||||
                'path' => '/',
 | 
			
		||||
                'secure' => true,
 | 
			
		||||
                'hostonly' => true,
 | 
			
		||||
                'httponly' => true,
 | 
			
		||||
                'samesite' => 'lax'
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
        $stringDate = '2016-01-01 12:00:00';
 | 
			
		||||
        $formattedStringDate = gmdate('D, d-M-Y H:i:s e', strtotime($stringDate));
 | 
			
		||||
        $propertiesStringDate = [
 | 
			
		||||
            'name' => 'test_date',
 | 
			
		||||
            'properties' => [
 | 
			
		||||
                'value' => 'Works',
 | 
			
		||||
                'expires' => $stringDate,
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
        $cookie = $method->invokeArgs($cookies, $properties);
 | 
			
		||||
        $cookieComplex = $method->invokeArgs($cookies, $propertiesComplex);
 | 
			
		||||
        $cookieStringDate = $method->invokeArgs($cookies, $propertiesStringDate);
 | 
			
		||||
        $this->assertEquals('test=Works', $cookie);
 | 
			
		||||
        $this->assertEquals(
 | 
			
		||||
            'test_complex=Works; domain=example.com; path=/; expires='
 | 
			
		||||
            . $formattedDate . '; secure; HostOnly; HttpOnly; SameSite=lax',
 | 
			
		||||
            $cookieComplex
 | 
			
		||||
        );
 | 
			
		||||
        $this->assertEquals('test_date=Works; expires=' . $formattedStringDate, $cookieStringDate);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParseHeaderException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        Cookies::parseHeader(new stdClass());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetSameSiteNoneToHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $cookies = new Cookies();
 | 
			
		||||
        $cookies->set('foo', ['value' => 'bar', 'samesite' => 'None']);
 | 
			
		||||
        $this->assertEquals('foo=bar; SameSite=None', $cookies->toHeaders()[0]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										48
									
								
								qwen/php/vendor/slim/psr7/tests/EnvironmentTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								qwen/php/vendor/slim/psr7/tests/EnvironmentTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
 | 
			
		||||
class EnvironmentTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testMock()
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/foo/bar/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar?abc=123',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/foo/bar/index.php', $env['SCRIPT_NAME']);
 | 
			
		||||
        $this->assertEquals('/foo/bar?abc=123', $env['REQUEST_URI']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMockHttps()
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock([
 | 
			
		||||
            'HTTPS' => 'on'
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('on', $env['HTTPS']);
 | 
			
		||||
        $this->assertEquals(443, $env['SERVER_PORT']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMockRequestScheme()
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock([
 | 
			
		||||
            'REQUEST_SCHEME' => 'https'
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('https', $env['REQUEST_SCHEME']);
 | 
			
		||||
        $this->assertEquals(443, $env['SERVER_PORT']);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/RequestFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/RequestFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use Interop\Http\Factory\RequestFactoryTestCase;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Factory\RequestFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
class RequestFactoryTest extends RequestFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function createRequestFactory(): RequestFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new RequestFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createUri($uri): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        return (new UriFactory())->createUri($uri);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateRequestThrowsExceptionWithInvalidUri()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Parameter 2 of RequestFactory::createRequest() must be a string' .
 | 
			
		||||
                                      ' or a compatible UriInterface.');
 | 
			
		||||
 | 
			
		||||
        $factory = $this->createRequestFactory();
 | 
			
		||||
 | 
			
		||||
        $factory->createRequest('GET', new stdClass());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/ResponseFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/ResponseFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use Interop\Http\Factory\ResponseFactoryTestCase;
 | 
			
		||||
use Psr\Http\Message\ResponseInterface;
 | 
			
		||||
use Slim\Psr7\Factory\ResponseFactory;
 | 
			
		||||
 | 
			
		||||
class ResponseFactoryTest extends ResponseFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function createResponseFactory(): ResponseFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new ResponseFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function assertResponseCodeAndReasonPhrase(ResponseInterface $response, int $code, string $reasonPhrase)
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertInstanceOf(ResponseInterface::class, $response);
 | 
			
		||||
        $this->assertSame($code, $response->getStatusCode());
 | 
			
		||||
        $this->assertSame($reasonPhrase, $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider dataCodes
 | 
			
		||||
     *
 | 
			
		||||
     * @param int $code
 | 
			
		||||
     */
 | 
			
		||||
    public function testCreateResponseWithReasonPhrase(int $code)
 | 
			
		||||
    {
 | 
			
		||||
        $response = $this->factory->createResponse($code, 'Reason');
 | 
			
		||||
        $this->assertResponse($response, $code);
 | 
			
		||||
        $this->assertResponseCodeAndReasonPhrase($response, $code, 'Reason');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										208
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/ServerRequestFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										208
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/ServerRequestFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,208 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use Interop\Http\Factory\ServerRequestFactoryTestCase;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use ReflectionClass;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Factory\ServerRequestFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
use function microtime;
 | 
			
		||||
use function time;
 | 
			
		||||
 | 
			
		||||
class ServerRequestFactoryTest extends ServerRequestFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function createServerRequestFactory(): ServerRequestFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new ServerRequestFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createUri($uri): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        return (new UriFactory())->createUri($uri);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetProtocolVersion()
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock(['SERVER_PROTOCOL' => 'HTTP/1.0']);
 | 
			
		||||
        $request = $this->createServerRequestFactory()->createServerRequest('GET', '', $env);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('1.0', $request->getProtocolVersion());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobals()
 | 
			
		||||
    {
 | 
			
		||||
        $GLOBALS['getallheaders_return'] = [
 | 
			
		||||
            'ACCEPT' => 'application/json',
 | 
			
		||||
            'ACCEPT-CHARSET' => 'utf-8',
 | 
			
		||||
            'ACCEPT-LANGUAGE' => 'en-US',
 | 
			
		||||
            'CONTENT-TYPE' => 'multipart/form-data',
 | 
			
		||||
            'HOST' => 'example.com',
 | 
			
		||||
            'USER-AGENT' => 'Slim Framework',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $_SERVER = Environment::mock([
 | 
			
		||||
            'HTTP_HOST' => 'example.com',
 | 
			
		||||
            'PHP_AUTH_PW' => 'sekrit',
 | 
			
		||||
            'PHP_AUTH_USER' => 'josh',
 | 
			
		||||
            'QUERY_STRING' => 'abc=123',
 | 
			
		||||
            'REMOTE_ADDR' => '127.0.0.1',
 | 
			
		||||
            'REQUEST_METHOD' => 'GET',
 | 
			
		||||
            'REQUEST_TIME' => time(),
 | 
			
		||||
            'REQUEST_TIME_FLOAT' => microtime(true),
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar',
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'SERVER_NAME' => 'localhost',
 | 
			
		||||
            'SERVER_PORT' => 8080,
 | 
			
		||||
            'SERVER_PROTOCOL' => 'HTTP/1.1',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        unset($GLOBALS['getallheaders_return']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('GET', $request->getMethod());
 | 
			
		||||
        $this->assertEquals('1.1', $request->getProtocolVersion());
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('application/json', $request->getHeaderLine('Accept'));
 | 
			
		||||
        $this->assertEquals('utf-8', $request->getHeaderLine('Accept-Charset'));
 | 
			
		||||
        $this->assertEquals('en-US', $request->getHeaderLine('Accept-Language'));
 | 
			
		||||
        $this->assertEquals('multipart/form-data', $request->getHeaderLine('Content-Type'));
 | 
			
		||||
 | 
			
		||||
        $uri = $request->getUri();
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithParsedBody()
 | 
			
		||||
    {
 | 
			
		||||
        $_SERVER = Environment::mock([
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'multipart/form-data',
 | 
			
		||||
            'REQUEST_METHOD' => 'POST',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $_POST = [
 | 
			
		||||
            'def' => '456',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        // $_POST should be placed into the parsed body
 | 
			
		||||
        $this->assertEquals($_POST, $request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsBodyPointsToPhpInput()
 | 
			
		||||
    {
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('php://input', $request->getBody()->getMetadata('uri'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsSetsACache()
 | 
			
		||||
    {
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        // ensure that the Stream's $cache property has been set for this php://input stream
 | 
			
		||||
        $stream = $request->getBody();
 | 
			
		||||
        $class = new ReflectionClass($stream);
 | 
			
		||||
        $property = $class->getProperty('cache');
 | 
			
		||||
        $property->setAccessible(true);
 | 
			
		||||
        $cacheStreamValue = $property->getValue($stream);
 | 
			
		||||
        $this->assertNotNull($cacheStreamValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithUploadedFiles()
 | 
			
		||||
    {
 | 
			
		||||
        $_SERVER = Environment::mock([
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'multipart/form-data',
 | 
			
		||||
            'REQUEST_METHOD' => 'POST',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $_FILES = [
 | 
			
		||||
            'uploaded_file' => [
 | 
			
		||||
                'name' => [
 | 
			
		||||
                    0 => 'foo.jpg',
 | 
			
		||||
                    1 => 'bar.jpg',
 | 
			
		||||
                ],
 | 
			
		||||
 | 
			
		||||
                'type' => [
 | 
			
		||||
                    0 => 'image/jpeg',
 | 
			
		||||
                    1 => 'image/jpeg',
 | 
			
		||||
                ],
 | 
			
		||||
 | 
			
		||||
                'tmp_name' => [
 | 
			
		||||
                    0 => '/tmp/phpUA3XUw',
 | 
			
		||||
                    1 => '/tmp/phpXUFS0x',
 | 
			
		||||
                ],
 | 
			
		||||
 | 
			
		||||
                'error' => [
 | 
			
		||||
                    0 => 0,
 | 
			
		||||
                    1 => 0,
 | 
			
		||||
                ],
 | 
			
		||||
 | 
			
		||||
                'size' => [
 | 
			
		||||
                    0 => 358708,
 | 
			
		||||
                    1 => 236162,
 | 
			
		||||
                ],
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        // $_FILES should be mapped to an array of UploadedFile objects
 | 
			
		||||
        $uploadedFiles = $request->getUploadedFiles();
 | 
			
		||||
        $this->assertCount(1, $uploadedFiles);
 | 
			
		||||
        $this->assertArrayHasKey('uploaded_file', $uploadedFiles);
 | 
			
		||||
        $this->assertInstanceOf(UploadedFile::class, $uploadedFiles['uploaded_file'][0]);
 | 
			
		||||
        $this->assertInstanceOf(UploadedFile::class, $uploadedFiles['uploaded_file'][1]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsParsesBodyWithFragmentedContentType()
 | 
			
		||||
    {
 | 
			
		||||
        $_SERVER = Environment::mock([
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded;charset=utf-8',
 | 
			
		||||
            'REQUEST_METHOD' => 'POST',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $_POST = [
 | 
			
		||||
            'def' => '456',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $request = ServerRequestFactory::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($_POST, $request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateServerRequestWithNullAsUri()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $env = Environment::mock();
 | 
			
		||||
        $this->createServerRequestFactory()->createServerRequest('GET', null, $env);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateServerRequestWithInvalidUriObject()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $env = Environment::mock();
 | 
			
		||||
        $this->createServerRequestFactory()->createServerRequest('GET', new stdClass(), $env);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										66
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/StreamFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/StreamFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use Interop\Http\Factory\StreamFactoryTestCase;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
 | 
			
		||||
class StreamFactoryTest extends StreamFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    public function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        if (isset($GLOBALS['fopen_return'])) {
 | 
			
		||||
            unset($GLOBALS['fopen_return']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createStreamFactory(): StreamFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new StreamFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateStreamThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('StreamFactory::createStream() could not open temporary file stream.');
 | 
			
		||||
 | 
			
		||||
        $GLOBALS['fopen_return'] = false;
 | 
			
		||||
 | 
			
		||||
        $factory = $this->createStreamFactory();
 | 
			
		||||
 | 
			
		||||
        $factory->createStream();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateStreamFromFileThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('StreamFactory::createStreamFromFile() could not create resource'
 | 
			
		||||
                                      . ' from file `non-readable`');
 | 
			
		||||
 | 
			
		||||
        $GLOBALS['fopen_return'] = false;
 | 
			
		||||
 | 
			
		||||
        $factory = $this->createStreamFactory();
 | 
			
		||||
 | 
			
		||||
        $factory->createStreamFromFile('non-readable');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateStreamFromResourceThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Parameter 1 of StreamFactory::createStreamFromResource() must be a resource.');
 | 
			
		||||
 | 
			
		||||
        $factory = $this->createStreamFactory();
 | 
			
		||||
 | 
			
		||||
        $factory->createStreamFromResource('not-resource');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										114
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/UploadedFileFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/UploadedFileFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,114 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use Interop\Http\Factory\UploadedFileFactoryTestCase;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Prophecy\PhpUnit\ProphecyTrait;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UploadedFileFactory;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function rewind;
 | 
			
		||||
use function sys_get_temp_dir;
 | 
			
		||||
use function tempnam;
 | 
			
		||||
 | 
			
		||||
class UploadedFileFactoryTest extends UploadedFileFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    use ProphecyTrait;
 | 
			
		||||
 | 
			
		||||
    protected function createUploadedFileFactory(): UploadedFileFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new UploadedFileFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createStream($content): StreamInterface
 | 
			
		||||
    {
 | 
			
		||||
        $file = tempnam(sys_get_temp_dir(), 'Slim_Http_UploadedFileTest_');
 | 
			
		||||
        $resource = fopen($file, 'r+');
 | 
			
		||||
        fwrite($resource, $content);
 | 
			
		||||
        rewind($resource);
 | 
			
		||||
 | 
			
		||||
        return (new StreamFactory())->createStreamFromResource($resource);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Prophesize a `\Psr\Http\Message\StreamInterface` with a `getMetadata` method prophecy.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $argKey Argument for the method prophecy.
 | 
			
		||||
     * @param mixed $returnValue Return value of the `getMetadata` method.
 | 
			
		||||
     *
 | 
			
		||||
     * @return StreamInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected function prophesizeStreamInterfaceWithGetMetadataMethod(string $argKey, $returnValue): StreamInterface
 | 
			
		||||
    {
 | 
			
		||||
        $streamProphecy = $this->prophesize(StreamInterface::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->getMetadata($argKey)
 | 
			
		||||
            ->willReturn($returnValue)
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @var StreamInterface $stream */
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        return $stream;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateUploadedFileWithInvalidUri()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('File is not readable.');
 | 
			
		||||
 | 
			
		||||
        // Prophesize a `\Psr\Http\Message\StreamInterface` with a `getMetadata` method prophecy.
 | 
			
		||||
        $streamProphecy = $this->prophesize(StreamInterface::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->getMetadata('uri')
 | 
			
		||||
            ->willReturn(null)
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @var StreamInterface $stream */
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        $this->factory->createUploadedFile($stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateUploadedFileWithNonReadableFile()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('File is not readable.');
 | 
			
		||||
 | 
			
		||||
        // Prophesize a `\Psr\Http\Message\StreamInterface` with a `getMetadata` and `isReadable` method prophecies.
 | 
			
		||||
        $streamProphecy = $this->prophesize(StreamInterface::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->getMetadata('uri')
 | 
			
		||||
            ->willReturn('non-readable')
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->isReadable()
 | 
			
		||||
            ->willReturn(false)
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @var StreamInterface $stream */
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        $this->factory->createUploadedFile($stream);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										243
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/UriFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										243
									
								
								qwen/php/vendor/slim/psr7/tests/Factory/UriFactoryTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,243 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Factory;
 | 
			
		||||
 | 
			
		||||
use Interop\Http\Factory\UriFactoryTestCase;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
 | 
			
		||||
class UriFactoryTest extends UriFactoryTestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function createUriFactory(): UriFactory
 | 
			
		||||
    {
 | 
			
		||||
        return new UriFactory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAuthorityWithUsername()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://josh@example.com/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh@example.com', $uri->getAuthority());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAuthority()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://example.com/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getAuthority());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAuthorityWithNonStandardPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://example.com:400/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('example.com:400', $uri->getAuthority());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUserInfoWithUsernameAndPassword()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://josh:sekrit@example.com:443/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUserInfoWithUsernameAndPasswordEncodesCorrectly()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this
 | 
			
		||||
            ->createUriFactory()
 | 
			
		||||
            ->createUri('https://bob@example.com:pass:word@example.com:443/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bob%40example.com:pass%3Aword', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUserInfoWithUsername()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('http://josh@example.com/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUserInfoNone()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://example.com/foo/bar?abc=123#section3');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromString()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createUri('https://example.com:8080/foo/bar?abc=123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('https', $uri->getScheme());
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobals()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar?baz=1',
 | 
			
		||||
            'PHP_AUTH_USER' => 'josh',
 | 
			
		||||
            'PHP_AUTH_PW' => 'sekrit',
 | 
			
		||||
            'QUERY_STRING' => 'abc=123',
 | 
			
		||||
            'HTTP_HOST' => 'example.com:8080',
 | 
			
		||||
            'SERVER_PORT' => 8080,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithHttps()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock(
 | 
			
		||||
            [
 | 
			
		||||
                'HTTPS' => 'on',
 | 
			
		||||
                'HTTP_HOST' => 'example.com'
 | 
			
		||||
            ]
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        // Make the 'SERVER_PORT' empty as we want to test if the default server port gets set correctly.
 | 
			
		||||
        $globals['SERVER_PORT'] = '';
 | 
			
		||||
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('https', $uri->getScheme());
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
 | 
			
		||||
        // The port is expected to be NULL as the server port is the default standard (443 in case of https).
 | 
			
		||||
        $this->assertNull($uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsUsesServerNameAsHostIfHostHeaderIsNotPresent()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SERVER_NAME' => 'example.com',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('example.com', $uri->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalWithIPv6HostNoPort()
 | 
			
		||||
    {
 | 
			
		||||
        $environment = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar',
 | 
			
		||||
            'PHP_AUTH_USER' => 'josh',
 | 
			
		||||
            'PHP_AUTH_PW' => 'sekrit',
 | 
			
		||||
            'QUERY_STRING' => 'abc=123',
 | 
			
		||||
            'HTTP_HOST' => '[2001:db8::1]',
 | 
			
		||||
            'REMOTE_ADDR' => '2001:db8::1',
 | 
			
		||||
            'SERVER_PORT' => 8080,
 | 
			
		||||
        ]);
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($environment);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
        $this->assertEquals('[2001:db8::1]', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithIPv6HostWithPort()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/foo/bar',
 | 
			
		||||
            'PHP_AUTH_USER' => 'josh',
 | 
			
		||||
            'PHP_AUTH_PW' => 'sekrit',
 | 
			
		||||
            'QUERY_STRING' => 'abc=123',
 | 
			
		||||
            'HTTP_HOST' => '[2001:db8::1]:8080',
 | 
			
		||||
            'REMOTE_ADDR' => '2001:db8::1',
 | 
			
		||||
            'SERVER_PORT' => 8080,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('josh:sekrit', $uri->getUserInfo());
 | 
			
		||||
        $this->assertEquals('[2001:db8::1]', $uri->getHost());
 | 
			
		||||
        $this->assertEquals('8080', $uri->getPort());
 | 
			
		||||
        $this->assertEquals('/foo/bar', $uri->getPath());
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithBasePathContainingSpace()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => "/f'oo bar/index.php",
 | 
			
		||||
            'REQUEST_URI' => "/f%27oo%20bar/baz",
 | 
			
		||||
        ]);
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/f%27oo%20bar/baz', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathWhenBaseRootIsEmpty()
 | 
			
		||||
    {
 | 
			
		||||
        $globals = Environment::mock([
 | 
			
		||||
            'SCRIPT_NAME' => '/index.php',
 | 
			
		||||
            'REQUEST_URI' => '/bar',
 | 
			
		||||
        ]);
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals($globals);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('http://localhost/test', (string) $uri->withPath('test'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * When the URL is /foo/index.php/bar/baz, we need the baseURL to be
 | 
			
		||||
     * /foo/index.php so that routing works correctly.
 | 
			
		||||
     *
 | 
			
		||||
     * @ticket 1639 as a fix to 1590 broke this.
 | 
			
		||||
     */
 | 
			
		||||
    public function testRequestURIContainsIndexDotPhp()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals(
 | 
			
		||||
            Environment::mock(
 | 
			
		||||
                [
 | 
			
		||||
                    'SCRIPT_NAME' => '/foo/index.php',
 | 
			
		||||
                    'REQUEST_URI' => '/foo/index.php/bar/baz',
 | 
			
		||||
                ]
 | 
			
		||||
            )
 | 
			
		||||
        );
 | 
			
		||||
        $this->assertSame('/foo/index.php/bar/baz', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRequestURICanContainParams()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->createUriFactory()->createFromGlobals(
 | 
			
		||||
            Environment::mock(
 | 
			
		||||
                [
 | 
			
		||||
                    'REQUEST_URI' => '/foo?abc=123',
 | 
			
		||||
                ]
 | 
			
		||||
            )
 | 
			
		||||
        );
 | 
			
		||||
        $this->assertEquals('abc=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testUriDistinguishZeroFromEmptyString()
 | 
			
		||||
    {
 | 
			
		||||
        $expected = 'https://0:0@0:1/0?0#0';
 | 
			
		||||
        $this->assertSame($expected, (string) $this->createUriFactory()->createUri($expected));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										61
									
								
								qwen/php/vendor/slim/psr7/tests/HeaderTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								qwen/php/vendor/slim/psr7/tests/HeaderTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Header;
 | 
			
		||||
 | 
			
		||||
class HeaderTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Instantiate a default header.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Header
 | 
			
		||||
     */
 | 
			
		||||
    protected function headerFactory(): Header
 | 
			
		||||
    {
 | 
			
		||||
        $originalName = 'ACCEPT';
 | 
			
		||||
        $normalizedName = 'accept';
 | 
			
		||||
        $values = ['application/json'];
 | 
			
		||||
 | 
			
		||||
        return new Header($originalName, $normalizedName, $values);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetOriginalName(): void
 | 
			
		||||
    {
 | 
			
		||||
        $header = $this->headerFactory();
 | 
			
		||||
        $this->assertEquals('ACCEPT', $header->getOriginalName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetNormalizedName(): void
 | 
			
		||||
    {
 | 
			
		||||
        $header = $this->headerFactory();
 | 
			
		||||
        $this->assertEquals('accept', $header->getNormalizedName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddValue(): void
 | 
			
		||||
    {
 | 
			
		||||
        $header = $this->headerFactory();
 | 
			
		||||
        $header2 = $header->addValue('text/html');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $header->getValues());
 | 
			
		||||
        $this->assertSame($header2, $header);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddValuesString(): void
 | 
			
		||||
    {
 | 
			
		||||
        $header = $this->headerFactory();
 | 
			
		||||
        $header2 = $header->addValues('text/html');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $header->getValues());
 | 
			
		||||
        $this->assertSame($header2, $header);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										288
									
								
								qwen/php/vendor/slim/psr7/tests/HeadersTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										288
									
								
								qwen/php/vendor/slim/psr7/tests/HeadersTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,288 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
use function base64_encode;
 | 
			
		||||
 | 
			
		||||
class HeadersTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testCreateFromGlobals()
 | 
			
		||||
    {
 | 
			
		||||
        $GLOBALS['getallheaders_return'] = [
 | 
			
		||||
            'HTTP_ACCEPT' => 'application/json',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $headers = Headers::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        unset($GLOBALS['getallheaders_return']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['accept' => ['application/json']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['ACCEPT' => ['application/json']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsUsesEmptyArrayIfGetAllHeadersReturnsFalse()
 | 
			
		||||
    {
 | 
			
		||||
        $GLOBALS['getallheaders_return'] = false;
 | 
			
		||||
 | 
			
		||||
        $headers = Headers::createFromGlobals();
 | 
			
		||||
 | 
			
		||||
        unset($GLOBALS['getallheaders_return']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals([], $headers->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Accept' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->addHeader('Accept', 'text/html');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $headers->getHeader('Accept'));
 | 
			
		||||
        $this->assertEquals(['accept' => ['application/json', 'text/html']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['Accept' => ['application/json', 'text/html']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddHeaderValueEmptyArray()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('Header', []);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRemoveHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Accept' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->removeHeader('Accept');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals([], $headers->getHeader('Accept'));
 | 
			
		||||
        $this->assertEquals([], $headers->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @doesNotPerformAssertions
 | 
			
		||||
     */
 | 
			
		||||
    public function testRemoveHeaderByIncompatibleStringWithRFC()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->removeHeader('<incompatible with RFC>');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Accept' => ['application/json', 'text/html'],
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $headers->getHeader('accept'));
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $headers->getHeader('Accept'));
 | 
			
		||||
        $this->assertEquals(['application/json', 'text/html'], $headers->getHeader('HTTP_ACCEPT'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaderReturnsValidatedAndTrimedHeaderDefaultValue()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['application/json'], $headers->getHeader('accept', ' application/json'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaderThrowsExceptionWithInvalidDefaultArgument()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers([]);
 | 
			
		||||
 | 
			
		||||
        $headers->getHeader('accept', new stdClass());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Content-Length' => 0,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeader('Content-Length', 100);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame(['100'], $headers->getHeader('Content-Length'));
 | 
			
		||||
        $this->assertEquals(['content-length' => ['100']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['Content-Length' => ['100']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetHeaderPreservesOriginalCaseIfHeaderAlreadyExists()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'CONTENT-LENGTH' => 0,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeader('Content-Length', 100);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['content-length' => ['100']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['CONTENT-LENGTH' => ['100']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Content-Length' => 0,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeaders([
 | 
			
		||||
            'Accept' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['accept' => ['application/json']], $headers->getHeaders());
 | 
			
		||||
        $this->assertEquals(['Accept' => ['application/json']], $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHasHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'Accept' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($headers->hasHeader('accept'));
 | 
			
		||||
        $this->assertTrue($headers->hasHeader('Accept'));
 | 
			
		||||
        $this->assertTrue($headers->hasHeader('HTTP_ACCEPT'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'HTTP_ACCEPT' => 'text/html',
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $expectedNormalizedHeaders = [
 | 
			
		||||
            'accept' => ['text/html'],
 | 
			
		||||
            'content-type' => ['application/json'],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedNormalizedHeaders, $headers->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeadersPreservesOriginalCase()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers([
 | 
			
		||||
            'HTTP_ACCEPT' => 'text/html',
 | 
			
		||||
            'HTTP_CONTENT_TYPE' => 'application/json',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $expectedOriginalHeaders = [
 | 
			
		||||
            'ACCEPT' => ['text/html'],
 | 
			
		||||
            'CONTENT-TYPE' => ['application/json'],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($expectedOriginalHeaders, $headers->getHeaders(true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParseAuthorizationHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $expectedValue = 'Basic ' . base64_encode('user:password');
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers(['Authorization' => $expectedValue]);
 | 
			
		||||
        $this->assertEquals([$expectedValue], $headers->getHeader('Authorization'));
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers([], ['REDIRECT_HTTP_AUTHORIZATION' => 'cookie']);
 | 
			
		||||
        $this->assertEquals(['cookie'], $headers->getHeader('Authorization'));
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers([], ['PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'password']);
 | 
			
		||||
        $this->assertEquals([$expectedValue], $headers->getHeader('Authorization'));
 | 
			
		||||
 | 
			
		||||
        $headers = new Headers([], ['PHP_AUTH_DIGEST' => 'digest']);
 | 
			
		||||
        $this->assertEquals(['digest'], $headers->getHeader('Authorization'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider provideInvalidHeaderNames
 | 
			
		||||
     */
 | 
			
		||||
    public function testWithInvalidHeaderName($headerName): void
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
 | 
			
		||||
        $this->expectException(\InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeader($headerName, 'foo');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function provideInvalidHeaderNames(): array
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            [[]],
 | 
			
		||||
            [false],
 | 
			
		||||
            [new \stdClass()],
 | 
			
		||||
            ["Content-Type\r\n\r\n"],
 | 
			
		||||
            ["Content-Type\r\n"],
 | 
			
		||||
            ["Content-Type\n"],
 | 
			
		||||
            ["\r\nContent-Type"],
 | 
			
		||||
            ["\nContent-Type"],
 | 
			
		||||
            ["\n"],
 | 
			
		||||
            ["\r\n"],
 | 
			
		||||
            ["\t"],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider provideInvalidHeaderValues
 | 
			
		||||
     */
 | 
			
		||||
    public function testSetInvalidHeaderValue($headerValue)
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
 | 
			
		||||
        $this->expectException(\InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $headers->setHeader('Content-Type', $headerValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function provideInvalidHeaderValues(): array
 | 
			
		||||
    {
 | 
			
		||||
        // Explicit tests for newlines as the most common exploit vector.
 | 
			
		||||
        $tests = [
 | 
			
		||||
            ["new\nline"],
 | 
			
		||||
            ["new\r\nline"],
 | 
			
		||||
            ["new\rline"],
 | 
			
		||||
            ["new\r\n line"],
 | 
			
		||||
            ["newline\n"],
 | 
			
		||||
            ["\nnewline"],
 | 
			
		||||
            ["newline\r\n"],
 | 
			
		||||
            ["\n\rnewline"],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i <= 0xff; $i++) {
 | 
			
		||||
            if (\chr($i) == "\t") {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if (\chr($i) == " ") {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if ($i >= 0x21 && $i <= 0x7e) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if ($i >= 0x80) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $tests[] = ["foo" . \chr($i) . "bar"];
 | 
			
		||||
            $tests[] = ["foo" . \chr($i)];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $tests;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										57
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/BaseTestFactories.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/BaseTestFactories.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Integration;
 | 
			
		||||
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function is_resource;
 | 
			
		||||
 | 
			
		||||
trait BaseTestFactories
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $uri
 | 
			
		||||
     * @return UriInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected function buildUri($uri): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        return (new UriFactory())->createUri($uri);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param $data
 | 
			
		||||
     * @return Stream
 | 
			
		||||
     */
 | 
			
		||||
    protected function buildStream($data): Stream
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_resource($data)) {
 | 
			
		||||
            $h = fopen('php://temp', 'w+');
 | 
			
		||||
            fwrite($h, $data);
 | 
			
		||||
 | 
			
		||||
            $data = $h;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Stream($data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param $data
 | 
			
		||||
     * @return UploadedFile
 | 
			
		||||
     */
 | 
			
		||||
    protected function buildUploadableFile($data): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        return new UploadedFile($this->buildStream($data));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										36
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/RequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/RequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Integration;
 | 
			
		||||
 | 
			
		||||
use Http\Psr7Test\RequestIntegrationTest;
 | 
			
		||||
use Psr\Http\Message\RequestInterface;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Request;
 | 
			
		||||
 | 
			
		||||
class RequestTest extends RequestIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return RequestInterface that is used in the tests
 | 
			
		||||
     */
 | 
			
		||||
    public function createSubject(): RequestInterface
 | 
			
		||||
    {
 | 
			
		||||
        return new Request(
 | 
			
		||||
            'GET',
 | 
			
		||||
            $this->buildUri('/'),
 | 
			
		||||
            new Headers(),
 | 
			
		||||
            [],
 | 
			
		||||
            [],
 | 
			
		||||
            $this->buildStream('')
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/ResponseTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/ResponseTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Integration;
 | 
			
		||||
 | 
			
		||||
use Http\Psr7Test\ResponseIntegrationTest;
 | 
			
		||||
use Slim\Psr7\Response;
 | 
			
		||||
 | 
			
		||||
class ResponseTest extends ResponseIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Response that is used in the tests
 | 
			
		||||
     */
 | 
			
		||||
    public function createSubject(): Response
 | 
			
		||||
    {
 | 
			
		||||
        return new Response();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/ServerRequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/ServerRequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Integration;
 | 
			
		||||
 | 
			
		||||
use Http\Psr7Test\ServerRequestIntegrationTest;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Request;
 | 
			
		||||
 | 
			
		||||
class ServerRequestTest extends ServerRequestIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Request
 | 
			
		||||
     */
 | 
			
		||||
    public function createSubject(): Request
 | 
			
		||||
    {
 | 
			
		||||
        return new Request(
 | 
			
		||||
            'GET',
 | 
			
		||||
            $this->buildUri('/'),
 | 
			
		||||
            new Headers(),
 | 
			
		||||
            $_COOKIE,
 | 
			
		||||
            $_SERVER,
 | 
			
		||||
            $this->buildStream('')
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										46
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/StreamTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/StreamTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Integration;
 | 
			
		||||
 | 
			
		||||
use Http\Psr7Test\StreamIntegrationTest;
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function is_resource;
 | 
			
		||||
use function is_string;
 | 
			
		||||
 | 
			
		||||
class StreamTest extends StreamIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string|resource|StreamInterface $data
 | 
			
		||||
     *
 | 
			
		||||
     * @return StreamInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function createStream($data)
 | 
			
		||||
    {
 | 
			
		||||
        if ($data instanceof StreamInterface) {
 | 
			
		||||
            return $data;
 | 
			
		||||
        } elseif (is_resource($data)) {
 | 
			
		||||
            return new Stream($data);
 | 
			
		||||
        } elseif (is_string($data)) {
 | 
			
		||||
            $s = fopen('php://temp', 'w+');
 | 
			
		||||
            fwrite($s, $data);
 | 
			
		||||
            return new Stream($s);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        throw new InvalidArgumentException();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										51
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/UploadedFileTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/UploadedFileTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Integration;
 | 
			
		||||
 | 
			
		||||
use Http\Psr7Test\UploadedFileIntegrationTest;
 | 
			
		||||
use Psr\Http\Message\UploadedFileInterface;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
 | 
			
		||||
use function sys_get_temp_dir;
 | 
			
		||||
use function tempnam;
 | 
			
		||||
 | 
			
		||||
class UploadedFileTest extends UploadedFileIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    protected string $tempFilename;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return UploadedFileInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function createSubject()
 | 
			
		||||
    {
 | 
			
		||||
        $this->tempFilename = tempnam(sys_get_temp_dir(), 'Slim_Http_UploadedFileTest_');
 | 
			
		||||
        if (!$this->tempFilename) {
 | 
			
		||||
            throw new \RuntimeException("Unable to create temporary file");
 | 
			
		||||
        }
 | 
			
		||||
        file_put_contents($this->tempFilename, '12345');
 | 
			
		||||
 | 
			
		||||
        return new UploadedFile(
 | 
			
		||||
            $this->tempFilename,
 | 
			
		||||
            basename($this->tempFilename),
 | 
			
		||||
            'text/plain',
 | 
			
		||||
            (int)filesize($this->tempFilename)
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        if (is_file($this->tempFilename)) {
 | 
			
		||||
            unlink($this->tempFilename);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/UriTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								qwen/php/vendor/slim/psr7/tests/Integration/UriTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Integration;
 | 
			
		||||
 | 
			
		||||
use Http\Psr7Test\UriIntegrationTest;
 | 
			
		||||
use Psr\Http\Message\UriInterface;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
 | 
			
		||||
class UriTest extends UriIntegrationTest
 | 
			
		||||
{
 | 
			
		||||
    use BaseTestFactories;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $uri
 | 
			
		||||
     *
 | 
			
		||||
     * @return UriInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function createUri($uri): UriInterface
 | 
			
		||||
    {
 | 
			
		||||
        return (new UriFactory())->createUri($uri);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										186
									
								
								qwen/php/vendor/slim/psr7/tests/MessageTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										186
									
								
								qwen/php/vendor/slim/psr7/tests/MessageTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,186 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\MockObject\MockObject;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use Slim\Tests\Psr7\Mocks\MessageStub;
 | 
			
		||||
 | 
			
		||||
class MessageTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testGetProtocolVersion()
 | 
			
		||||
    {
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->protocolVersion = '1.0';
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('1.0', $message->getProtocolVersion());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithProtocolVersion()
 | 
			
		||||
    {
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $clone = $message->withProtocolVersion('1.0');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('1.0', $clone->protocolVersion);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithProtocolVersionInvalidThrowsException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->withProtocolVersion('3.0');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaders()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'two');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'three');
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
 | 
			
		||||
        $shouldBe = [
 | 
			
		||||
            'X-Foo' => [
 | 
			
		||||
                'one',
 | 
			
		||||
                'two',
 | 
			
		||||
                'three',
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($shouldBe, $message->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testHasHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($message->hasHeader('X-Foo'));
 | 
			
		||||
        $this->assertFalse($message->hasHeader('X-Bar'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeaderLine()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'two');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'three');
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('one,two,three', $message->getHeaderLine('X-Foo'));
 | 
			
		||||
        $this->assertEquals('', $message->getHeaderLine('X-Bar'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'two');
 | 
			
		||||
        $headers->addHeader('X-Foo', 'three');
 | 
			
		||||
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['one', 'two', 'three'], $message->getHeader('X-Foo'));
 | 
			
		||||
        $this->assertEquals([], $message->getHeader('X-Bar'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
        $clone = $message->withHeader('X-Foo', 'bar');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bar', $clone->getHeaderLine('X-Foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithAddedHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->headers = $headers;
 | 
			
		||||
        $clone = $message->withAddedHeader('X-Foo', 'two');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('one,two', $clone->getHeaderLine('X-Foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithoutHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->addHeader('X-Foo', 'one');
 | 
			
		||||
        $headers->addHeader('X-Bar', 'two');
 | 
			
		||||
        $response = new MessageStub();
 | 
			
		||||
        $response->headers = $headers;
 | 
			
		||||
        $clone = $response->withoutHeader('X-Foo');
 | 
			
		||||
        $shouldBe = [
 | 
			
		||||
            'X-Bar' => ['two'],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($shouldBe, $clone->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @doesNotPerformAssertions
 | 
			
		||||
     */
 | 
			
		||||
    public function testWithoutHeaderByIncompatibleStringWithRFC()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $response = new MessageStub();
 | 
			
		||||
        $response->headers = $headers;
 | 
			
		||||
        $response->withoutHeader('<incompatible with RFC');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetBody()
 | 
			
		||||
    {
 | 
			
		||||
        $body = $this->getBody();
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->body = $body;
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($body, $message->getBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithBody()
 | 
			
		||||
    {
 | 
			
		||||
        $body = $this->getBody();
 | 
			
		||||
        $body2 = $this->getBody();
 | 
			
		||||
        $message = new MessageStub();
 | 
			
		||||
        $message->body = $body;
 | 
			
		||||
        $clone = $message->withBody($body2);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($body, $message->body);
 | 
			
		||||
        $this->assertSame($body2, $clone->body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return MockObject|Stream
 | 
			
		||||
     */
 | 
			
		||||
    protected function getBody()
 | 
			
		||||
    {
 | 
			
		||||
        return $this
 | 
			
		||||
            ->getMockBuilder(Stream::class)
 | 
			
		||||
            ->disableOriginalConstructor()
 | 
			
		||||
            ->getMock();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										37
									
								
								qwen/php/vendor/slim/psr7/tests/Mocks/MessageStub.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								qwen/php/vendor/slim/psr7/tests/Mocks/MessageStub.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7\Mocks;
 | 
			
		||||
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Slim\Psr7\Interfaces\HeadersInterface;
 | 
			
		||||
use Slim\Psr7\Message;
 | 
			
		||||
 | 
			
		||||
class MessageStub extends Message
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Protocol version
 | 
			
		||||
     */
 | 
			
		||||
    public string $protocolVersion;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Headers
 | 
			
		||||
     *
 | 
			
		||||
     * @var HeadersInterface
 | 
			
		||||
     */
 | 
			
		||||
    public $headers;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Body object
 | 
			
		||||
     *
 | 
			
		||||
     * @var StreamInterface
 | 
			
		||||
     */
 | 
			
		||||
    public $body;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										159
									
								
								qwen/php/vendor/slim/psr7/tests/NonBufferedBodyTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										159
									
								
								qwen/php/vendor/slim/psr7/tests/NonBufferedBodyTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,159 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\NonBufferedBody;
 | 
			
		||||
use Slim\Psr7\Response;
 | 
			
		||||
use Slim\Tests\Psr7\Assets\HeaderStack;
 | 
			
		||||
 | 
			
		||||
use function ob_get_clean;
 | 
			
		||||
use function ob_get_level;
 | 
			
		||||
use function ob_start;
 | 
			
		||||
use function strlen;
 | 
			
		||||
 | 
			
		||||
class NonBufferedBodyTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        HeaderStack::reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        HeaderStack::reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testTheStreamContract()
 | 
			
		||||
    {
 | 
			
		||||
        $body = new NonBufferedBody();
 | 
			
		||||
        self::assertSame('', (string) $body, 'Casting to string returns no data, since the class does not store any');
 | 
			
		||||
        self::assertNull($body->detach(), 'Returns null since there is no such underlying stream');
 | 
			
		||||
        self::assertNull($body->getSize(), 'Current size is undefined');
 | 
			
		||||
        self::assertSame(0, $body->tell(), 'Pointer is considered to be at position 0 to conform');
 | 
			
		||||
        self::assertTrue($body->eof(), 'Always considered to be at EOF');
 | 
			
		||||
        self::assertFalse($body->isSeekable(), 'Cannot seek');
 | 
			
		||||
        self::assertTrue($body->isWritable(), 'Body is writable');
 | 
			
		||||
        self::assertFalse($body->isReadable(), 'Body is not readable');
 | 
			
		||||
        self::assertSame('', $body->getContents(), 'Data cannot be retrieved once written');
 | 
			
		||||
        self::assertNull($body->getMetadata(), 'Metadata mechanism is not implemented');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWrite()
 | 
			
		||||
    {
 | 
			
		||||
        $ob_initial_level = ob_get_level();
 | 
			
		||||
 | 
			
		||||
        // Start output buffering.
 | 
			
		||||
        ob_start();
 | 
			
		||||
 | 
			
		||||
        // Start output buffering again to test the while-loop in the `write()`
 | 
			
		||||
        // method that calls `ob_get_clean()` as long as the ob level is bigger
 | 
			
		||||
        // than 0.
 | 
			
		||||
        ob_start();
 | 
			
		||||
        echo 'buffer content: ';
 | 
			
		||||
 | 
			
		||||
        // Set the ob level shift that should be applied in the `ob_get_level()`
 | 
			
		||||
        // function override. That way, the `write()` method would only flush
 | 
			
		||||
        // the second ob, not the first one. We will add the initial ob level
 | 
			
		||||
        // because phpunit may have started ob too.
 | 
			
		||||
        $GLOBALS['ob_get_level_shift'] = -($ob_initial_level + 1);
 | 
			
		||||
 | 
			
		||||
        $body = new NonBufferedBody();
 | 
			
		||||
        $length0 = $body->write('hello ');
 | 
			
		||||
        $length1 = $body->write('world');
 | 
			
		||||
 | 
			
		||||
        unset($GLOBALS['ob_get_level_shift']);
 | 
			
		||||
        $contents = ob_get_clean();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(strlen('buffer content: ') + strlen('hello '), $length0);
 | 
			
		||||
        $this->assertEquals(strlen('world'), $length1);
 | 
			
		||||
        $this->assertEquals('buffer content: hello world', $contents);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHeader()
 | 
			
		||||
    {
 | 
			
		||||
        (new Response())
 | 
			
		||||
            ->withBody(new NonBufferedBody())
 | 
			
		||||
            ->withHeader('Foo', 'Bar');
 | 
			
		||||
 | 
			
		||||
        self::assertSame([
 | 
			
		||||
            [
 | 
			
		||||
                'header' => 'Foo: Bar',
 | 
			
		||||
                'replace' => true,
 | 
			
		||||
                'status_code' => null
 | 
			
		||||
            ]
 | 
			
		||||
        ], HeaderStack::stack());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithAddedHeader()
 | 
			
		||||
    {
 | 
			
		||||
        (new Response())
 | 
			
		||||
            ->withBody(new NonBufferedBody())
 | 
			
		||||
            ->withHeader('Foo', 'Bar')
 | 
			
		||||
            ->withAddedHeader('Foo', 'Baz');
 | 
			
		||||
 | 
			
		||||
        self::assertSame([
 | 
			
		||||
            [
 | 
			
		||||
                'header' => 'Foo: Bar',
 | 
			
		||||
                'replace' => true,
 | 
			
		||||
                'status_code' => null
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'header' => 'Foo: Bar,Baz',
 | 
			
		||||
                'replace' => true,
 | 
			
		||||
                'status_code' => null
 | 
			
		||||
            ]
 | 
			
		||||
        ], HeaderStack::stack());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithoutHeader()
 | 
			
		||||
    {
 | 
			
		||||
        (new Response())
 | 
			
		||||
            ->withBody(new NonBufferedBody())
 | 
			
		||||
            ->withHeader('Foo', 'Bar')
 | 
			
		||||
            ->withoutHeader('Foo');
 | 
			
		||||
 | 
			
		||||
        self::assertSame([], HeaderStack::stack());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCloseThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('A NonBufferedBody is not closable.');
 | 
			
		||||
 | 
			
		||||
        (new NonBufferedBody())->close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSeekThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('A NonBufferedBody is not seekable.');
 | 
			
		||||
 | 
			
		||||
        (new NonBufferedBody())->seek(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRewindThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('A NonBufferedBody is not rewindable.');
 | 
			
		||||
 | 
			
		||||
        (new NonBufferedBody())->rewind();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReadThrowsRuntimeException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('A NonBufferedBody is not readable.');
 | 
			
		||||
 | 
			
		||||
        (new NonBufferedBody())->read(10);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										458
									
								
								qwen/php/vendor/slim/psr7/tests/RequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										458
									
								
								qwen/php/vendor/slim/psr7/tests/RequestTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,458 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UriFactory;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Request;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
use Slim\Psr7\Uri;
 | 
			
		||||
 | 
			
		||||
use function property_exists;
 | 
			
		||||
use function sprintf;
 | 
			
		||||
 | 
			
		||||
class RequestTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function requestFactory($envData = []): Request
 | 
			
		||||
    {
 | 
			
		||||
        $env = Environment::mock($envData);
 | 
			
		||||
 | 
			
		||||
        $uri = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $headers = Headers::createFromGlobals($env);
 | 
			
		||||
        $cookies = [
 | 
			
		||||
            'user' => 'john',
 | 
			
		||||
            'id' => '123',
 | 
			
		||||
        ];
 | 
			
		||||
        $serverParams = $env;
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $uploadedFiles = UploadedFile::createFromGlobals($env);
 | 
			
		||||
        $request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
 | 
			
		||||
 | 
			
		||||
        return $request;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDisableSetter()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $request->foo = 'bar';
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse(property_exists($request, 'foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAddsHostHeaderFromUri()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $this->assertEquals('example.com', $request->getHeaderLine('Host'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMethod()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('GET', $this->requestFactory()->getMethod());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithMethod()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory()->withMethod('PUT');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('PUT', $request->getMethod());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithMethodCaseSensitive()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory()->withMethod('pOsT');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('pOsT', $request->getMethod());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithAllAllowedCharactersMethod()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory()->withMethod("!#$%&'*+.^_`|~09AZ-");
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals("!#$%&'*+.^_`|~09AZ-", $request->getMethod());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithMethodInvalid()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->requestFactory()->withMethod('B@R');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateRequestWithInvalidMethodString()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $uri = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
 | 
			
		||||
        new Request('B@R', $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateRequestWithInvalidMethodOther()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $uri = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
 | 
			
		||||
        new Request(10, $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetRequestTarget()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('/foo/bar?abc=123', $this->requestFactory()->getRequestTarget());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetRequestTargetAlreadySet()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'requestTarget');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, '/foo/bar?abc=123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/foo/bar?abc=123', $request->getRequestTarget());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetRequestTargetIfNoUri()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'uri');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/', $request->getRequestTarget());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithRequestTarget()
 | 
			
		||||
    {
 | 
			
		||||
        $clone = $this->requestFactory()->withRequestTarget('/test?user=1');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/test?user=1', $clone->getRequestTarget());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithRequestTargetThatHasSpaces()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->requestFactory()->withRequestTarget('/test/m ore/stuff?user=1');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetUri()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($uri, $request->getUri());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUri()
 | 
			
		||||
    {
 | 
			
		||||
        // Uris
 | 
			
		||||
        $uri1 = (new UriFactory())->createUri('https://example.com:443/foo/bar?abc=123');
 | 
			
		||||
        $uri2 = (new UriFactory())->createUri('https://example2.com:443/test?xyz=123');
 | 
			
		||||
 | 
			
		||||
        // Request
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $request = new Request('GET', $uri1, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
        $clone = $request->withUri($uri2);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame($uri2, $clone->getUri());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUriPreservesHost()
 | 
			
		||||
    {
 | 
			
		||||
        // When `$preserveHost` is set to `true`, this method interacts with
 | 
			
		||||
        // the Host header in the following ways:
 | 
			
		||||
 | 
			
		||||
        // - If the Host header is missing or empty, and the new URI contains
 | 
			
		||||
        //   a host component, this method MUST update the Host header in the returned
 | 
			
		||||
        //   request.
 | 
			
		||||
        $uri1 = (new UriFactory())->createUri('');
 | 
			
		||||
        $uri2 = (new UriFactory())->createUri('http://example2.com/test');
 | 
			
		||||
 | 
			
		||||
        // Request
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $request = new Request('GET', $uri1, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
 | 
			
		||||
        $clone = $request->withUri($uri2, true);
 | 
			
		||||
        $this->assertSame('example2.com', $clone->getHeaderLine('Host'));
 | 
			
		||||
 | 
			
		||||
        // - If the Host header is missing or empty, and the new URI does not contain a
 | 
			
		||||
        //   host component, this method MUST NOT update the Host header in the returned
 | 
			
		||||
        //   request.
 | 
			
		||||
        $uri3 = (new UriFactory())->createUri('');
 | 
			
		||||
 | 
			
		||||
        $clone = $request->withUri($uri3, true);
 | 
			
		||||
        $this->assertSame('', $clone->getHeaderLine('Host'));
 | 
			
		||||
 | 
			
		||||
        // - If a Host header is present and non-empty, this method MUST NOT update
 | 
			
		||||
        //   the Host header in the returned request.
 | 
			
		||||
        $request = $request->withHeader('Host', 'example.com');
 | 
			
		||||
        $clone = $request->withUri($uri2, true);
 | 
			
		||||
        $this->assertSame('example.com', $clone->getHeaderLine('Host'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetCookieParams()
 | 
			
		||||
    {
 | 
			
		||||
        $shouldBe = [
 | 
			
		||||
            'user' => 'john',
 | 
			
		||||
            'id' => '123',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($shouldBe, $this->requestFactory()->getCookieParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithCookieParams()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $clone = $request->withCookieParams(['type' => 'framework']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['type' => 'framework'], $clone->getCookieParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetQueryParams()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals(['abc' => '123'], $this->requestFactory()->getQueryParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetQueryParamsAlreadySet()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'queryParams');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['foo' => 'bar'], $request->getQueryParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryParams()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $clone = $request->withQueryParams(['foo' => 'bar']);
 | 
			
		||||
        $cloneUri = $clone->getUri();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('abc=123', $cloneUri->getQuery()); // <-- Unchanged
 | 
			
		||||
        $this->assertEquals(['foo' => 'bar'], $clone->getQueryParams()); // <-- Changed
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryParamsEmptyArray()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $clone = $request->withQueryParams([]);
 | 
			
		||||
        $cloneUri = $clone->getUri();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('abc=123', $cloneUri->getQuery()); // <-- Unchanged
 | 
			
		||||
        $this->assertEquals([], $clone->getQueryParams()); // <-- Changed
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetQueryParamsWithoutUri()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'uri');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals([], $request->getQueryParams());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUploadedFiles()
 | 
			
		||||
    {
 | 
			
		||||
        $files = [new UploadedFile('foo.txt'), new UploadedFile('bar.txt')];
 | 
			
		||||
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prevUploaded = $request->getUploadedFiles();
 | 
			
		||||
        $clone = $request->withUploadedFiles($files);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($prevUploaded, $request->getUploadedFiles());
 | 
			
		||||
        $this->assertEquals($files, $clone->getUploadedFiles());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetServerParams()
 | 
			
		||||
    {
 | 
			
		||||
        $mockEnv = Environment::mock(["HTTP_AUTHORIZATION" => "test"]);
 | 
			
		||||
        $request = $this->requestFactory(["HTTP_AUTHORIZATION" => "test"]);
 | 
			
		||||
 | 
			
		||||
        $serverParams = $request->getServerParams();
 | 
			
		||||
        foreach ($serverParams as $key => $value) {
 | 
			
		||||
            if ($key == 'REQUEST_TIME' || $key == 'REQUEST_TIME_FLOAT') {
 | 
			
		||||
                $this->assertGreaterThanOrEqual(
 | 
			
		||||
                    $mockEnv[$key],
 | 
			
		||||
                    $value,
 | 
			
		||||
                    sprintf("%s value of %s was less than expected value of %s", $key, $value, $mockEnv[$key])
 | 
			
		||||
                );
 | 
			
		||||
            } else {
 | 
			
		||||
                $this->assertEquals(
 | 
			
		||||
                    $mockEnv[$key],
 | 
			
		||||
                    $value,
 | 
			
		||||
                    sprintf("%s value of %s did not equal expected value of %s", $key, $value, $mockEnv[$key])
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAttributes()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $attrProp = new ReflectionProperty($request, 'attributes');
 | 
			
		||||
        $attrProp->setAccessible(true);
 | 
			
		||||
        $attrProp->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['foo' => 'bar'], $request->getAttributes());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAttribute()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $attrProp = new ReflectionProperty($request, 'attributes');
 | 
			
		||||
        $attrProp->setAccessible(true);
 | 
			
		||||
        $attrProp->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bar', $request->getAttribute('foo'));
 | 
			
		||||
        $this->assertNull($request->getAttribute('bar'));
 | 
			
		||||
        $this->assertEquals(2, $request->getAttribute('bar', 2));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithAttribute()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $attrProp = new ReflectionProperty($request, 'attributes');
 | 
			
		||||
        $attrProp->setAccessible(true);
 | 
			
		||||
        $attrProp->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
        $clone = $request->withAttribute('test', '123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('123', $clone->getAttribute('test'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithoutAttribute()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $attrProp = new ReflectionProperty($request, 'attributes');
 | 
			
		||||
        $attrProp->setAccessible(true);
 | 
			
		||||
        $attrProp->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
        $clone = $request->withoutAttribute('foo');
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($clone->getAttribute('foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetParsedBodyWhenAlreadyParsed()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'parsedBody');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, ['foo' => 'bar']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['foo' => 'bar'], $request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetParsedBodyWhenBodyDoesNotExist()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory();
 | 
			
		||||
        $prop = new ReflectionProperty($request, 'body');
 | 
			
		||||
        $prop->setAccessible(true);
 | 
			
		||||
        $prop->setValue($request, null);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBody()
 | 
			
		||||
    {
 | 
			
		||||
        $clone = $this->requestFactory()->withParsedBody(['xyz' => '123']);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(['xyz' => '123'], $clone->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBodyEmptyArray()
 | 
			
		||||
    {
 | 
			
		||||
        $method = 'GET';
 | 
			
		||||
        $uri = new Uri('https', 'example.com', 443, '/foo/bar', 'abc=123', '', '');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf8');
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $body->write('foo=bar');
 | 
			
		||||
        $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
 | 
			
		||||
        $clone = $request->withParsedBody([]);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals([], $clone->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBodyNull()
 | 
			
		||||
    {
 | 
			
		||||
        $method = 'GET';
 | 
			
		||||
        $uri = new Uri('https', 'example.com', 443, '/foo/bar', 'abc=123', '', '');
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $headers->setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf8');
 | 
			
		||||
        $cookies = [];
 | 
			
		||||
        $serverParams = [];
 | 
			
		||||
        $body = (new StreamFactory())->createStream();
 | 
			
		||||
        $body->write('foo=bar');
 | 
			
		||||
        $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
 | 
			
		||||
 | 
			
		||||
        $clone = $request->withParsedBody(null);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($clone->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetParsedBodyReturnsNullWhenThereIsNoBodyData()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory(['REQUEST_METHOD' => 'POST']);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetParsedBodyReturnsNullWhenThereIsNoMediaTypeParserRegistered()
 | 
			
		||||
    {
 | 
			
		||||
        $request = $this->requestFactory([
 | 
			
		||||
            'REQUEST_METHOD' => 'POST',
 | 
			
		||||
            'CONTENT_TYPE' => 'text/csv',
 | 
			
		||||
        ]);
 | 
			
		||||
        $request->getBody()->write('foo,bar,baz');
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($request->getParsedBody());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBodyInvalid()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->requestFactory()->withParsedBody(2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithParsedBodyInvalidFalseValue()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->requestFactory()->withParsedBody(false);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										191
									
								
								qwen/php/vendor/slim/psr7/tests/ResponseTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										191
									
								
								qwen/php/vendor/slim/psr7/tests/ResponseTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,191 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Response;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function property_exists;
 | 
			
		||||
 | 
			
		||||
class ResponseTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testConstructorWithDefaultArgs()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
 | 
			
		||||
        $headersReflection = new ReflectionProperty($response, 'headers');
 | 
			
		||||
        $headersReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyReflection = new ReflectionProperty($response, 'body');
 | 
			
		||||
        $bodyReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(200, $response->getStatusCode());
 | 
			
		||||
        $this->assertInstanceOf(Headers::class, $headersReflection->getValue($response));
 | 
			
		||||
        $this->assertInstanceOf(Stream::class, $bodyReflection->getValue($response));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructorWithCustomArgs()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $body = new Stream(fopen('php://temp', 'r+'));
 | 
			
		||||
        $response = new Response(404, $headers, $body);
 | 
			
		||||
 | 
			
		||||
        $headersReflection = new ReflectionProperty($response, 'headers');
 | 
			
		||||
        $headersReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $bodyReflection = new ReflectionProperty($response, 'body');
 | 
			
		||||
        $bodyReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(404, $response->getStatusCode());
 | 
			
		||||
        $this->assertSame($headers, $headersReflection->getValue($response));
 | 
			
		||||
        $this->assertSame($body, $bodyReflection->getValue($response));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDeepCopyClone()
 | 
			
		||||
    {
 | 
			
		||||
        $headers = new Headers();
 | 
			
		||||
        $body = new Stream(fopen('php://temp', 'r+'));
 | 
			
		||||
        $response = new Response(404, $headers, $body);
 | 
			
		||||
        $clone = clone $response;
 | 
			
		||||
 | 
			
		||||
        $headersReflection = new ReflectionProperty($response, 'headers');
 | 
			
		||||
        $headersReflection->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(404, $clone->getStatusCode());
 | 
			
		||||
        $this->assertEquals('1.1', $clone->getProtocolVersion());
 | 
			
		||||
        $this->assertNotSame($headers, $headersReflection->getValue($clone));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDisableSetter()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response->foo = 'bar';
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse(property_exists($response, 'foo'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetStatusCode()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $responseStatus = new ReflectionProperty($response, 'status');
 | 
			
		||||
        $responseStatus->setAccessible(true);
 | 
			
		||||
        $responseStatus->setValue($response, 404);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(404, $response->getStatusCode());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatus()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $clone = $response->withStatus(302);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(302, $clone->getStatusCode());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatusInvalidStatusCodeThrowsException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response->withStatus(800);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatusInvalidReasonPhraseThrowsException()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Response reason phrase must be a string');
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response->withStatus(200, null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatusEmptyReasonPhrase()
 | 
			
		||||
    {
 | 
			
		||||
        $responseWithNoMessage = new Response(310);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $responseWithNoMessage->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReasonPhraseContainsCarriageReturn()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Reason phrase contains one of the following prohibited characters: \r \n');
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(404, "Not Found\r");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReasonPhraseContainsLineFeed()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Reason phrase contains one of the following prohibited characters: \r \n');
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(404, "Not Found\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithStatusValidReasonPhraseObject()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(200, new StringableTestObject('Slim OK'));
 | 
			
		||||
        $this->assertEquals('Slim OK', $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetReasonPhrase()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response(404);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('Not Found', $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testEmptyReasonPhraseForUnrecognisedCode()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(199);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame('', $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetReasonPhraseForUnrecognisedCode()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $response = $response->withStatus(199, 'Random Message');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('Random Message', $response->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetCustomReasonPhrase()
 | 
			
		||||
    {
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $clone = $response->withStatus(200, 'Custom Phrase');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('Custom Phrase', $clone->getReasonPhrase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testResponseHeadersDoNotContainAuthorizationHeader()
 | 
			
		||||
    {
 | 
			
		||||
        $_SERVER = Environment::mock(
 | 
			
		||||
            [
 | 
			
		||||
                'PHP_AUTH_USER' => 'foo'
 | 
			
		||||
            ]
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $response = new Response();
 | 
			
		||||
        $this->assertEmpty($response->getHeaders());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										284
									
								
								qwen/php/vendor/slim/psr7/tests/StreamTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										284
									
								
								qwen/php/vendor/slim/psr7/tests/StreamTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,284 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Prophecy\PhpUnit\ProphecyTrait;
 | 
			
		||||
use ReflectionException;
 | 
			
		||||
use ReflectionMethod;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function popen;
 | 
			
		||||
use function stream_get_contents;
 | 
			
		||||
use function trim;
 | 
			
		||||
 | 
			
		||||
class StreamTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    use ProphecyTrait;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var resource pipe stream file handle
 | 
			
		||||
     */
 | 
			
		||||
    private $pipeFh;
 | 
			
		||||
 | 
			
		||||
    private Stream $pipeStream;
 | 
			
		||||
 | 
			
		||||
    public function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->pipeFh != null) {
 | 
			
		||||
            // prevent broken pipe error message
 | 
			
		||||
            stream_get_contents($this->pipeFh);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsPipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($this->pipeStream->isPipe());
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->detach();
 | 
			
		||||
        $this->assertFalse($this->pipeStream->isPipe());
 | 
			
		||||
 | 
			
		||||
        $fhFile = fopen(__FILE__, 'r');
 | 
			
		||||
        $fileStream = new Stream($fhFile);
 | 
			
		||||
        $this->assertFalse($fileStream->isPipe());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsPipeReadable()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($this->pipeStream->isReadable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testPipeIsNotSeekable()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($this->pipeStream->isSeekable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCannotSeekPipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->seek(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCannotTellPipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->tell();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCannotRewindPipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->rewind();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testPipeGetSizeYieldsNull()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($this->pipeStream->getSize());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testClosePipe()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        // prevent broken pipe error message
 | 
			
		||||
        stream_get_contents($this->pipeFh);
 | 
			
		||||
 | 
			
		||||
        $this->pipeStream->close();
 | 
			
		||||
        $this->pipeFh = null;
 | 
			
		||||
 | 
			
		||||
        $this->assertFalse($this->pipeStream->isPipe());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testPipeToString()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
        $content = trim((string) $this->pipeStream);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame('12', $content);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConvertsToStringPartiallyReadNonSeekableStream()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
        $head = $this->pipeStream->read(1);
 | 
			
		||||
        $tail = trim((string) $this->pipeStream);
 | 
			
		||||
 | 
			
		||||
        $this->assertSame('1', $head);
 | 
			
		||||
        $this->assertSame('2', $tail);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testPipeGetContents()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $contents = trim($this->pipeStream->getContents());
 | 
			
		||||
        $this->assertSame('12', $contents);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsWriteable()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'w');
 | 
			
		||||
        $stream = new Stream($resource);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(13, $stream->write('Hello, world!'));
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($stream->isWritable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsReadable()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'r');
 | 
			
		||||
        $stream = new Stream($resource);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($stream->isReadable());
 | 
			
		||||
        $this->assertFalse($stream->isWritable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testIsWritableAndReadable()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'w+');
 | 
			
		||||
        $stream = new Stream($resource);
 | 
			
		||||
 | 
			
		||||
        $stream->write('Hello, world!');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('Hello, world!', $stream);
 | 
			
		||||
 | 
			
		||||
        $this->assertTrue($stream->isWritable());
 | 
			
		||||
        $this->assertTrue($stream->isReadable());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Test that a call to the protected method `attach` would invoke `detach`.
 | 
			
		||||
     *
 | 
			
		||||
     * @throws ReflectionException
 | 
			
		||||
     */
 | 
			
		||||
    public function testAttachAgain()
 | 
			
		||||
    {
 | 
			
		||||
        $this->openPipeStream();
 | 
			
		||||
 | 
			
		||||
        $streamProphecy = $this->prophesize(Stream::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy->detach()->shouldBeCalled();
 | 
			
		||||
 | 
			
		||||
        /** @var Stream $stream */
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        $streamProperty = new ReflectionProperty(Stream::class, 'stream');
 | 
			
		||||
        $streamProperty->setAccessible(true);
 | 
			
		||||
        $streamProperty->setValue($stream, $this->pipeFh);
 | 
			
		||||
 | 
			
		||||
        $attachMethod = new ReflectionMethod(Stream::class, 'attach');
 | 
			
		||||
        $attachMethod->setAccessible(true);
 | 
			
		||||
        $attachMethod->invoke($stream, $this->pipeFh);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetMetaDataReturnsNullIfStreamIsDetached()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'rw+');
 | 
			
		||||
        $stream = new Stream($resource);
 | 
			
		||||
        $stream->detach();
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($stream->getMetadata());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function openPipeStream()
 | 
			
		||||
    {
 | 
			
		||||
        $this->pipeFh = popen('echo 12', 'r');
 | 
			
		||||
        $this->pipeStream = new Stream($this->pipeFh);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testReadOnlyCachedStreamsAreDisallowed()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'w+');
 | 
			
		||||
        $cache =  new Stream(fopen('php://temp', 'r'));
 | 
			
		||||
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Cache stream must be seekable and writable');
 | 
			
		||||
        new Stream($resource, $cache);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testNonSeekableCachedStreamsAreDisallowed()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('php://temp', 'w+');
 | 
			
		||||
        $cache =  new Stream(fopen('php://output', 'w'));
 | 
			
		||||
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Cache stream must be seekable and writable');
 | 
			
		||||
 | 
			
		||||
        new Stream($resource, $cache);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCachedStreamsGetsContentFromTheCache()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = popen('echo HelloWorld', 'r');
 | 
			
		||||
        $stream = new Stream($resource, new Stream(fopen('php://temp', 'w+')));
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals("HelloWorld\n", $stream->getContents());
 | 
			
		||||
        $this->assertEquals("HelloWorld\n", $stream->getContents());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCachedStreamsFillsCacheOnRead()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('data://,0', 'r');
 | 
			
		||||
        $stream = new Stream($resource, new Stream(fopen('php://temp', 'w+')));
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals("0", $stream->read(100));
 | 
			
		||||
        $this->assertEquals("0", $stream->__toString());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDetachingStreamDropsCache()
 | 
			
		||||
    {
 | 
			
		||||
        $cache = new Stream(fopen('php://temp', 'w+'));
 | 
			
		||||
        $resource = fopen('data://,foo', 'r');
 | 
			
		||||
        $stream = new Stream($resource, $cache);
 | 
			
		||||
 | 
			
		||||
        $stream->detach();
 | 
			
		||||
 | 
			
		||||
        $cacheProperty = new ReflectionProperty(Stream::class, 'cache');
 | 
			
		||||
        $cacheProperty->setAccessible(true);
 | 
			
		||||
        $finishedProperty = new ReflectionProperty(Stream::class, 'finished');
 | 
			
		||||
        $finishedProperty->setAccessible(true);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($cacheProperty->getValue($stream));
 | 
			
		||||
        $this->assertFalse($finishedProperty->getValue($stream));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCachedStreamsRewindIfFinishedOnToString()
 | 
			
		||||
    {
 | 
			
		||||
        $resource = fopen('data://,foo', 'r');
 | 
			
		||||
 | 
			
		||||
        $stream = new Stream($resource, new Stream(fopen('php://temp', 'w+')));
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('foo', (string)$stream);
 | 
			
		||||
        $this->assertEquals('foo', (string)$stream);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								qwen/php/vendor/slim/psr7/tests/StringableTestObject.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								qwen/php/vendor/slim/psr7/tests/StringableTestObject.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
final class StringableTestObject implements \Stringable
 | 
			
		||||
{
 | 
			
		||||
    public function __construct(private string $value)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function __toString(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->value;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										676
									
								
								qwen/php/vendor/slim/psr7/tests/UploadedFileTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										676
									
								
								qwen/php/vendor/slim/psr7/tests/UploadedFileTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,676 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Prophecy\PhpUnit\ProphecyTrait;
 | 
			
		||||
use Psr\Http\Message\StreamInterface;
 | 
			
		||||
use Psr\Http\Message\UploadedFileInterface;
 | 
			
		||||
use ReflectionProperty;
 | 
			
		||||
use RuntimeException;
 | 
			
		||||
use Slim\Psr7\Environment;
 | 
			
		||||
use Slim\Psr7\Factory\StreamFactory;
 | 
			
		||||
use Slim\Psr7\Factory\UploadedFileFactory;
 | 
			
		||||
use Slim\Psr7\Stream;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
 | 
			
		||||
use function call_user_func;
 | 
			
		||||
use function fclose;
 | 
			
		||||
use function file_exists;
 | 
			
		||||
use function file_get_contents;
 | 
			
		||||
use function fopen;
 | 
			
		||||
use function fwrite;
 | 
			
		||||
use function microtime;
 | 
			
		||||
use function ob_get_clean;
 | 
			
		||||
use function ob_start;
 | 
			
		||||
use function strlen;
 | 
			
		||||
use function sys_get_temp_dir;
 | 
			
		||||
use function uniqid;
 | 
			
		||||
use function unlink;
 | 
			
		||||
use function version_compare;
 | 
			
		||||
 | 
			
		||||
use const DIRECTORY_SEPARATOR;
 | 
			
		||||
use const UPLOAD_ERR_CANT_WRITE;
 | 
			
		||||
use const UPLOAD_ERR_OK;
 | 
			
		||||
 | 
			
		||||
class UploadedFileTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    use ProphecyTrait;
 | 
			
		||||
 | 
			
		||||
    private static string $filename = './phpUxcOty';
 | 
			
		||||
 | 
			
		||||
    private static array $tmpFiles = ['./phpUxcOty'];
 | 
			
		||||
 | 
			
		||||
    public static function setUpBeforeClass(): void
 | 
			
		||||
    {
 | 
			
		||||
        $fh = fopen(self::$filename, "w");
 | 
			
		||||
        fwrite($fh, "12345678");
 | 
			
		||||
        fclose($fh);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function tearDownAfterClass(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (self::$tmpFiles as $filename) {
 | 
			
		||||
            if (file_exists($filename)) {
 | 
			
		||||
                unlink($filename);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        if (isset($GLOBALS['is_uploaded_file_return'])) {
 | 
			
		||||
            unset($GLOBALS['is_uploaded_file_return']);
 | 
			
		||||
        }
 | 
			
		||||
        if (isset($GLOBALS['copy_return'])) {
 | 
			
		||||
            unset($GLOBALS['copy_return']);
 | 
			
		||||
        }
 | 
			
		||||
        if (isset($GLOBALS['rename_return'])) {
 | 
			
		||||
            unset($GLOBALS['rename_return']);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generateNewTmpFile(): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $filename = './php' . microtime();
 | 
			
		||||
 | 
			
		||||
        $fh = fopen($filename, "w");
 | 
			
		||||
        fwrite($fh, "12345678");
 | 
			
		||||
        fclose($fh);
 | 
			
		||||
 | 
			
		||||
        self::$tmpFiles[] = $filename;
 | 
			
		||||
 | 
			
		||||
        return new UploadedFile($filename);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array $input    The input array to parse.
 | 
			
		||||
     * @param array $expected The expected normalized output.
 | 
			
		||||
     *
 | 
			
		||||
     * @dataProvider providerCreateFromGlobals
 | 
			
		||||
     */
 | 
			
		||||
    public function testCreateFromGlobalsFromFilesSuperglobal(array $input, array $expected)
 | 
			
		||||
    {
 | 
			
		||||
        $_FILES = $input;
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = UploadedFile::createFromGlobals(Environment::mock());
 | 
			
		||||
        $this->assertEquals($expected, $uploadedFile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array $input The input array to parse.
 | 
			
		||||
     *
 | 
			
		||||
     * @dataProvider providerCreateFromGlobals
 | 
			
		||||
     */
 | 
			
		||||
    public function testCreateFromGlobalsFromUserData(array $input)
 | 
			
		||||
    {
 | 
			
		||||
        //If slim.files provided - it will return what was provided
 | 
			
		||||
        $userData['slim.files'] = $input;
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = UploadedFile::createFromGlobals(Environment::mock($userData));
 | 
			
		||||
        $this->assertEquals($input, $uploadedFile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateFromGlobalsWithoutFile()
 | 
			
		||||
    {
 | 
			
		||||
        unset($_FILES);
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = UploadedFile::createFromGlobals(Environment::mock());
 | 
			
		||||
        $this->assertEquals([], $uploadedFile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructor(): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $attr = [
 | 
			
		||||
            'tmp_name' => self::$filename,
 | 
			
		||||
            'name' => 'my-avatar.txt',
 | 
			
		||||
            'size' => 8,
 | 
			
		||||
            'type' => 'text/plain',
 | 
			
		||||
            'error' => 0,
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = new UploadedFile(
 | 
			
		||||
            $attr['tmp_name'],
 | 
			
		||||
            $attr['name'],
 | 
			
		||||
            $attr['type'],
 | 
			
		||||
            $attr['size'],
 | 
			
		||||
            $attr['error'],
 | 
			
		||||
            false
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($attr['name'], $uploadedFile->getClientFilename());
 | 
			
		||||
        $this->assertEquals($attr['type'], $uploadedFile->getClientMediaType());
 | 
			
		||||
        $this->assertEquals($attr['size'], $uploadedFile->getSize());
 | 
			
		||||
        $this->assertEquals($attr['error'], $uploadedFile->getError());
 | 
			
		||||
        $this->assertEquals($attr['tmp_name'], $uploadedFile->getFilePath());
 | 
			
		||||
 | 
			
		||||
        return $uploadedFile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructorSapi(): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $attr = [
 | 
			
		||||
            'tmp_name' => self::$filename,
 | 
			
		||||
            'name' => 'my-avatar.txt',
 | 
			
		||||
            'size' => 8,
 | 
			
		||||
            'type' => 'text/plain',
 | 
			
		||||
            'error' => 0,
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = new UploadedFile(
 | 
			
		||||
            $attr['tmp_name'],
 | 
			
		||||
            $attr['name'],
 | 
			
		||||
            $attr['type'],
 | 
			
		||||
            $attr['size'],
 | 
			
		||||
            $attr['error'],
 | 
			
		||||
            true
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($attr['name'], $uploadedFile->getClientFilename());
 | 
			
		||||
        $this->assertEquals($attr['type'], $uploadedFile->getClientMediaType());
 | 
			
		||||
        $this->assertEquals($attr['size'], $uploadedFile->getSize());
 | 
			
		||||
        $this->assertEquals($attr['error'], $uploadedFile->getError());
 | 
			
		||||
        $this->assertEquals($attr['tmp_name'], $uploadedFile->getFilePath());
 | 
			
		||||
 | 
			
		||||
        return $uploadedFile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     * @return UploadedFile
 | 
			
		||||
     */
 | 
			
		||||
    public function testGetStream(UploadedFile $uploadedFile): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $stream = $uploadedFile->getStream();
 | 
			
		||||
        $this->assertEquals(true, $uploadedFile->getStream() instanceof Stream);
 | 
			
		||||
        $stream->close();
 | 
			
		||||
 | 
			
		||||
        return $uploadedFile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToNotWritable(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = 'some_random_dir' . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     * @return UploadedFile
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveTo(UploadedFile $uploadedFile): UploadedFile
 | 
			
		||||
    {
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
 | 
			
		||||
        $this->assertFileExists($path);
 | 
			
		||||
 | 
			
		||||
        unlink($path);
 | 
			
		||||
 | 
			
		||||
        return $uploadedFile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMoveToRenameFailure()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessageMatches('/^Error moving uploaded file .* to .*$/');
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = $this->generateNewTmpFile();
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
 | 
			
		||||
        $GLOBALS['rename_return'] = false;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructorSapi
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToSapiNonUploadedFile(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testConstructorSapi
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToSapiMoveUploadedFileFails(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessageMatches('~Error moving uploaded file.*~');
 | 
			
		||||
 | 
			
		||||
        $GLOBALS['is_uploaded_file_return'] = true;
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @depends testMoveTo
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToCannotBeDoneTwice(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
        $this->assertFileExists($path);
 | 
			
		||||
        unlink($path);
 | 
			
		||||
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This test must run after testMoveTo
 | 
			
		||||
     *
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMoveToAgain(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $tempName = uniqid('file-');
 | 
			
		||||
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
 | 
			
		||||
        $uploadedFile->moveTo($path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This test must run after testMoveTo
 | 
			
		||||
     *
 | 
			
		||||
     * @depends testConstructor
 | 
			
		||||
     *
 | 
			
		||||
     * @param UploadedFile $uploadedFile
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    public function testMovedStream(UploadedFile $uploadedFile)
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
 | 
			
		||||
        $uploadedFile->getStream();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMoveToStream()
 | 
			
		||||
    {
 | 
			
		||||
        $uploadedFile = $this->generateNewTmpFile();
 | 
			
		||||
 | 
			
		||||
        $fileProperty = new ReflectionProperty($uploadedFile, 'file');
 | 
			
		||||
        $fileProperty->setAccessible(true);
 | 
			
		||||
        $fileName = $fileProperty->getValue($uploadedFile);
 | 
			
		||||
 | 
			
		||||
        $contents = file_get_contents($fileName);
 | 
			
		||||
 | 
			
		||||
        ob_start();
 | 
			
		||||
        $uploadedFile->moveTo('php://output');
 | 
			
		||||
        $movedFileContents = ob_get_clean();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals($contents, $movedFileContents);
 | 
			
		||||
        $this->assertFileDoesNotExist($fileName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testMoveToStreamCopyFailure()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(RuntimeException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Error moving uploaded file  to php://output');
 | 
			
		||||
 | 
			
		||||
        $uploadedFile = $this->generateNewTmpFile();
 | 
			
		||||
 | 
			
		||||
        $GLOBALS['copy_return'] = false;
 | 
			
		||||
        $uploadedFile->moveTo('php://output');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFileUploadWithTempStream()
 | 
			
		||||
    {
 | 
			
		||||
        $streamFactory = function (...$args) {
 | 
			
		||||
            return (new StreamFactory())->createStream(...$args);
 | 
			
		||||
        };
 | 
			
		||||
        $uploadedFileFactory = function (...$args) {
 | 
			
		||||
            return (new UploadedFileFactory())->createUploadedFile(...$args);
 | 
			
		||||
        };
 | 
			
		||||
        $this->runFileUploadWithTempStreamTest($streamFactory, $uploadedFileFactory);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This test sequence has been inspired by UploadedFileFactoryTestCase from http-interop/http-factory-tests package.
 | 
			
		||||
     *
 | 
			
		||||
     * @param callable $streamFactory
 | 
			
		||||
     * @param callable $uploadedFileFactory
 | 
			
		||||
     */
 | 
			
		||||
    private function runFileUploadWithTempStreamTest(callable $streamFactory, callable $uploadedFileFactory)
 | 
			
		||||
    {
 | 
			
		||||
        $content = 'this is your capitan speaking';
 | 
			
		||||
        $error = UPLOAD_ERR_OK;
 | 
			
		||||
        $clientFilename = 'test.txt';
 | 
			
		||||
        $clientMediaType = 'text/plain';
 | 
			
		||||
 | 
			
		||||
        $stream = call_user_func($streamFactory, $content);
 | 
			
		||||
        $file = call_user_func(
 | 
			
		||||
            $uploadedFileFactory,
 | 
			
		||||
            $stream,
 | 
			
		||||
            strlen($content),
 | 
			
		||||
            $error,
 | 
			
		||||
            $clientFilename,
 | 
			
		||||
            $clientMediaType
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->assertInstanceOf(UploadedFileInterface::class, $file);
 | 
			
		||||
        $this->assertSame($content, (string)$file->getStream());
 | 
			
		||||
        $this->assertSame(strlen($content), $file->getSize());
 | 
			
		||||
        $this->assertSame($error, $file->getError());
 | 
			
		||||
        $this->assertSame($clientFilename, $file->getClientFilename());
 | 
			
		||||
        $this->assertSame($clientMediaType, $file->getClientMediaType());
 | 
			
		||||
        $this->assertSame($stream->getMetadata('uri'), $file->getFilePath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateUploadedFileWithInvalidArguments()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        new UploadedFile(42); // a random value that is neither a string nor an instance of StreamInterface
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateUploadedFileWithInvalidUri()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $streamProphecy = $this->prophesize(StreamInterface::class);
 | 
			
		||||
 | 
			
		||||
        /** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
        $streamProphecy
 | 
			
		||||
            ->getMetadata('uri')
 | 
			
		||||
            ->willReturn(null)
 | 
			
		||||
            ->shouldBeCalled();
 | 
			
		||||
        $stream = $streamProphecy->reveal();
 | 
			
		||||
 | 
			
		||||
        // Test with a StreamInterface that returns `null`
 | 
			
		||||
        // when `$stream->getMetadata('uri')` is called (which is an invalid case).
 | 
			
		||||
        new UploadedFile($stream);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function providerCreateFromGlobals(): array
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            // no nest: <input name="avatar" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatar' => [
 | 
			
		||||
                        'tmp_name' => 'phpUxcOty',
 | 
			
		||||
                        'name' => 'my-avatar.png',
 | 
			
		||||
                        'size' => 90996,
 | 
			
		||||
                        'type' => 'image/png',
 | 
			
		||||
                        'error' => 0,
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatar' => new UploadedFile('phpUxcOty', 'my-avatar.png', 'image/png', 90996, UPLOAD_ERR_OK, true)
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
            // no nest, with error: <input name="avatar" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatar' => [
 | 
			
		||||
                        'tmp_name' => 'phpUxcOty',
 | 
			
		||||
                        'name' => 'my-avatar.png',
 | 
			
		||||
                        'size' => 90996,
 | 
			
		||||
                        'type' => 'image/png',
 | 
			
		||||
                        'error' => 7,
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatar' => new UploadedFile(
 | 
			
		||||
                        'phpUxcOty',
 | 
			
		||||
                        'my-avatar.png',
 | 
			
		||||
                        'image/png',
 | 
			
		||||
                        90996,
 | 
			
		||||
                        UPLOAD_ERR_CANT_WRITE,
 | 
			
		||||
                        true
 | 
			
		||||
                    )
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
 | 
			
		||||
            // array of files: <input name="avatars[]" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatars' => [
 | 
			
		||||
                        'tmp_name' => [
 | 
			
		||||
                            0 => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                            1 => __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'name' => [
 | 
			
		||||
                            0 => 'file0.txt',
 | 
			
		||||
                            1 => 'file1.html',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'type' => [
 | 
			
		||||
                            0 => 'text/plain',
 | 
			
		||||
                            1 => 'text/html',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'error' => [
 | 
			
		||||
                            0 => 0,
 | 
			
		||||
                            1 => 0
 | 
			
		||||
                        ],
 | 
			
		||||
                        'size' => [
 | 
			
		||||
                            0 => 0,
 | 
			
		||||
                            1 => 0
 | 
			
		||||
                        ]
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'avatars' => [
 | 
			
		||||
                        0 => new UploadedFile(
 | 
			
		||||
                            __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                            'file0.txt',
 | 
			
		||||
                            'text/plain',
 | 
			
		||||
                            null,
 | 
			
		||||
                            UPLOAD_ERR_OK,
 | 
			
		||||
                            true
 | 
			
		||||
                        ),
 | 
			
		||||
                        1 => new UploadedFile(
 | 
			
		||||
                            __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                            'file1.html',
 | 
			
		||||
                            'text/html',
 | 
			
		||||
                            null,
 | 
			
		||||
                            UPLOAD_ERR_OK,
 | 
			
		||||
                            true
 | 
			
		||||
                        ),
 | 
			
		||||
                    ],
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
            // array of files as multidimensional array: <input name="avatars[]" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    [
 | 
			
		||||
                        'avatars' => [
 | 
			
		||||
                            'tmp_name' => [
 | 
			
		||||
                                0 => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                                1 => __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                            ],
 | 
			
		||||
                            'name' => [
 | 
			
		||||
                                0 => 'file0.txt',
 | 
			
		||||
                                1 => 'file1.html',
 | 
			
		||||
                            ],
 | 
			
		||||
                            'type' => [
 | 
			
		||||
                                0 => 'text/plain',
 | 
			
		||||
                                1 => 'text/html',
 | 
			
		||||
                            ],
 | 
			
		||||
                            'size' => [
 | 
			
		||||
                                0 => 0,
 | 
			
		||||
                                1 => 0,
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    0 =>
 | 
			
		||||
                        [
 | 
			
		||||
                            'avatars' =>
 | 
			
		||||
                                [
 | 
			
		||||
                                    'tmp_name' => [],
 | 
			
		||||
                                    'name' => [],
 | 
			
		||||
                                    'type' => [],
 | 
			
		||||
                                    'size' => [],
 | 
			
		||||
                                ],
 | 
			
		||||
                        ],
 | 
			
		||||
                ],
 | 
			
		||||
            ],
 | 
			
		||||
            // single nested file: <input name="details[avatar]" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                // $_FILES array
 | 
			
		||||
                [
 | 
			
		||||
                    'details' => [
 | 
			
		||||
                        'tmp_name' => [
 | 
			
		||||
                            'avatar' => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'name' => [
 | 
			
		||||
                            'avatar' => 'file0.txt',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'type' => [
 | 
			
		||||
                            'avatar' => 'text/plain',
 | 
			
		||||
                        ],
 | 
			
		||||
                        'error' => [
 | 
			
		||||
                            'avatar' => 0,
 | 
			
		||||
                        ],
 | 
			
		||||
                        'size' => [
 | 
			
		||||
                            'avatar' => 0,
 | 
			
		||||
                        ],
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'details' => [
 | 
			
		||||
                        'avatar' => new UploadedFile(
 | 
			
		||||
                            __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                            'file0.txt',
 | 
			
		||||
                            'text/plain',
 | 
			
		||||
                            null,
 | 
			
		||||
                            UPLOAD_ERR_OK,
 | 
			
		||||
                            true
 | 
			
		||||
                        ),
 | 
			
		||||
                    ],
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
            // nested array of files: <input name="files[details][avatar][]" type="file">
 | 
			
		||||
            [
 | 
			
		||||
                [
 | 
			
		||||
                    'files' => [
 | 
			
		||||
                        'tmp_name' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                                    1 => __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                        'name' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => 'file0.txt',
 | 
			
		||||
                                    1 => 'file1.html',
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                        'type' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => 'text/plain',
 | 
			
		||||
                                    1 => 'text/html',
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                        'error' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => 0,
 | 
			
		||||
                                    1 => 0
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                        'size' => [
 | 
			
		||||
                            'details' => [
 | 
			
		||||
                                'avatar' => [
 | 
			
		||||
                                    0 => 0,
 | 
			
		||||
                                    1 => 0
 | 
			
		||||
                                ],
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                    ],
 | 
			
		||||
                ],
 | 
			
		||||
                // expected format of array
 | 
			
		||||
                [
 | 
			
		||||
                    'files' => [
 | 
			
		||||
                        'details' => [
 | 
			
		||||
                            'avatar' => [
 | 
			
		||||
                                0 => new UploadedFile(
 | 
			
		||||
                                    __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
 | 
			
		||||
                                    'file0.txt',
 | 
			
		||||
                                    'text/plain',
 | 
			
		||||
                                    null,
 | 
			
		||||
                                    UPLOAD_ERR_OK,
 | 
			
		||||
                                    true
 | 
			
		||||
                                ),
 | 
			
		||||
                                1 => new UploadedFile(
 | 
			
		||||
                                    __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
 | 
			
		||||
                                    'file1.html',
 | 
			
		||||
                                    'text/html',
 | 
			
		||||
                                    null,
 | 
			
		||||
                                    UPLOAD_ERR_OK,
 | 
			
		||||
                                    true
 | 
			
		||||
                                ),
 | 
			
		||||
                            ],
 | 
			
		||||
                        ],
 | 
			
		||||
                    ],
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										383
									
								
								qwen/php/vendor/slim/psr7/tests/UriTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										383
									
								
								qwen/php/vendor/slim/psr7/tests/UriTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,383 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace Slim\Tests\Psr7;
 | 
			
		||||
 | 
			
		||||
use InvalidArgumentException;
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Slim\Psr7\Uri;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
class UriTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function uriFactory(): Uri
 | 
			
		||||
    {
 | 
			
		||||
        $scheme = 'https';
 | 
			
		||||
        $host = 'example.com';
 | 
			
		||||
        $port = 443;
 | 
			
		||||
        $path = '/foo/bar';
 | 
			
		||||
        $query = 'abc=123';
 | 
			
		||||
        $fragment = 'section3';
 | 
			
		||||
        $user = 'josh';
 | 
			
		||||
        $password = 'sekrit';
 | 
			
		||||
 | 
			
		||||
        return new Uri($scheme, $host, $port, $path, $query, $fragment, $user, $password);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSupportOtherSchemes()
 | 
			
		||||
    {
 | 
			
		||||
        $wsUri = new class ('ws', 'example.com') extends Uri {
 | 
			
		||||
            public const SUPPORTED_SCHEMES = [
 | 
			
		||||
                'ws' => 80,
 | 
			
		||||
                'wss' => 443,
 | 
			
		||||
            ];
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('ws', $wsUri->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetScheme()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('https', $this->uriFactory()->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithScheme()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withScheme('http');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('http', $uri->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithSchemeRemovesSuffix()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withScheme('http://');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('http', $uri->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithSchemeEmpty()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withScheme('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getScheme());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithSchemeInvalid()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessageMatches('/^Uri scheme must be one of:.*$/');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withScheme('ftp');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithSchemeInvalidType()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri scheme must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withScheme([]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetAuthorityWithUsernameAndPassword()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('josh:sekrit@example.com', $this->uriFactory()->getAuthority());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUserInfo()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withUserInfo('bob', 'pass');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bob:pass', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUserInfoEncodesCorrectly()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withUserInfo('bob@example.com', 'pass:word');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bob%40example.com:pass%3Aword', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUserInfoRemovesPassword()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withUserInfo('bob');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('bob', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithUserInfoRemovesInfo()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withUserInfo('bob', 'password');
 | 
			
		||||
        $uri = $uri->withUserInfo('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getUserInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetHost()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('example.com', $this->uriFactory()->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHost()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withHost('slimframework.com');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('slimframework.com', $uri->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHostValidObject()
 | 
			
		||||
    {
 | 
			
		||||
        $mock = new StringableTestObject('host.test');
 | 
			
		||||
 | 
			
		||||
        $uri = $this->uriFactory()->withHost($mock);
 | 
			
		||||
        $this->assertEquals('host.test', $uri->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithHostInvalidObject()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri host must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withHost(new stdClass());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFilterHost()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = new Uri('http', '2001:db8::1');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('[2001:db8::1]', $uri->getHost());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPortWithSchemeAndNonDefaultPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = new Uri('https', 'www.example.com', 4000);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(4000, $uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPortWithSchemeAndDefaultPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uriHttp = new Uri('http', 'www.example.com', 80);
 | 
			
		||||
        $uriHttps = new Uri('https', 'www.example.com', 443);
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($uriHttp->getPort());
 | 
			
		||||
        $this->assertNull($uriHttps->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPortWithoutSchemeAndPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = new Uri('', 'www.example.com');
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPortWithSchemeWithoutPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = new Uri('http', 'www.example.com');
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPort()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPort(8000);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(8000, $uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPortNull()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPort(null);
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(null, $uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPortInvalidInt()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withPort(70000);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPortInvalidString()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withPort('Foo');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPortIntegerAsString()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPort("199");
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(199, $uri->getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetPath()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('/foo/bar', $this->uriFactory()->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPath()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('/new');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/new', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathWithoutPrefix()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('new');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('new', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathEmptyValue()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathUrlEncodesInput()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('/includes?/new');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/includes%3F/new', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathDoesNotDoubleEncodeInput()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withPath('/include%25s/new');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('/include%25s/new', $uri->getPath());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithPathInvalidType()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri path must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withPath(['foo']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetQuery()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('abc=123', $this->uriFactory()->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQuery()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery('xyz=123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('xyz=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryRemovesPrefix()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery('?xyz=123');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('xyz=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryEmpty()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryValidObject()
 | 
			
		||||
    {
 | 
			
		||||
        $mock = new StringableTestObject('xyz=123');
 | 
			
		||||
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery($mock);
 | 
			
		||||
        $this->assertEquals('xyz=123', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testFilterQuery()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withQuery('?foobar=%match');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('foobar=%25match', $uri->getQuery());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithQueryInvalidType()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri query must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withQuery(['foo']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetFragment()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('section3', $this->uriFactory()->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragment()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment('other-fragment');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('other-fragment', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentRemovesPrefix()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment('#other-fragment');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('other-fragment', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentEmpty()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment('');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentValidObject()
 | 
			
		||||
    {
 | 
			
		||||
        $mock = new StringableTestObject('other-fragment');
 | 
			
		||||
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment($mock);
 | 
			
		||||
        $this->assertEquals('other-fragment', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentUrlEncode()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory()->withFragment('^a');
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('%5Ea', $uri->getFragment());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testWithFragmentInvalidType()
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(InvalidArgumentException::class);
 | 
			
		||||
        $this->expectExceptionMessage('Uri fragment must be a string');
 | 
			
		||||
 | 
			
		||||
        $this->uriFactory()->withFragment(['foo']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testToString()
 | 
			
		||||
    {
 | 
			
		||||
        $uri = $this->uriFactory();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals('https://josh:sekrit@example.com/foo/bar?abc=123#section3', (string) $uri);
 | 
			
		||||
 | 
			
		||||
        $uri = $uri->withPath('bar');
 | 
			
		||||
        $this->assertEquals('https://josh:sekrit@example.com/bar?abc=123#section3', (string) $uri);
 | 
			
		||||
 | 
			
		||||
        $uri = $uri->withPath('/bar');
 | 
			
		||||
        $this->assertEquals('https://josh:sekrit@example.com/bar?abc=123#section3', (string) $uri);
 | 
			
		||||
 | 
			
		||||
        $uri = $uri->withScheme('')->withHost('')->withPort(null)->withUserInfo('')->withPath('//bar');
 | 
			
		||||
        $this->assertEquals('/bar?abc=123#section3', (string) $uri);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										99
									
								
								qwen/php/vendor/slim/psr7/tests/bootstrap.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								qwen/php/vendor/slim/psr7/tests/bootstrap.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,99 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Slim Framework (https://slimframework.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
use AdrianSuter\Autoload\Override\Override;
 | 
			
		||||
use Slim\Psr7\Factory;
 | 
			
		||||
use Slim\Psr7\Headers;
 | 
			
		||||
use Slim\Psr7\Message;
 | 
			
		||||
use Slim\Psr7\NonBufferedBody;
 | 
			
		||||
use Slim\Psr7\UploadedFile;
 | 
			
		||||
use Slim\Tests\Psr7\Assets\HeaderStack;
 | 
			
		||||
 | 
			
		||||
$classLoader = require __DIR__ . '/../vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
Override::apply($classLoader, [
 | 
			
		||||
    Headers::class => [
 | 
			
		||||
        'getallheaders' => function () {
 | 
			
		||||
            if (array_key_exists('getallheaders_return', $GLOBALS)) {
 | 
			
		||||
                return $GLOBALS['getallheaders_return'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return getallheaders();
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    Message::class => [
 | 
			
		||||
        'header' => function (string $string, bool $replace = true, ?int $statusCode = null): void {
 | 
			
		||||
            HeaderStack::push(
 | 
			
		||||
                [
 | 
			
		||||
                    'header'      => $string,
 | 
			
		||||
                    'replace'     => $replace,
 | 
			
		||||
                    'status_code' => $statusCode,
 | 
			
		||||
                ]
 | 
			
		||||
            );
 | 
			
		||||
        },
 | 
			
		||||
        'header_remove' => function ($name = null): void {
 | 
			
		||||
            HeaderStack::remove($name);
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    NonBufferedBody::class => [
 | 
			
		||||
        'ob_get_level' => function (): int {
 | 
			
		||||
            if (isset($GLOBALS['ob_get_level_shift'])) {
 | 
			
		||||
                return ob_get_level() + $GLOBALS['ob_get_level_shift'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return ob_get_level();
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    UploadedFile::class => [
 | 
			
		||||
        'copy' => function (string $source, string $destination, $context = null): bool {
 | 
			
		||||
            if (isset($GLOBALS['copy_return'])) {
 | 
			
		||||
                return $GLOBALS['copy_return'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if ($context === null) {
 | 
			
		||||
                return copy($source, $destination);
 | 
			
		||||
            }
 | 
			
		||||
            return copy($source, $destination, $context);
 | 
			
		||||
        },
 | 
			
		||||
        'is_uploaded_file' => function (string $filename): bool {
 | 
			
		||||
            if (isset($GLOBALS['is_uploaded_file_return'])) {
 | 
			
		||||
                return $GLOBALS['is_uploaded_file_return'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return is_uploaded_file($filename);
 | 
			
		||||
        },
 | 
			
		||||
        'rename' => function (string $oldName, string $newName, $context = null): bool {
 | 
			
		||||
            if (isset($GLOBALS['rename_return'])) {
 | 
			
		||||
                return $GLOBALS['rename_return'];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if ($context === null) {
 | 
			
		||||
                return rename($oldName, $newName);
 | 
			
		||||
            }
 | 
			
		||||
            return rename($oldName, $newName, $context = null);
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    Factory\StreamFactory::class => [
 | 
			
		||||
        'fopen' => function (string $filename, string $mode) {
 | 
			
		||||
            if (isset($GLOBALS['fopen_return'])) {
 | 
			
		||||
                return isset($GLOBALS['fopen_return']);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return fopen($filename, $mode);
 | 
			
		||||
        },
 | 
			
		||||
        'is_readable' => function (string $filename) {
 | 
			
		||||
            if ($filename === 'non-readable') {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return is_readable($filename);
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
]);
 | 
			
		||||
		Reference in New Issue
	
	Block a user