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
2
votes
1 answer

Matching Param on URL in Custom Router PHP

I'm adding a funcionality to this custom Router and custom Request Class in order to be able to serve pages and json responses. I'm stuck on the router part, where the Route has a parameter in the url like: example.com/apply/{variable} Those are…
Albeis
  • 1,544
  • 2
  • 17
  • 30
2
votes
1 answer

$_FILES key used for building a PSR-7 uploaded files list

The short version: When a user uploads a file using a form, an array is saved in the global variable $_FILES. For example, when using: the global variable looks like this: $_FILES = [ 'myfiles0' => [ …
PajuranCodes
  • 303
  • 3
  • 12
  • 43
2
votes
1 answer

PSR7 on Laravel Routes: access to latest params

Hi have the next route Route::get('/{param1}', 'Http\Controllers\SomeController@getCollection'); Route::get('/{param_for_middleware}/{param1}', 'Http\Controllers\SomeController@getCollection'); And, on my controller, I have // PSR7…
pablorsk
  • 3,861
  • 1
  • 32
  • 37
2
votes
1 answer

Guzzle: Access uploaded files in history middleware

I'm trying to access an uploaded file in the history middleware for Guzzle (v6). My actual code receives a request (so is using the ServerRequestInterface), then uses Guzzle to send the request elsewhere. I'm trying to test uploaded files going…
giggsey
  • 933
  • 2
  • 11
  • 31
2
votes
2 answers

How to parse / validate / handle http headers in PHP

Currently i am building my own php framework and i am now creating an implementation of the PHP-FIG PSR-7 MessageInterface. In specific the withHeader method. It states that the method could trow an exeption: \InvalidArgumentException for invalid…
ITGuy1990
  • 93
  • 1
  • 9
2
votes
3 answers

PSR-7 "attributes" on Response object

I'm developing using PSR-7 (with Zend Expressive). I figured out the method ServerRequestInterface::withAttribute() and I was wondering why the object Response doesn't have one. I'd like to pass metadata through middlewares after processing, on…
tornellas
  • 21
  • 3
2
votes
2 answers

Slim 3 - replacement for isPost()?

In Slim 2, I would do this, $app->map('/login', function () use ($app) { // Test for Post & make a cheap security check, to get avoid from bots if ($app->request()->isPost() && sizeof($app->request()->post()) >= 2) { // } …
Run
  • 54,938
  • 169
  • 450
  • 748
2
votes
1 answer

Can I use PSR-7 StreamInterfaces with PHP's native stream functions?

I'm asking as I'm using packages like im0rtality/jsonstreamingparser that depend on the input being a native php stream, e.g. by calling get_resource_type(). If not directly, is there any wrapper library on packagist that my search did not turn up?
andig
  • 13,378
  • 13
  • 61
  • 98
1
vote
1 answer

How to replace deprecated HttpUtility::redirect() with PSR-7 response in legacy TYPO3 plugin?

I have a legacy extension with a plugin that's handled in MyPluginController, which extends TYPO3\CMS\Frontend\Plugin\AbstractPlugin. The plugin is registered as a USER_INT content object: plugin.tx_myext_pi1 = USER_INT plugin.tx_myext_pi1.userFunc…
Stoppeye
  • 85
  • 7
1
vote
2 answers

Cannot autowire argument $request

My controller looks like: use Psr\Http\Message\ServerRequestInterface; class HelloController extends AbstractController { public function __invoke(ServerRequestInterface $request): Response { dd($request) return…
miclofa
  • 49
  • 1
  • 10
1
vote
2 answers

How to add a cookie when using TYPO3 Middleware?

I want to use the Middleware to add a cookie. In TYPO3 I have the Psr\Http\Message\ServerRequestInterface $request and the Psr\Http\Server\RequestHandlerInterface $handler variables. What is the best practise to add a cookie with all the needed…
Thomas Löffler
  • 5,922
  • 1
  • 14
  • 29
1
vote
2 answers

How to call another internal endpoint from within zend expressive REST api application?

I am trying to call an REST api endpoint(internal) from within another method in zend expressive (PSR-7) application. Currently what I'm doing is, I send another http request like this (docs): $request = (new Zend\Diactoros\Request()) …
Sanju
  • 1,478
  • 2
  • 20
  • 41
1
vote
0 answers

PSR-15 Middleware: is it expected that middleware *instance* can be reused for different requests?

I cannot find any articles or docs on the web that say that clearly. Are PSR-15 middleware objects expected to be reusable or each server request implies creating brand new middleware instances? This is important when there is need to keep data in…
1
vote
1 answer

Change Slim Request property

How can I change a Slim Request's URI path? I tried the following, however, withPath() clones the uri thus the request object isn't changed. If it is not possible, is there a straightforward process to create a new Slim Request based on the…
user1032531
  • 24,767
  • 68
  • 217
  • 387
1
vote
0 answers

Should I implement both RequestInterface and ServerRequestInterface

I am currently writing an implementation of the HTTP Message Interface Recommendation (PSR-7) for my personal PHP framework. I've written classes for each interface in the recommendation. But now I realize that I do not need an abstraction for…
Youmy001
  • 515
  • 3
  • 11