qa-data / psr7-http-message
HTTP message interface
Installs: 700
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/qa-data/psr7-http-message
Requires
- php: >=8.1
- guzzlehttp/psr7: ^2.7
Requires (Dev)
- nette/tester: ^2.5
- orisai/coding-standard: ^3.10
- phpstan/phpstan: ^1.12
README
PSR-7 is HTTP message interface. It's very useful interface especially for middleware / relay pattern. Read more on official PHP-FIG website.
This package is based on a package from the guys at Contributte - PSR-7 HTTP Message, which is based on guzzle/psr7.
Usage
To install latest version of qa-data/psr7-http-message use Composer.
composer require qa-data/psr7-http-message
Psr7Request
The easiest way is to create request using Psr7RequestFactory.
use Contributte\Psr7\Psr7RequestFactory; $psr7 = Psr7RequestFactory::fromGlobals();
Additional methods (against PSR7 interface):
- of(RequestInterface $request): self
- getContents(): mixed
- getContentsCopy(): mixed
- getJsonBody(bool $associative = true): mixed
- getJsonBodyCopy(bool $associative = true): mixed
Psr7ServerRequest
Additional methods (against PSR7 interface):
- of(ServerRequestInterface $request): self
- fromGlobals(): self
- withAttributes(array $attributes): self
- hasQueryParam(string $name): bool
- getQueryParam(string $name, mixed $default = null): mixed
Psr7Response
The easiest way is to create request using Psr7ResponseFactory.
use Contributte\Psr7\Psr7ResponseFactory; $psr7 = Psr7ResponseFactory::fromGlobal();
Additional methods (against PSR7 interface):
- of(ResponseInterface $response): self
- fromGlobals(): self
- appendBody(mixed $body): self
- rewindBody(): self
- writeBody(mixed $body): self
- writeJsonBody(array $data): self
- writeJsonObject(JsonSerializable $object): self
- getJsonBody(bool $associative = true): mixed
- getContents(bool $rewind = true): mixed
- withHeaders(array $headers): self
- send(): void
- sendHeaders(): void
- sendBody(): void
API
MessageInterface
getProtocolVersion: stringwithProtocolVersion(string $version): staticgetHeaders(): arrayhasHeader(string $name): boolgetHeader(string $name): string[]getHeaderLine(string $name): stringwithHeader(string $name, string|string[] $value): staticwithAddedHeader(string $name, string|string[] $value): staticwithoutHeader(string $name): staticgetBody(): StreamInterfacewithBody(StreamInterface $body): static
RequestInterface << MessageInterface
getRequestTarget(): stringwithRequestTarget($requestTarget): staticgetMethod(): stringwithMethod(string $method): static
ServerRequestInterface << RequestInterface
getServerParams(): arraygetCookieParams(): arraywithCookieParams(array $cookies): staticgetQueryParams(): arraywithQueryParams(array $query): staticgetUploadedFiles(): UploadedFileInterface[]withUploadedFiles(array $uploadedFiles): staticgetParsedBody(): mixedwithParsedBody($data): staticgetAttributes(): mixed[]getAttribute(string $name, $default = null): mixedwithAttribute(string $name, $value): staticwithoutAttribute(string $name): static
ResponseInterface << MessageInterface
getStatusCode(): intwithStatus(int $code, string $reasonPhrase = ''): staticgetReasonPhrase(): string
StreamInterface
__toString(): stringclose(): voiddetach(): ?resourcegetSize(): ?inttell(): inteof(): boolisSeekable(): boolseek(int $offset, int $whence = SEEK_SET): voidrewind(): voidisWritable(): boolwrite($string): voidisReadable(): boolread($length): stringgetContents(): stringgetMetadata(?string $key = null): mixed
UriInterface
getScheme(): stringwithScheme(string $scheme): staticgetAuthority(): stringgetUserInfo(): stringwithUserInfo(string $user, ?string $password = null): staticgetHost(): stringwithHost(string $host): staticgetPort(): ?intwithPort(?int $port): staticgetPath(): stringwithPath(string $path): staticgetQuery(): stringwithQuery(string $query): staticgetFragment(): stringwithFragment(string $fragment): static__toString(): string
UploadedFileInterface
getStream(): StreamInterfacemoveTo($targetPath): voidgetSize(): ?intgetError(): intgetClientFilename(): ?stringgetClientMediaType(): ?string