-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Prokl\ServiceProvider\Services\PSR\PSR17; | ||
|
||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Response; | ||
use GuzzleHttp\Psr7\ServerRequest; | ||
use GuzzleHttp\Psr7\UploadedFile; | ||
use GuzzleHttp\Psr7\Uri; | ||
use GuzzleHttp\Psr7\Utils; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
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\StreamInterface; | ||
use Psr\Http\Message\UploadedFileFactoryInterface; | ||
use Psr\Http\Message\UploadedFileInterface; | ||
use Psr\Http\Message\UriFactoryInterface; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
/** | ||
* Class HttpFactory | ||
* @package Prokl\ServiceProvider\Services\PSR\PSR17 | ||
*/ | ||
class HttpFactory implements | ||
RequestFactoryInterface, | ||
ResponseFactoryInterface, | ||
ServerRequestFactoryInterface, | ||
StreamFactoryInterface, | ||
UploadedFileFactoryInterface, | ||
UriFactoryInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createRequest(string $method, $uri): RequestInterface | ||
{ | ||
return new Request($method, $uri); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface | ||
{ | ||
return new Response($code, [], null, '1.1', $reasonPhrase); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface | ||
{ | ||
return new ServerRequest($method, $uri, [], null, '1.1', $serverParams); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createStream(string $content = ''): StreamInterface | ||
{ | ||
return Utils::streamFor($content); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface | ||
{ | ||
return Utils::streamFor(fopen($filename, $mode)); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createStreamFromResource($resource): StreamInterface | ||
{ | ||
return Utils::streamFor($resource); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createUploadedFile( | ||
StreamInterface $stream, | ||
int $size = null, | ||
int $error = \UPLOAD_ERR_OK, | ||
string $clientFilename = null, | ||
string $clientMediaType = null | ||
): UploadedFileInterface | ||
{ | ||
return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createUri(string $uri = ''): UriInterface | ||
{ | ||
return new Uri($uri); | ||
} | ||
} |