|
| 1 | +PHP HTTP Tools |
| 2 | +======================================= |
| 3 | + |
| 4 | +PHP HTTP Tool kit that brings common functionality in a standarized way, |
| 5 | +supporting PSR-7 and PSR-17 standards. |
| 6 | + |
| 7 | +Installation |
| 8 | +--------------------------------------- |
| 9 | + |
| 10 | +Using composer. |
| 11 | + |
| 12 | +```bash |
| 13 | +composer install francerz/php-http-tools |
| 14 | +``` |
| 15 | + |
| 16 | +Featured functionality |
| 17 | +---------------------------------------- |
| 18 | + |
| 19 | +### HttpFactoryManager class |
| 20 | + |
| 21 | +Preserve per instance, reference of PSR-17 Factories (psr/http-factory). |
| 22 | +Uses set and get methods to manage existing factory instances. |
| 23 | + |
| 24 | +#### Individual setter methods |
| 25 | + |
| 26 | +- `setRequestFactory(RequestFactoryInterface $requestFactory)` |
| 27 | +- `setResponseFactory(ResponseFactoryInterface $responseFactory)` |
| 28 | +- `setServerRequestFactory(ServerRequestFactoryInterface $serverRequestFactory)` |
| 29 | +- `setStreamFactory(StreamFactoryInterface $streamFactory)` |
| 30 | +- `setUploadedFileFactory(UploadedFileFactoryInterface $uploadedFileFactory)` |
| 31 | +- `setUriFactory(UriFactoryInterface $uriFactory)` |
| 32 | + |
| 33 | +#### Getter methods |
| 34 | + |
| 35 | +Getter Methods will throw a `LogicException` if not factory has been set |
| 36 | +previously. |
| 37 | +- `getRequestFactory() : RequestFactoryInterface` |
| 38 | +- `getResponseFactory() : ResponseFactoryInterface` |
| 39 | +- `getServerRequestFactory() : ServerRequestFactoryInterface` |
| 40 | +- `getStreamFactory() : StreamFactoryInterface` |
| 41 | +- `getUploadedFileFactory() : UploadedFileFactoryInterface` |
| 42 | +- `getUriFactory() : UriFactoryInterface` |
| 43 | + |
| 44 | +#### Automatic setter method |
| 45 | + |
| 46 | +The method `setMatchingFactories($factoryObject)` receives an object and |
| 47 | +checks implementation of each Factory Interface. All matching interfaces |
| 48 | +will be set. |
| 49 | + |
| 50 | +This method is included on the constructor to quick factory setting. |
| 51 | + |
| 52 | +### UriHelper class |
| 53 | + |
| 54 | +Provides methods for common manipulation to `UriInterface` objects. |
| 55 | + |
| 56 | +#### Creating uri of current request |
| 57 | + |
| 58 | +- `getCurrent(UriFactoryInterface $uriFactory) : UriInterface` |
| 59 | + |
| 60 | +#### Path part manipulation |
| 61 | + |
| 62 | +- `appendPath(UriInterface $uri, string $postpath) : UriInterface` |
| 63 | +- `prependPath(UriInterface $uri, string $prepath) : UriInterface` |
| 64 | + |
| 65 | +#### Query part manipulation |
| 66 | + |
| 67 | +- `withQueryParams(UriInterface $uri, string $key, $value) : UriInterface` |
| 68 | +- `withQueryParams(UriInterface $uri, array $params, $replace = true) : UriInterface` |
| 69 | +- `withoutQueryParam(UriInterface $uri, string $key, &$value = null) : UriInterface` |
| 70 | +- `getQueryParams(UriInterface $uri) : array` |
| 71 | +- `getQueryParam(UriInterface $uri, string $key) : ?string` |
| 72 | + |
| 73 | +#### Fragment part manipulation |
| 74 | + |
| 75 | +- `withFragmentParam(UriInterface $uri, string $key, $value) : UriInterface` |
| 76 | +- `withFragmentParams(UriInterface $uri, array $params, $replace = true) : UriInterface` |
| 77 | +- `withoutFragmentParam(UriInterface $uri, string $key, &$value = null) : UriInterface` |
| 78 | +- `getFragmentParams(UriInterface $uri) : array` |
| 79 | +- `getFragmentParam(UriInterface $uri, string $key) : ?string` |
| 80 | + |
| 81 | +### MessageHelper class |
| 82 | + |
| 83 | +Provides methods for common manipulation to `MessageInterface` objects. |
| 84 | + |
| 85 | +#### Helper setup |
| 86 | + |
| 87 | +- `setHttpFactoryManager(HttpFactoryManager $factories)` |
| 88 | +- `setAuthenticationSchemes(array $authenticationSchemeClasses)` |
| 89 | + |
| 90 | +#### Creating a request object from server parameters |
| 91 | + |
| 92 | +- `getCurrentRequest() : RequestInterface` |
| 93 | + |
| 94 | +#### Handling message headers |
| 95 | + |
| 96 | +- `getAuthorizationHeader(MessageInterface $message) : ?AbstractAuthorizationHeader` |
| 97 | + |
| 98 | +#### Parsing body message content based on Content-Type header |
| 99 | + |
| 100 | +- `getContent(MessageInterface $message)` |
| 101 | +- `withContent(MessageInterface $message, string $mediaType, $content) : MessageInterface` |
0 commit comments