Psr18Client
extends Psr17Factory
in package
implements
ClientInterface
A generic PSR-18 and PSR-17 implementation.
You can create this class with concrete client and factory instances or let it use discovery to find suitable implementations as needed.
Tags
Table of Contents
Interfaces
Properties
- $client : mixed
Methods
- __construct() : mixed
- createRequest() : RequestInterface
- Create a new request.
- createResponse() : ResponseInterface
- Create a new response.
- createServerRequest() : ServerRequestInterface
- Create a new server request.
- createServerRequestFromGlobals() : ServerRequestInterface
- createStream() : StreamInterface
- Create a new stream from a string.
- createStreamFromFile() : StreamInterface
- Create a stream from an existing file.
- createStreamFromResource() : StreamInterface
- Create a new stream from an existing resource.
- createUploadedFile() : UploadedFileInterface
- Create a new uploaded file.
- createUri() : UriInterface
- Create a new URI.
- createUriFromGlobals() : UriInterface
- sendRequest() : ResponseInterface
- Sends a PSR-7 request and returns a PSR-7 response.
Properties
$client
private
mixed
$client
Methods
__construct()
public
__construct([ClientInterface|null $client = null ][, RequestFactoryInterface|null $requestFactory = null ][, ResponseFactoryInterface|null $responseFactory = null ][, ServerRequestFactoryInterface|null $serverRequestFactory = null ][, StreamFactoryInterface|null $streamFactory = null ][, UploadedFileFactoryInterface|null $uploadedFileFactory = null ][, UriFactoryInterface|null $uriFactory = null ]) : mixed
Parameters
- $client : ClientInterface|null = null
- $requestFactory : RequestFactoryInterface|null = null
- $responseFactory : ResponseFactoryInterface|null = null
- $serverRequestFactory : ServerRequestFactoryInterface|null = null
- $streamFactory : StreamFactoryInterface|null = null
- $uploadedFileFactory : UploadedFileFactoryInterface|null = null
- $uriFactory : UriFactoryInterface|null = null
createRequest()
Create a new request.
public
createRequest(string $method, UriInterface|string $uri) : RequestInterface
Parameters
- $method : string
-
The HTTP method associated with the request.
- $uri : UriInterface|string
Return values
RequestInterfacecreateResponse()
Create a new response.
public
createResponse([int $code = 200 ][, string $reasonPhrase = '' ]) : ResponseInterface
Parameters
- $code : int = 200
-
HTTP status code; defaults to 200
- $reasonPhrase : string = ''
-
Reason phrase to associate with status code in generated response; if none is provided implementations MAY use the defaults as suggested in the HTTP specification.
Return values
ResponseInterfacecreateServerRequest()
Create a new server request.
public
createServerRequest(string $method, UriInterface|string $uri[, array<string|int, mixed> $serverParams = [] ]) : ServerRequestInterface
Parameters
- $method : string
-
The HTTP method associated with the request.
- $uri : UriInterface|string
- $serverParams : array<string|int, mixed> = []
-
Array of SAPI parameters with which to seed the generated request instance.
Return values
ServerRequestInterfacecreateServerRequestFromGlobals()
public
createServerRequestFromGlobals([array<string|int, mixed>|null $server = null ][, array<string|int, mixed>|null $get = null ][, array<string|int, mixed>|null $post = null ][, array<string|int, mixed>|null $cookie = null ][, array<string|int, mixed>|null $files = null ][, StreamInterface|null $body = null ]) : ServerRequestInterface
Parameters
- $server : array<string|int, mixed>|null = null
- $get : array<string|int, mixed>|null = null
- $post : array<string|int, mixed>|null = null
- $cookie : array<string|int, mixed>|null = null
- $files : array<string|int, mixed>|null = null
- $body : StreamInterface|null = null
Return values
ServerRequestInterfacecreateStream()
Create a new stream from a string.
public
createStream([string $content = '' ]) : StreamInterface
The stream SHOULD be created with a temporary resource.
Parameters
- $content : string = ''
-
String content with which to populate the stream.
Return values
StreamInterfacecreateStreamFromFile()
Create a stream from an existing file.
public
createStreamFromFile(string $filename[, string $mode = 'r' ]) : StreamInterface
The file MUST be opened using the given mode, which may be any mode
supported by the fopen function.
The $filename MAY be any string supported by fopen().
Parameters
- $filename : string
-
Filename or stream URI to use as basis of stream.
- $mode : string = 'r'
-
Mode with which to open the underlying filename/stream.
Return values
StreamInterfacecreateStreamFromResource()
Create a new stream from an existing resource.
public
createStreamFromResource(resource $resource) : StreamInterface
Parameters
- $resource : resource
Return values
StreamInterfacecreateUploadedFile()
Create a new uploaded file.
public
createUploadedFile(StreamInterface $stream[, int|null $size = null ][, int $error = UPLOAD_ERR_OK ][, string|null $clientFilename = null ][, string|null $clientMediaType = null ]) : UploadedFileInterface
If a size is not provided it will be determined by checking the size of the file.
Parameters
- $stream : StreamInterface
-
Underlying stream representing the uploaded file content.
- $size : int|null = null
-
in bytes
- $error : int = UPLOAD_ERR_OK
-
PHP file upload error
- $clientFilename : string|null = null
-
Filename as provided by the client, if any.
- $clientMediaType : string|null = null
-
Media type as provided by the client, if any.
Return values
UploadedFileInterfacecreateUri()
Create a new URI.
public
createUri([string $uri = '' ]) : UriInterface
Parameters
- $uri : string = ''
Return values
UriInterfacecreateUriFromGlobals()
public
createUriFromGlobals([array<string|int, mixed>|null $server = null ]) : UriInterface
Parameters
- $server : array<string|int, mixed>|null = null
Return values
UriInterfacesendRequest()
Sends a PSR-7 request and returns a PSR-7 response.
public
sendRequest(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface