init
- 框架初始化 - 安装插件 - 修复PHP8.4报错
This commit is contained in:
25
vendor/symfony/psr-http-message-bridge/.php-cs-fixer.dist.php
vendored
Normal file
25
vendor/symfony/psr-http-message-bridge/.php-cs-fixer.dist.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
return (new PhpCsFixer\Config())
|
||||
->setRules([
|
||||
'@Symfony' => true,
|
||||
'@Symfony:risky' => true,
|
||||
'@PHPUnit48Migration:risky' => true,
|
||||
'php_unit_no_expectation_annotation' => false, // part of `PHPUnitXYMigration:risky` ruleset, to be enabled when PHPUnit 4.x support will be dropped, as we don't want to rewrite exceptions handling twice
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'fopen_flags' => false,
|
||||
'ordered_imports' => true,
|
||||
'protected_to_private' => false,
|
||||
// Part of @Symfony:risky in PHP-CS-Fixer 2.13.0. To be removed from the config file once upgrading
|
||||
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
|
||||
// Part of future @Symfony ruleset in PHP-CS-Fixer To be removed from the config file once upgrading
|
||||
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
|
||||
])
|
||||
->setRiskyAllowed(true)
|
||||
->setFinder(
|
||||
(new PhpCsFixer\Finder())
|
||||
->in(__DIR__)
|
||||
->exclude('vendor')
|
||||
->name('*.php')
|
||||
)
|
||||
;
|
||||
67
vendor/symfony/psr-http-message-bridge/ArgumentValueResolver/PsrServerRequestResolver.php
vendored
Normal file
67
vendor/symfony/psr-http-message-bridge/ArgumentValueResolver/PsrServerRequestResolver.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver;
|
||||
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
|
||||
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface as BaseValueResolverInterface;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
||||
|
||||
/**
|
||||
* Injects the RequestInterface, MessageInterface or ServerRequestInterface when requested.
|
||||
*
|
||||
* @author Iltar van der Berg <kjarli@gmail.com>
|
||||
* @author Alexander M. Turek <me@derrabus.de>
|
||||
*/
|
||||
final class PsrServerRequestResolver implements ArgumentValueResolverInterface, ValueResolverInterface
|
||||
{
|
||||
private const SUPPORTED_TYPES = [
|
||||
ServerRequestInterface::class => true,
|
||||
RequestInterface::class => true,
|
||||
MessageInterface::class => true,
|
||||
];
|
||||
|
||||
private $httpMessageFactory;
|
||||
|
||||
public function __construct(HttpMessageFactoryInterface $httpMessageFactory)
|
||||
{
|
||||
$this->httpMessageFactory = $httpMessageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports(Request $request, ArgumentMetadata $argument): bool
|
||||
{
|
||||
if ($this instanceof BaseValueResolverInterface) {
|
||||
trigger_deprecation('symfony/psr-http-message-bridge', '2.3', 'Method "%s" is deprecated, call "resolve()" without calling "supports()" first.', __METHOD__);
|
||||
}
|
||||
|
||||
return self::SUPPORTED_TYPES[$argument->getType()] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resolve(Request $request, ArgumentMetadata $argument): \Traversable
|
||||
{
|
||||
if (!isset(self::SUPPORTED_TYPES[$argument->getType()])) {
|
||||
return;
|
||||
}
|
||||
|
||||
yield $this->httpMessageFactory->createRequest($request);
|
||||
}
|
||||
}
|
||||
26
vendor/symfony/psr-http-message-bridge/ArgumentValueResolver/ValueResolverInterface.php
vendored
Normal file
26
vendor/symfony/psr-http-message-bridge/ArgumentValueResolver/ValueResolverInterface.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver;
|
||||
|
||||
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface as BaseValueResolverInterface;
|
||||
|
||||
if (interface_exists(BaseValueResolverInterface::class)) {
|
||||
/** @internal */
|
||||
interface ValueResolverInterface extends BaseValueResolverInterface
|
||||
{
|
||||
}
|
||||
} else {
|
||||
/** @internal */
|
||||
interface ValueResolverInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
85
vendor/symfony/psr-http-message-bridge/CHANGELOG.md
vendored
Normal file
85
vendor/symfony/psr-http-message-bridge/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
# 2.3.1 (2023-07-26)
|
||||
|
||||
* Don't rely on `Request::getPayload()` to populate the parsed body
|
||||
|
||||
# 2.3.0 (2023-07-25)
|
||||
|
||||
* Leverage `Request::getPayload()` to populate the parsed body of PSR-7 requests
|
||||
* Implement `ValueResolverInterface` introduced with Symfony 6.2
|
||||
|
||||
# 2.2.0 (2023-04-21)
|
||||
|
||||
* Drop support for Symfony 4
|
||||
* Bump minimum version of PHP to 7.2
|
||||
* Support version 2 of the psr/http-message contracts
|
||||
|
||||
# 2.1.3 (2022-09-05)
|
||||
|
||||
* Ignore invalid HTTP headers when creating PSR7 objects
|
||||
* Fix for wrong type passed to `moveTo()`
|
||||
|
||||
# 2.1.2 (2021-11-05)
|
||||
|
||||
* Allow Symfony 6
|
||||
|
||||
# 2.1.0 (2021-02-17)
|
||||
|
||||
* Added a `PsrResponseListener` to automatically convert PSR-7 responses returned by controllers
|
||||
* Added a `PsrServerRequestResolver` that allows injecting PSR-7 request objects into controllers
|
||||
|
||||
# 2.0.2 (2020-09-29)
|
||||
|
||||
* Fix populating server params from URI in HttpFoundationFactory
|
||||
* Create cookies as raw in HttpFoundationFactory
|
||||
* Fix BinaryFileResponse with Content-Range PsrHttpFactory
|
||||
|
||||
# 2.0.1 (2020-06-25)
|
||||
|
||||
* Don't normalize query string in PsrHttpFactory
|
||||
* Fix conversion for HTTPS requests
|
||||
* Fix populating default port and headers in HttpFoundationFactory
|
||||
|
||||
# 2.0.0 (2020-01-02)
|
||||
|
||||
* Remove DiactorosFactory
|
||||
|
||||
# 1.3.0 (2019-11-25)
|
||||
|
||||
* Added support for streamed requests
|
||||
* Added support for Symfony 5.0+
|
||||
* Fixed bridging UploadedFile objects
|
||||
* Bumped minimum version of Symfony to 4.4
|
||||
|
||||
# 1.2.0 (2019-03-11)
|
||||
|
||||
* Added new documentation links
|
||||
* Bumped minimum version of PHP to 7.1
|
||||
* Added support for streamed responses
|
||||
|
||||
# 1.1.2 (2019-04-03)
|
||||
|
||||
* Fixed createResponse
|
||||
|
||||
# 1.1.1 (2019-03-11)
|
||||
|
||||
* Deprecated DiactorosFactory, use PsrHttpFactory instead
|
||||
* Removed triggering of deprecation
|
||||
|
||||
# 1.1.0 (2018-08-30)
|
||||
|
||||
* Added support for creating PSR-7 messages using PSR-17 factories
|
||||
|
||||
# 1.0.2 (2017-12-19)
|
||||
|
||||
* Fixed request target in PSR7 Request (mtibben)
|
||||
|
||||
# 1.0.1 (2017-12-04)
|
||||
|
||||
* Added support for Symfony 4 (dunglas)
|
||||
|
||||
# 1.0.0 (2016-09-14)
|
||||
|
||||
* Initial release
|
||||
50
vendor/symfony/psr-http-message-bridge/EventListener/PsrResponseListener.php
vendored
Normal file
50
vendor/symfony/psr-http-message-bridge/EventListener/PsrResponseListener.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\EventListener;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
|
||||
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\ViewEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
/**
|
||||
* Converts PSR-7 Response to HttpFoundation Response using the bridge.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
* @author Alexander M. Turek <me@derrabus.de>
|
||||
*/
|
||||
final class PsrResponseListener implements EventSubscriberInterface
|
||||
{
|
||||
private $httpFoundationFactory;
|
||||
|
||||
public function __construct(HttpFoundationFactoryInterface $httpFoundationFactory = null)
|
||||
{
|
||||
$this->httpFoundationFactory = $httpFoundationFactory ?? new HttpFoundationFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the conversion if applicable and update the response of the event.
|
||||
*/
|
||||
public function onKernelView(ViewEvent $event): void
|
||||
{
|
||||
$controllerResult = $event->getControllerResult();
|
||||
|
||||
if (!$controllerResult instanceof ResponseInterface) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->setResponse($this->httpFoundationFactory->createResponse($controllerResult));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
KernelEvents::VIEW => 'onKernelView',
|
||||
];
|
||||
}
|
||||
}
|
||||
252
vendor/symfony/psr-http-message-bridge/Factory/HttpFoundationFactory.php
vendored
Normal file
252
vendor/symfony/psr-http-message-bridge/Factory/HttpFoundationFactory.php
vendored
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Factory;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class HttpFoundationFactory implements HttpFoundationFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @var int The maximum output buffering size for each iteration when sending the response
|
||||
*/
|
||||
private $responseBufferMaxLength;
|
||||
|
||||
public function __construct(int $responseBufferMaxLength = 16372)
|
||||
{
|
||||
$this->responseBufferMaxLength = $responseBufferMaxLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function createRequest(ServerRequestInterface $psrRequest, bool $streamed = false)
|
||||
{
|
||||
$server = [];
|
||||
$uri = $psrRequest->getUri();
|
||||
|
||||
if ($uri instanceof UriInterface) {
|
||||
$server['SERVER_NAME'] = $uri->getHost();
|
||||
$server['SERVER_PORT'] = $uri->getPort() ?: ('https' === $uri->getScheme() ? 443 : 80);
|
||||
$server['REQUEST_URI'] = $uri->getPath();
|
||||
$server['QUERY_STRING'] = $uri->getQuery();
|
||||
|
||||
if ('' !== $server['QUERY_STRING']) {
|
||||
$server['REQUEST_URI'] .= '?'.$server['QUERY_STRING'];
|
||||
}
|
||||
|
||||
if ('https' === $uri->getScheme()) {
|
||||
$server['HTTPS'] = 'on';
|
||||
}
|
||||
}
|
||||
|
||||
$server['REQUEST_METHOD'] = $psrRequest->getMethod();
|
||||
|
||||
$server = array_replace($psrRequest->getServerParams(), $server);
|
||||
|
||||
$parsedBody = $psrRequest->getParsedBody();
|
||||
$parsedBody = \is_array($parsedBody) ? $parsedBody : [];
|
||||
|
||||
$request = new Request(
|
||||
$psrRequest->getQueryParams(),
|
||||
$parsedBody,
|
||||
$psrRequest->getAttributes(),
|
||||
$psrRequest->getCookieParams(),
|
||||
$this->getFiles($psrRequest->getUploadedFiles()),
|
||||
$server,
|
||||
$streamed ? $psrRequest->getBody()->detach() : $psrRequest->getBody()->__toString()
|
||||
);
|
||||
$request->headers->add($psrRequest->getHeaders());
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to the input array to $_FILES structure.
|
||||
*/
|
||||
private function getFiles(array $uploadedFiles): array
|
||||
{
|
||||
$files = [];
|
||||
|
||||
foreach ($uploadedFiles as $key => $value) {
|
||||
if ($value instanceof UploadedFileInterface) {
|
||||
$files[$key] = $this->createUploadedFile($value);
|
||||
} else {
|
||||
$files[$key] = $this->getFiles($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Symfony UploadedFile instance from PSR-7 ones.
|
||||
*/
|
||||
private function createUploadedFile(UploadedFileInterface $psrUploadedFile): UploadedFile
|
||||
{
|
||||
return new UploadedFile($psrUploadedFile, function () { return $this->getTemporaryPath(); });
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a temporary file path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTemporaryPath()
|
||||
{
|
||||
return tempnam(sys_get_temp_dir(), uniqid('symfony', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function createResponse(ResponseInterface $psrResponse, bool $streamed = false)
|
||||
{
|
||||
$cookies = $psrResponse->getHeader('Set-Cookie');
|
||||
$psrResponse = $psrResponse->withoutHeader('Set-Cookie');
|
||||
|
||||
if ($streamed) {
|
||||
$response = new StreamedResponse(
|
||||
$this->createStreamedResponseCallback($psrResponse->getBody()),
|
||||
$psrResponse->getStatusCode(),
|
||||
$psrResponse->getHeaders()
|
||||
);
|
||||
} else {
|
||||
$response = new Response(
|
||||
$psrResponse->getBody()->__toString(),
|
||||
$psrResponse->getStatusCode(),
|
||||
$psrResponse->getHeaders()
|
||||
);
|
||||
}
|
||||
|
||||
$response->setProtocolVersion($psrResponse->getProtocolVersion());
|
||||
|
||||
foreach ($cookies as $cookie) {
|
||||
$response->headers->setCookie($this->createCookie($cookie));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Cookie instance from a cookie string.
|
||||
*
|
||||
* Some snippets have been taken from the Guzzle project: https://github.com/guzzle/guzzle/blob/5.3/src/Cookie/SetCookie.php#L34
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private function createCookie(string $cookie): Cookie
|
||||
{
|
||||
foreach (explode(';', $cookie) as $part) {
|
||||
$part = trim($part);
|
||||
|
||||
$data = explode('=', $part, 2);
|
||||
$name = $data[0];
|
||||
$value = isset($data[1]) ? trim($data[1], " \n\r\t\0\x0B\"") : null;
|
||||
|
||||
if (!isset($cookieName)) {
|
||||
$cookieName = $name;
|
||||
$cookieValue = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('expires' === strtolower($name) && null !== $value) {
|
||||
$cookieExpire = new \DateTime($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('path' === strtolower($name) && null !== $value) {
|
||||
$cookiePath = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('domain' === strtolower($name) && null !== $value) {
|
||||
$cookieDomain = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('secure' === strtolower($name)) {
|
||||
$cookieSecure = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('httponly' === strtolower($name)) {
|
||||
$cookieHttpOnly = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('samesite' === strtolower($name) && null !== $value) {
|
||||
$samesite = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($cookieName)) {
|
||||
throw new \InvalidArgumentException('The value of the Set-Cookie header is malformed.');
|
||||
}
|
||||
|
||||
return new Cookie(
|
||||
$cookieName,
|
||||
$cookieValue,
|
||||
$cookieExpire ?? 0,
|
||||
$cookiePath ?? '/',
|
||||
$cookieDomain ?? null,
|
||||
isset($cookieSecure),
|
||||
isset($cookieHttpOnly),
|
||||
true,
|
||||
$samesite ?? null
|
||||
);
|
||||
}
|
||||
|
||||
private function createStreamedResponseCallback(StreamInterface $body): callable
|
||||
{
|
||||
return function () use ($body) {
|
||||
if ($body->isSeekable()) {
|
||||
$body->rewind();
|
||||
}
|
||||
|
||||
if (!$body->isReadable()) {
|
||||
echo $body;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
while (!$body->eof()) {
|
||||
echo $body->read($this->responseBufferMaxLength);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
198
vendor/symfony/psr-http-message-bridge/Factory/PsrHttpFactory.php
vendored
Normal file
198
vendor/symfony/psr-http-message-bridge/Factory/PsrHttpFactory.php
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Factory;
|
||||
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestFactoryInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\StreamFactoryInterface;
|
||||
use Psr\Http\Message\UploadedFileFactoryInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
/**
|
||||
* Builds Psr\HttpMessage instances using a PSR-17 implementation.
|
||||
*
|
||||
* @author Antonio J. García Lagar <aj@garcialagar.es>
|
||||
* @author Aurélien Pillevesse <aurelienpillevesse@hotmail.fr>
|
||||
*/
|
||||
class PsrHttpFactory implements HttpMessageFactoryInterface
|
||||
{
|
||||
private $serverRequestFactory;
|
||||
private $streamFactory;
|
||||
private $uploadedFileFactory;
|
||||
private $responseFactory;
|
||||
|
||||
public function __construct(ServerRequestFactoryInterface $serverRequestFactory, StreamFactoryInterface $streamFactory, UploadedFileFactoryInterface $uploadedFileFactory, ResponseFactoryInterface $responseFactory)
|
||||
{
|
||||
$this->serverRequestFactory = $serverRequestFactory;
|
||||
$this->streamFactory = $streamFactory;
|
||||
$this->uploadedFileFactory = $uploadedFileFactory;
|
||||
$this->responseFactory = $responseFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return ServerRequestInterface
|
||||
*/
|
||||
public function createRequest(Request $symfonyRequest)
|
||||
{
|
||||
$uri = $symfonyRequest->server->get('QUERY_STRING', '');
|
||||
$uri = $symfonyRequest->getSchemeAndHttpHost().$symfonyRequest->getBaseUrl().$symfonyRequest->getPathInfo().('' !== $uri ? '?'.$uri : '');
|
||||
|
||||
$request = $this->serverRequestFactory->createServerRequest(
|
||||
$symfonyRequest->getMethod(),
|
||||
$uri,
|
||||
$symfonyRequest->server->all()
|
||||
);
|
||||
|
||||
foreach ($symfonyRequest->headers->all() as $name => $value) {
|
||||
try {
|
||||
$request = $request->withHeader($name, $value);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// ignore invalid header
|
||||
}
|
||||
}
|
||||
|
||||
$body = $this->streamFactory->createStreamFromResource($symfonyRequest->getContent(true));
|
||||
|
||||
if (method_exists(Request::class, 'getContentTypeFormat')) {
|
||||
$format = $symfonyRequest->getContentTypeFormat();
|
||||
} else {
|
||||
$format = $symfonyRequest->getContentType();
|
||||
}
|
||||
|
||||
if ('json' === $format) {
|
||||
$parsedBody = json_decode($symfonyRequest->getContent(), true, 512, \JSON_BIGINT_AS_STRING);
|
||||
|
||||
if (!\is_array($parsedBody)) {
|
||||
$parsedBody = null;
|
||||
}
|
||||
} else {
|
||||
$parsedBody = $symfonyRequest->request->all();
|
||||
}
|
||||
|
||||
$request = $request
|
||||
->withBody($body)
|
||||
->withUploadedFiles($this->getFiles($symfonyRequest->files->all()))
|
||||
->withCookieParams($symfonyRequest->cookies->all())
|
||||
->withQueryParams($symfonyRequest->query->all())
|
||||
->withParsedBody($parsedBody)
|
||||
;
|
||||
|
||||
foreach ($symfonyRequest->attributes->all() as $key => $value) {
|
||||
$request = $request->withAttribute($key, $value);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts Symfony uploaded files array to the PSR one.
|
||||
*/
|
||||
private function getFiles(array $uploadedFiles): array
|
||||
{
|
||||
$files = [];
|
||||
|
||||
foreach ($uploadedFiles as $key => $value) {
|
||||
if (null === $value) {
|
||||
$files[$key] = $this->uploadedFileFactory->createUploadedFile($this->streamFactory->createStream(), 0, \UPLOAD_ERR_NO_FILE);
|
||||
continue;
|
||||
}
|
||||
if ($value instanceof UploadedFile) {
|
||||
$files[$key] = $this->createUploadedFile($value);
|
||||
} else {
|
||||
$files[$key] = $this->getFiles($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PSR-7 UploadedFile instance from a Symfony one.
|
||||
*/
|
||||
private function createUploadedFile(UploadedFile $symfonyUploadedFile): UploadedFileInterface
|
||||
{
|
||||
return $this->uploadedFileFactory->createUploadedFile(
|
||||
$this->streamFactory->createStreamFromFile(
|
||||
$symfonyUploadedFile->getRealPath()
|
||||
),
|
||||
(int) $symfonyUploadedFile->getSize(),
|
||||
$symfonyUploadedFile->getError(),
|
||||
$symfonyUploadedFile->getClientOriginalName(),
|
||||
$symfonyUploadedFile->getClientMimeType()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function createResponse(Response $symfonyResponse)
|
||||
{
|
||||
$response = $this->responseFactory->createResponse($symfonyResponse->getStatusCode(), Response::$statusTexts[$symfonyResponse->getStatusCode()] ?? '');
|
||||
|
||||
if ($symfonyResponse instanceof BinaryFileResponse && !$symfonyResponse->headers->has('Content-Range')) {
|
||||
$stream = $this->streamFactory->createStreamFromFile(
|
||||
$symfonyResponse->getFile()->getPathname()
|
||||
);
|
||||
} else {
|
||||
$stream = $this->streamFactory->createStreamFromFile('php://temp', 'wb+');
|
||||
if ($symfonyResponse instanceof StreamedResponse || $symfonyResponse instanceof BinaryFileResponse) {
|
||||
ob_start(function ($buffer) use ($stream) {
|
||||
$stream->write($buffer);
|
||||
|
||||
return '';
|
||||
}, 1);
|
||||
|
||||
$symfonyResponse->sendContent();
|
||||
ob_end_clean();
|
||||
} else {
|
||||
$stream->write($symfonyResponse->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
$response = $response->withBody($stream);
|
||||
|
||||
$headers = $symfonyResponse->headers->all();
|
||||
$cookies = $symfonyResponse->headers->getCookies();
|
||||
if (!empty($cookies)) {
|
||||
$headers['Set-Cookie'] = [];
|
||||
|
||||
foreach ($cookies as $cookie) {
|
||||
$headers['Set-Cookie'][] = $cookie->__toString();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($headers as $name => $value) {
|
||||
try {
|
||||
$response = $response->withHeader($name, $value);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// ignore invalid header
|
||||
}
|
||||
}
|
||||
|
||||
$protocolVersion = $symfonyResponse->getProtocolVersion();
|
||||
$response = $response->withProtocolVersion($protocolVersion);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
73
vendor/symfony/psr-http-message-bridge/Factory/UploadedFile.php
vendored
Normal file
73
vendor/symfony/psr-http-message-bridge/Factory/UploadedFile.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Factory;
|
||||
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile as BaseUploadedFile;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class UploadedFile extends BaseUploadedFile
|
||||
{
|
||||
private $psrUploadedFile;
|
||||
private $test = false;
|
||||
|
||||
public function __construct(UploadedFileInterface $psrUploadedFile, callable $getTemporaryPath)
|
||||
{
|
||||
$error = $psrUploadedFile->getError();
|
||||
$path = '';
|
||||
|
||||
if (\UPLOAD_ERR_NO_FILE !== $error) {
|
||||
$path = $psrUploadedFile->getStream()->getMetadata('uri') ?? '';
|
||||
|
||||
if ($this->test = !\is_string($path) || !is_uploaded_file($path)) {
|
||||
$path = $getTemporaryPath();
|
||||
$psrUploadedFile->moveTo($path);
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct(
|
||||
$path,
|
||||
(string) $psrUploadedFile->getClientFilename(),
|
||||
$psrUploadedFile->getClientMediaType(),
|
||||
$psrUploadedFile->getError(),
|
||||
$this->test
|
||||
);
|
||||
|
||||
$this->psrUploadedFile = $psrUploadedFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function move(string $directory, ?string $name = null): File
|
||||
{
|
||||
if (!$this->isValid() || $this->test) {
|
||||
return parent::move($directory, $name);
|
||||
}
|
||||
|
||||
$target = $this->getTargetFile($directory, $name);
|
||||
|
||||
try {
|
||||
$this->psrUploadedFile->moveTo((string) $target);
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, $e->getMessage()), 0, $e);
|
||||
}
|
||||
|
||||
@chmod($target, 0666 & ~umask());
|
||||
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
39
vendor/symfony/psr-http-message-bridge/HttpFoundationFactoryInterface.php
vendored
Normal file
39
vendor/symfony/psr-http-message-bridge/HttpFoundationFactoryInterface.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Creates Symfony Request and Response instances from PSR-7 ones.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
interface HttpFoundationFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Creates a Symfony Request instance from a PSR-7 one.
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function createRequest(ServerRequestInterface $psrRequest, bool $streamed = false);
|
||||
|
||||
/**
|
||||
* Creates a Symfony Response instance from a PSR-7 one.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function createResponse(ResponseInterface $psrResponse, bool $streamed = false);
|
||||
}
|
||||
39
vendor/symfony/psr-http-message-bridge/HttpMessageFactoryInterface.php
vendored
Normal file
39
vendor/symfony/psr-http-message-bridge/HttpMessageFactoryInterface.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Creates PSR HTTP Request and Response instances from Symfony ones.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
interface HttpMessageFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Creates a PSR-7 Request instance from a Symfony one.
|
||||
*
|
||||
* @return ServerRequestInterface
|
||||
*/
|
||||
public function createRequest(Request $symfonyRequest);
|
||||
|
||||
/**
|
||||
* Creates a PSR-7 Response instance from a Symfony one.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function createResponse(Response $symfonyResponse);
|
||||
}
|
||||
19
vendor/symfony/psr-http-message-bridge/LICENSE
vendored
Normal file
19
vendor/symfony/psr-http-message-bridge/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2004-2021 Fabien Potencier
|
||||
|
||||
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.
|
||||
19
vendor/symfony/psr-http-message-bridge/README.md
vendored
Normal file
19
vendor/symfony/psr-http-message-bridge/README.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
PSR-7 Bridge
|
||||
============
|
||||
|
||||
Provides integration for PSR7.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
* [Documentation](https://symfony.com/doc/current/components/psr7.html)
|
||||
|
||||
Running the tests
|
||||
-----------------
|
||||
|
||||
If you want to run the unit tests, install dev dependencies before
|
||||
running PHPUnit:
|
||||
|
||||
$ cd path/to/Symfony/Bridge/PsrHttpMessage/
|
||||
$ composer.phar install
|
||||
$ phpunit
|
||||
48
vendor/symfony/psr-http-message-bridge/composer.json
vendored
Normal file
48
vendor/symfony/psr-http-message-bridge/composer.json
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "symfony/psr-http-message-bridge",
|
||||
"type": "symfony-bridge",
|
||||
"description": "PSR HTTP message bridge",
|
||||
"keywords": ["http", "psr-7", "psr-17", "http-message"],
|
||||
"homepage": "http://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "http://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"psr/http-message": "^1.0 || ^2.0",
|
||||
"symfony/deprecation-contracts": "^2.5 || ^3.0",
|
||||
"symfony/http-foundation": "^5.4 || ^6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/browser-kit": "^5.4 || ^6.0",
|
||||
"symfony/config": "^5.4 || ^6.0",
|
||||
"symfony/event-dispatcher": "^5.4 || ^6.0",
|
||||
"symfony/framework-bundle": "^5.4 || ^6.0",
|
||||
"symfony/http-kernel": "^5.4 || ^6.0",
|
||||
"symfony/phpunit-bridge": "^6.2",
|
||||
"nyholm/psr7": "^1.1",
|
||||
"psr/log": "^1.1 || ^2 || ^3"
|
||||
},
|
||||
"suggest": {
|
||||
"nyholm/psr7": "For a super lightweight PSR-7/17 implementation"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Bridge\\PsrHttpMessage\\": "" },
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "2.3-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user