Skip to content

Commit 9d20efd

Browse files
committed
Imports implementation from http-interop/http-factory
Imports implementation, and makes the following changes: - `s/Interop/Psr/g` - `s/http-interop/psr/g` - Reference final, accepted specification
1 parent 16ecb7d commit 9d20efd

10 files changed

+220
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
composer.lock
2+
vendor/

.pullapprove.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extends: default
2+
reviewers:
3+
-
4+
name: contributors
5+
required: 1
6+
teams:
7+
- http-factory-contributors

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HTTP Factories
2+
==============
3+
4+
This is the implementation of [PSR-17 (HTTP Message Factories)][psr-17]. Please refer to the
5+
specification for a description.
6+
7+
[psr-17]: https://www.php-fig.org/psr/psr-17/

composer.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "psr/http-factory",
3+
"description": "Common interfaces for PSR-7 HTTP message factories",
4+
"keywords": [
5+
"psr",
6+
"psr-7",
7+
"psr-17",
8+
"http",
9+
"factory",
10+
"message",
11+
"request",
12+
"response"
13+
],
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "PHP-FIG",
18+
"homepage": "http://www.php-fig.org/"
19+
}
20+
],
21+
"require": {
22+
"php": ">=7.0.0",
23+
"psr/http-message": "^1.0"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"Psr\\Http\\Factory\\": "src/"
28+
}
29+
},
30+
"extra": {
31+
"branch-alias": {
32+
"dev-master": "1.0.x-dev"
33+
}
34+
}
35+
}

src/RequestFactoryInterface.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Psr\Http\Factory;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
use Psr\Http\Message\UriInterface;
7+
8+
interface RequestFactoryInterface
9+
{
10+
/**
11+
* Create a new request.
12+
*
13+
* @param string $method The HTTP method associated with the request.
14+
* @param UriInterface|string $uri The URI associated with the request. If
15+
* the value is a string, the factory MUST create a UriInterface
16+
* instance based on it.
17+
*
18+
* @return RequestInterface
19+
*/
20+
public function createRequest(string $method, $uri): RequestInterface;
21+
}

src/ResponseFactoryInterface.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Psr\Http\Factory;
4+
5+
use Psr\Http\Message\ResponseInterface;
6+
7+
interface ResponseFactoryInterface
8+
{
9+
/**
10+
* Create a new response.
11+
*
12+
* @param int $code HTTP status code; defaults to 200
13+
* @param string $reasonPhrase Reason phrase to associate with status code
14+
* in generated response; if none is provided implementations MAY use
15+
* the defaults as suggested in the HTTP specification.
16+
*
17+
* @return ResponseInterface
18+
*/
19+
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface;
20+
}

src/ServerRequestFactoryInterface.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Psr\Http\Factory;
4+
5+
use Psr\Http\Message\ServerRequestInterface;
6+
use Psr\Http\Message\UriInterface;
7+
8+
interface ServerRequestFactoryInterface
9+
{
10+
/**
11+
* Create a new server request.
12+
*
13+
* Note that server-params are taken precisely as given - no parsing/processing
14+
* of the given values is performed, and, in particular, no attempt is made to
15+
* determine the HTTP method or URI, which must be provided explicitly.
16+
*
17+
* @param string $method The HTTP method associated with the request.
18+
* @param UriInterface|string $uri The URI associated with the request. If
19+
* the value is a string, the factory MUST create a UriInterface
20+
* instance based on it.
21+
* @param array $serverParams Array of SAPI parameters with which to seed
22+
* the generated request instance.
23+
*
24+
* @return ServerRequestInterface
25+
*/
26+
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface;
27+
}

src/StreamFactoryInterface.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Psr\Http\Factory;
4+
5+
use Psr\Http\Message\StreamInterface;
6+
7+
interface StreamFactoryInterface
8+
{
9+
/**
10+
* Create a new stream from a string.
11+
*
12+
* The stream SHOULD be created with a temporary resource.
13+
*
14+
* @param string $content String content with which to populate the stream.
15+
*
16+
* @return StreamInterface
17+
*/
18+
public function createStream(string $content = ''): StreamInterface;
19+
20+
/**
21+
* Create a stream from an existing file.
22+
*
23+
* The file MUST be opened using the given mode, which may be any mode
24+
* supported by the `fopen` function.
25+
*
26+
* The `$filename` MAY be any string supported by `fopen()`.
27+
*
28+
* @param string $filename Filename or stream URI to use as basis of stream.
29+
* @param string $mode Mode with which to open the underlying filename/stream.
30+
*
31+
* @return StreamInterface
32+
*/
33+
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface;
34+
35+
/**
36+
* Create a new stream from an existing resource.
37+
*
38+
* The stream MUST be readable and may be writable.
39+
*
40+
* @param resource $resource PHP resource to use as basis of stream.
41+
*
42+
* @return StreamInterface
43+
*/
44+
public function createStreamFromResource($resource): StreamInterface;
45+
}

src/UploadedFileFactoryInterface.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Psr\Http\Factory;
4+
5+
use Psr\Http\Message\StreamInterface;
6+
use Psr\Http\Message\UploadedFileInterface;
7+
8+
interface UploadedFileFactoryInterface
9+
{
10+
/**
11+
* Create a new uploaded file.
12+
*
13+
* If a size is not provided it will be determined by checking the size of
14+
* the file.
15+
*
16+
* @see http://php.net/manual/features.file-upload.post-method.php
17+
* @see http://php.net/manual/features.file-upload.errors.php
18+
*
19+
* @param StreamInterface $stream Underlying stream representing the
20+
* uploaded file content.
21+
* @param int $size in bytes
22+
* @param int $error PHP file upload error
23+
* @param string $clientFilename Filename as provided by the client, if any.
24+
* @param string $clientMediaType Media type as provided by the client, if any.
25+
*
26+
* @return UploadedFileInterface
27+
*
28+
* @throws \InvalidArgumentException If the file resource is not readable.
29+
*/
30+
public function createUploadedFile(
31+
StreamInterface $stream,
32+
int $size = null,
33+
int $error = \UPLOAD_ERR_OK,
34+
string $clientFilename = null,
35+
string $clientMediaType = null
36+
): UploadedFileInterface;
37+
}

src/UriFactoryInterface.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Psr\Http\Factory;
4+
5+
use Psr\Http\Message\UriInterface;
6+
7+
interface UriFactoryInterface
8+
{
9+
/**
10+
* Create a new URI.
11+
*
12+
* @param string $uri
13+
*
14+
* @return UriInterface
15+
*
16+
* @throws \InvalidArgumentException If the given URI cannot be parsed.
17+
*/
18+
public function createUri(string $uri = ''): UriInterface;
19+
}

0 commit comments

Comments
 (0)