初始化仓库
This commit is contained in:
53
vendor/nyholm/psr7/src/Factory/HttplugFactory.php
vendored
Normal file
53
vendor/nyholm/psr7/src/Factory/HttplugFactory.php
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Nyholm\Psr7\Factory;
|
||||
|
||||
use Http\Message\{MessageFactory, StreamFactory, UriFactory};
|
||||
use Nyholm\Psr7\{Request, Response, Stream, Uri};
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
if (!\interface_exists(MessageFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Nyholm\Psr7\Factory\HttplugFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
@\trigger_error('Class "Nyholm\Psr7\Factory\HttplugFactory" is deprecated since version 1.8, use "Nyholm\Psr7\Factory\Psr17Factory" instead.', \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
* @author Martijn van der Ven <martijn@vanderven.se>
|
||||
*
|
||||
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
|
||||
*
|
||||
* @deprecated since version 1.8, use Psr17Factory instead
|
||||
*/
|
||||
class HttplugFactory implements MessageFactory, StreamFactory, UriFactory
|
||||
{
|
||||
public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1'): RequestInterface
|
||||
{
|
||||
return new Request($method, $uri, $headers, $body, $protocolVersion);
|
||||
}
|
||||
|
||||
public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $version = '1.1'): ResponseInterface
|
||||
{
|
||||
return new Response((int) $statusCode, $headers, $body, $version, $reasonPhrase);
|
||||
}
|
||||
|
||||
public function createStream($body = null): StreamInterface
|
||||
{
|
||||
return Stream::create($body ?? '');
|
||||
}
|
||||
|
||||
public function createUri($uri = ''): UriInterface
|
||||
{
|
||||
if ($uri instanceof UriInterface) {
|
||||
return $uri;
|
||||
}
|
||||
|
||||
return new Uri($uri);
|
||||
}
|
||||
}
|
||||
78
vendor/nyholm/psr7/src/Factory/Psr17Factory.php
vendored
Normal file
78
vendor/nyholm/psr7/src/Factory/Psr17Factory.php
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Nyholm\Psr7\Factory;
|
||||
|
||||
use Nyholm\Psr7\{Request, Response, ServerRequest, Stream, UploadedFile, Uri};
|
||||
use Psr\Http\Message\{RequestFactoryInterface, RequestInterface, ResponseFactoryInterface, ResponseInterface, ServerRequestFactoryInterface, ServerRequestInterface, StreamFactoryInterface, StreamInterface, UploadedFileFactoryInterface, UploadedFileInterface, UriFactoryInterface, UriInterface};
|
||||
|
||||
/**
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
* @author Martijn van der Ven <martijn@vanderven.se>
|
||||
*
|
||||
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
|
||||
*/
|
||||
class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
|
||||
{
|
||||
public function createRequest(string $method, $uri): RequestInterface
|
||||
{
|
||||
return new Request($method, $uri);
|
||||
}
|
||||
|
||||
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
|
||||
{
|
||||
if (2 > \func_num_args()) {
|
||||
// This will make the Response class to use a custom reasonPhrase
|
||||
$reasonPhrase = null;
|
||||
}
|
||||
|
||||
return new Response($code, [], null, '1.1', $reasonPhrase);
|
||||
}
|
||||
|
||||
public function createStream(string $content = ''): StreamInterface
|
||||
{
|
||||
return Stream::create($content);
|
||||
}
|
||||
|
||||
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
|
||||
{
|
||||
if ('' === $filename) {
|
||||
throw new \RuntimeException('Path cannot be empty');
|
||||
}
|
||||
|
||||
if (false === $resource = @\fopen($filename, $mode)) {
|
||||
if ('' === $mode || false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], true)) {
|
||||
throw new \InvalidArgumentException(\sprintf('The mode "%s" is invalid.', $mode));
|
||||
}
|
||||
|
||||
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $filename, \error_get_last()['message'] ?? ''));
|
||||
}
|
||||
|
||||
return Stream::create($resource);
|
||||
}
|
||||
|
||||
public function createStreamFromResource($resource): StreamInterface
|
||||
{
|
||||
return Stream::create($resource);
|
||||
}
|
||||
|
||||
public function createUploadedFile(StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null): UploadedFileInterface
|
||||
{
|
||||
if (null === $size) {
|
||||
$size = $stream->getSize();
|
||||
}
|
||||
|
||||
return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
|
||||
}
|
||||
|
||||
public function createUri(string $uri = ''): UriInterface
|
||||
{
|
||||
return new Uri($uri);
|
||||
}
|
||||
|
||||
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
|
||||
{
|
||||
return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user