Skip to content

Commit 76d2ce0

Browse files
weierophinneyNyholm
authored andcommitted
Extend interfaces from psr/http-factory (#43)
Now that PSR-17 is accepted, we can mark this package deprecated, and do a new minor release that has all interfaces extend those from the official specification.
1 parent c8d8491 commit 76d2ce0

7 files changed

+12
-126
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
],
2121
"require": {
2222
"php": ">=7.0.0",
23+
"psr/http-factory": "^1.0",
2324
"psr/http-message": "^1.0"
2425
},
2526
"autoload": {

src/RequestFactoryInterface.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,8 @@
22

33
namespace Interop\Http\Factory;
44

5-
use Psr\Http\Message\RequestInterface;
6-
use Psr\Http\Message\UriInterface;
5+
use Psr\Http\Message\RequestFactoryInterface as PsrRequestFactoryInterface;
76

8-
interface RequestFactoryInterface
7+
interface RequestFactoryInterface extends PsrRequestFactoryInterface
98
{
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;
219
}

src/ResponseFactoryInterface.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,8 @@
22

33
namespace Interop\Http\Factory;
44

5-
use Psr\Http\Message\ResponseInterface;
5+
use Psr\Http\Message\ResponseFactoryInterface as PsrResponseFactoryInterface;
66

7-
interface ResponseFactoryInterface
7+
interface ResponseFactoryInterface extends PsrResponseFactoryInterface
88
{
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;
209
}

src/ServerRequestFactoryInterface.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,8 @@
22

33
namespace Interop\Http\Factory;
44

5-
use Psr\Http\Message\ServerRequestInterface;
6-
use Psr\Http\Message\UriInterface;
5+
use Psr\Http\Message\ServerRequestFactoryInterface as PsrServerRequestFactoryInterface;
76

8-
interface ServerRequestFactoryInterface
7+
interface ServerRequestFactoryInterface extends PsrServerRequestFactoryInterface
98
{
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;
279
}

src/StreamFactoryInterface.php

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,8 @@
22

33
namespace Interop\Http\Factory;
44

5-
use Psr\Http\Message\StreamInterface;
5+
use Psr\Http\Message\StreamFactoryInterface as PsrStreamFactoryInterface;
66

7-
interface StreamFactoryInterface
7+
interface StreamFactoryInterface extends PsrStreamFactoryInterface
88
{
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;
459
}

src/UploadedFileFactoryInterface.php

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,8 @@
22

33
namespace Interop\Http\Factory;
44

5-
use Psr\Http\Message\StreamInterface;
6-
use Psr\Http\Message\UploadedFileInterface;
5+
use Psr\Http\Message\UploadedFileFactoryInterface as PsrUploadedFileFactoryInterface;
76

8-
interface UploadedFileFactoryInterface
7+
interface UploadedFileFactoryInterface extends PsrUploadedFileFactoryInterface
98
{
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;
379
}

src/UriFactoryInterface.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,8 @@
22

33
namespace Interop\Http\Factory;
44

5-
use Psr\Http\Message\UriInterface;
5+
use Psr\Http\Message\UriFactoryInterface as PsrUriFactoryInterface;
66

77
interface UriFactoryInterface
88
{
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;
199
}

0 commit comments

Comments
 (0)