Questions tagged [psr-7]

PSR-7 is the FIG standard for HTTP messages in PHP. It provides abstractions of HTTP messages and their components and defines a consistent set of interfaces to work with them.

The purpose of PSR-7 is to provide PHP with a set of common interfaces for HTTP messages as described in RFC 7230 and RFC 7231, and URIs as described in RFC 3986 (in the context of HTTP messages).

All HTTP messages consist of the HTTP protocol version being used, headers, and a message body. A Request builds on the message to include the HTTP method used to make the request, and the URI to which the request is made. A Response includes the HTTP status code and reason phrase.

In PHP, HTTP messages are used in two contexts:

  • To send an HTTP request, via the ext/curl extension, PHP's native stream layer, etc., and process the received HTTP response. In other words, HTTP messages are used when using PHP as an HTTP client.
  • To process an incoming HTTP request to the server, and return an HTTP response to the client making the request. PHP can use HTTP messages when used as a server-side application to fulfil HTTP requests.
94 questions
0
votes
1 answer

slim create response with guzzle streamFor content

I have an issue when building a slim (slim 4) response with a streamed content (a huge xlsx file content). $fileHandler = \fopen(getenv('SHARED_FILES_PATH') . $filename, 'r'); if (!$fileHandler) { throw new \Exception('Unable to open file ' .…
chaillouvincent
  • 197
  • 1
  • 3
  • 17
0
votes
1 answer

PSR-7 validation with regex possible? (parameter clash)

I'm currently generating OpenAPI annotations via Symfony (5.1) Routes and NelmioApiDocBundle, One of the routes looks like this: * @Route("/users/{id}", methods={"GET"}, requirements={"id": "\d+"}) * @OA\Parameter(name="id", in="path",…
Oliver Adria
  • 1,123
  • 11
  • 23
0
votes
1 answer

Guzzle PSR7 request with multipart/form-data

I created a simple API in Lumen (application A) which: receives PSR-7 request interface replaces URI of the request to the application B and sends the request through Guzzle. public function apiMethod(ServerRequestInterface $psrRequest) { $url…
kmasalski
  • 238
  • 4
  • 17
0
votes
1 answer

How To Use Mockery For Mocking Nested Object Like GuzzleHttp Request

I have the following code in PHP: $response = $this->client->request('GET', $path, $requestBody, $headers); $isRequestSuccess = $response->getStatusCode() === "200"; if ($isRequestSuccess) { return $response->getBody()->getContents(); } It…
Franz Noel
  • 1,820
  • 2
  • 23
  • 50
0
votes
0 answers

Codeception sendPOST not working with Slim 3 getParam

Relatively new to Codeception and trying to hook it up to Slim 3. Setting up a basic test for a POST request like so: $I->sendPOST('/user', [ 'details' => [ 'id' => 0, 'package_id' => 0, 'order_id' => 0 …
ejb
  • 1
0
votes
1 answer

Parsing huge XML in PSR-7 response

I would like to parse huge xml in PSR-7 response. Defaults XmlReader looks good, but it seems it can't use PSR-7 StreamInterface. My XML looks: ... ... I would like to use something…
venca
  • 1,196
  • 5
  • 18
0
votes
1 answer

Implement route specific middleware

I've managed to use the request-handler combined with aura-router with a single router handler. Am trying to implement route specific middleware, as opposed to the 'global' application middleware. $routerContainer = new RouterContainer(); $map =…
bmatovu
  • 3,756
  • 1
  • 35
  • 37
0
votes
1 answer

Remove body PSR-7 Slim3 middleware?

I'm trying to redirect user to a login page when is not authenticated. I'm using a middleware in Slim3 to check using Sentinel. Works but I need to override the body to not show the content. For example, I could use CURL to access to a route like…
fpilee
  • 1,918
  • 2
  • 22
  • 38
0
votes
1 answer

PHP 7 PSR-7 response test if script can resize image with GD in conditions of limited memory

I use PHP 7.1 with GD library. My script downloads images and resizes it before saving. Server has 256MB of memory (can't increase). Some of images have large physical size (not file size), greater than 50Mpx. When I try to resize it with GD, memory…
userlond
  • 3,632
  • 2
  • 36
  • 53
0
votes
0 answers

AWS - Guzzle The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method

I am using SignatureV4 aws authentication to authenticate my API call, I am also using Guzzle/Client to call API. By following these above, my API call works for GET method only and not working for POST method. For POST method call it show an error…
Himanshu Gupta
  • 71
  • 1
  • 2
  • 6
0
votes
0 answers

PHP+PSR7: getParsedBody() always convert empty strings on json to null

I'm im using zendframework/zend-diactoros with Laravel. I have a problem when I sent json data like { "data": { "value": "" } } Then, in controller // @var $request…
pablorsk
  • 3,861
  • 1
  • 32
  • 37
0
votes
3 answers

How to read the host name from a request URI in PHP?

For the router, I wanted to get the host name from the URI upon a server request. I know that I need to read it from the $_SERVER variable. But it seems that in the $_SERVER array there are multiple entries (at least two) for the host name. Could…
user7941334
0
votes
2 answers

How to read the request URI?

For my own MVC I need to read the request URI from the global variables ($_GET or $_SERVER). First I thought to read it from $_GET array. But then I discovered that it's contained in the $_SERVER array as well. So, I would like to ask, from which…
user7941334
0
votes
0 answers

empty array on getParsedBody

I have a ServerRequestInterface $request and when I call $body = $request->getBody()->getContents() it returns {"email":"a@b.com","password":"password"}, but $request->getParsedBody() returns an empty array[0]. This is a POST request. Anyone know…
Bluebaron
  • 2,289
  • 2
  • 27
  • 37
0
votes
1 answer

php error at runtime Interface 'Psr\Container\ContainerInterface' not found

I recently uploaded a new dependency to a PHP app I am working on and I am now continually getting the following error in Postman Fatal error: Interface 'Psr\Container\ContainerInterface' not found…
NightHawk95
  • 163
  • 3
  • 11