Download the PHP package lmc/cqrs-http without Composer
On this page you can find all versions of the php package lmc/cqrs-http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lmc/cqrs-http
More information about lmc/cqrs-http
Files in lmc/cqrs-http
Package cqrs-http
Short Description A library containing base implementations to help with Http Queries and Commands
License MIT
Informations about the package cqrs-http
LMC CQRS Http extension
A library containing base implementations to help with Http Queries and Commands. This library is an extension for CQRS/Bundle and adds support for PSR-7.
Table of contents
- Installation
- Queries
- Query
- Abstract HTTP Query
- Abstract HTTP GET Query
- Query Handlers
- Query
- Commands
- Command
- Abstract HTTP Command
- Abstract HTTP DELETE Command
- Abstract HTTP PATCH Command
- Abstract HTTP POST Command
- Abstract HTTP PUT Command
- Send Command Handlers
- Command
- Response Decoders
- Profiler Formatters
Installation
NOTE: You will also need an implementation for PSR-7, PSR-17 and PSR-18 for HTTP extensions to work.
Query
Query is a request which fetch a data without changing anything. See more here
AbstractHttpQuery
A base HTTP Query, it abstracts a creating of a Psr\Http\Message\RequestInterface
(PSR-7) using a Psr\Http\Message\RequestFactoryInterface
(PSR-17) (it is directly required to be injected into a query).
It also implements a ProfileableInterface
feature.
Method | Type | Description |
---|---|---|
getRequestType |
final | It declares a request type of a Http query to be a Psr\Http\Message\RequestInterface |
getHttpMethod |
abstract | It requires a query to return a http method of a query. (see PSR Http Message Util) |
getUri |
abstract | This method returns a URI of the Query - it may be just a string or a Psr\Http\Message\UriInterface (PSR-7) instance. |
modifyRequest |
base | If you overwrite this method, you can manipulate a RequestInterface instance. |
getProfilerId |
base | It's a predefined creating of profiler id for a http query. It creates a profiler id based on http method and uri . |
getProfilerData |
base | If you overwrite this method, you can specify additional profiler data. Default is null (no data). |
__toString |
base | It's a predefined casting a Query into string, it returns a string representation of uri . |
AbstractHttpGetQuery
A base HTTP GET Query, it abstracts a creating of a Psr\Http\Message\RequestInterface
(PSR-7) using a Psr\Http\Message\RequestFactoryInterface
(PSR-17) (it is directly required to be injected into a query).
It extends a base AbstractHttpQuery
and predefine some abstract methods. It also adds CacheableInterface
feature, since a GET request is mostly cacheable
Method | Type | Description |
---|---|---|
getHttpMethod |
final | It declares a http method of this query to be GET . |
getUri |
abstract | This method returns a URI of the Query - it may be just a string or a Psr\Http\Message\UriInterface (PSR-7) instance. |
getCacheTime |
base | It returns a default value for a cache time of 30 minutes. |
getCacheKey |
base | It creates a CacheKey out of a static class name (your implementation class name) and a uri , which should create a unique enough cache key for most queries. |
TIP: If you want to use this implementation but don't need a cache, you can simply return a CacheTime::noCache()
in your implementation of getCacheTime
method.
Query Handlers
It is responsible for handling a specific Query request and passing a result into OnSuccess
callback. See more here.
Http Query Handler
This handler supports Psr\Http\Message\RequestInterface
and handles it into Psr\Http\Message\ResponseInterface
.
It also checks a status code of a response and marks it as error if it is an error code:
- 400 ->
HttpBadRequestException
- 500 ->
HttpServerErrorException
Command
Command is a request which change a data and may return result data. See more here
AbstractHttpCommand
A base HTTP Command, it abstracts a creating of a Psr\Http\Message\RequestInterface
(PSR-7) using a Psr\Http\Message\RequestFactoryInterface
(PSR-17) (it is directly required to be injected into a command).
It also implements a ProfileableInterface
feature.
Method | Type | Description |
---|---|---|
getRequestType |
final | It declares a request type of a Http command to be a Psr\Http\Message\RequestInterface |
getHttpMethod |
abstract | It requires a command to return a http method of a command. (see PSR Http Message Util) |
getUri |
abstract | This method returns a URI of the Command - it may be just a string or a Psr\Http\Message\UriInterface (PSR-7) instance. |
modifyRequest |
base | If you overwrite this method, you can manipulate a RequestInterface instance. |
getProfilerId |
base | It's a predefined creating of profiler id for a http command. It creates a profiler id based on http method and uri . |
getProfilerData |
base | If you overwrite this method, you can specify additional profiler data. Default is null (no data). |
__toString |
base | It's a predefined casting a Command into string, it returns a string representation of uri . |
AbstractHttpDeleteCommand
A base HTTP DELETE Command, it abstracts a creating of a Psr\Http\Message\RequestInterface
(PSR-7) using a Psr\Http\Message\RequestFactoryInterface
(PSR-17) (it is directly required to be injected into a command).
It extends a base AbstractHttpCommand
and predefine some abstract methods.
Method | Type | Description |
---|---|---|
getHttpMethod |
final | It declares a http method of this query to be DELETE . |
AbstractHttpPatchCommand
A base HTTP PATCH Command, it abstracts a creating of a Psr\Http\Message\RequestInterface
(PSR-7) using a Psr\Http\Message\RequestFactoryInterface
(PSR-17) (it is directly required to be injected into a command).
It extends a base AbstractHttpCommand
and predefine some abstract methods.
Method | Type | Description |
---|---|---|
getHttpMethod |
final | It declares a http method of this query to be PATCH . |
AbstractHttpPostCommand
A base HTTP POST Command, it abstracts a creating of a Psr\Http\Message\RequestInterface
(PSR-7) using a Psr\Http\Message\RequestFactoryInterface
(PSR-17) (it is directly required to be injected into a command).
It extends a base AbstractHttpCommand
and predefine some abstract methods.
Method | Type | Description |
---|---|---|
getHttpMethod |
final | It declares a http method of this query to be POST . |
createBody |
abstract | It requires a command to return an instance of Psr\Http\Message\StreamInterface which is used as a POST request body. |
createRequest |
base | It creates a request with a body. |
getProfilerData |
base | It adds a Body into additional data for profiler, so it may be shown later in profiler. |
AbstractHttpPutCommand
A base HTTP PATCH Command, it abstracts a creating of a Psr\Http\Message\RequestInterface
(PSR-7) using a Psr\Http\Message\RequestFactoryInterface
(PSR-17) (it is directly required to be injected into a command).
It extends a base AbstractHttpCommand
and predefine some abstract methods.
Method | Type | Description |
---|---|---|
getHttpMethod |
final | It declares a http method of this query to be PATCH . |
Send Command Handlers
It is responsible for handling a specific Command request and passing a result into OnSuccess
callback. See more here.
Http Send Command Handler
This handler supports Psr\Http\Message\RequestInterface
and handles it into Psr\Http\Message\ResponseInterface
.
It also checks a status code of a response and marks it as error if it is an error code:
- 400 ->
HttpBadRequestException
- 500 ->
HttpServerErrorException
Response Decoders
It is meant to decode a response (a result of either QueryHandlerInterface
or a SendCommandHandlerInterface
). See more here.
HttpMessageResponseDecoder
It decodes a Psr\Http\Message\ResponseInterface
into a Psr\Http\Message\StreamInterface
by getting a body of a response.
StreamResponseDecoder
It decodes a Psr\Http\Message\StreamInterface
into a string
by getting a stream contents (if possible).
Note: There is also a JsonResponseDecoder which decodes a string into an array.
Profiler Formatters
HttpProfilerFormatter
It formats a Psr\Http\Message\MessageInterface
and Psr\Http\Message\StreamInterface
into a readable format, so a data is nicer in profiler.
All versions of cqrs-http with dependencies
ext-json Version *
ext-mbstring Version *
fig/http-message-util Version ^1.1
lmc/cqrs-types Version ^3.2
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0 || ^2.0