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
0 answers

Encrypted Cookies in Slim Framework v3

I am writing and application in Slim Framework v3.1. I am a lot confused on how to correctly set and get the cookies using Slim's methods. I need your help in understanding what is the right way to read and write cookies with encryption enabled. I…
ArunKolhapur
  • 5,805
  • 4
  • 18
  • 31
0
votes
0 answers

CakePHP - Psr classes not found

I have the following errors: Fatal error: Interface 'Psr\Http\Message\ServerRequestInterface' not found in /home/www/forex-arts/vendor/cakephp/cakephp/src/Http/ServerRequest.php on line 37 Fatal error: Interface 'Psr\Http\Message\UriInterface' not…
0
votes
1 answer

Create request object from globals in TYPO3

In Symfony you can do : use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); I'd like to know if there is something similar in TYPO3. Thank you.
StatiX
  • 854
  • 6
  • 21
0
votes
1 answer

How can I write a Zend Framework App that serves requests directly (maps URLs to files)?

Background: I have a legacy app that serves files as-is. That is, i.e. when I go to http://server/subfolder/my_index.php?value=x it goes into subfolder on the file system and serves a file called my_index.php and passes it the URL parameters and…
Dennis
  • 7,907
  • 11
  • 65
  • 115
0
votes
0 answers

Can I inject custom Request class into controller's action in Slim 3?

Slim's controllers receive PSR-7 Request and Response objects. The problem is that I want to use my own SomeCustomRequest classes that extends Slim's one in different controller's actions. I know how to set my own Request and Response classes in…
Shandur
  • 41
  • 8
0
votes
0 answers

PSR-7 Responses: how to send a proper Content-Length if the body is a stream of unknown length?

This is more a theoretical question, because I want to implement a way to deal with big arrays of objects that need to be converted to json using json_encode and I want to avoid having the whole array of results in memory to convert the whole thing…
itsjavi
  • 2,574
  • 2
  • 21
  • 24
0
votes
1 answer

Php PSR-7 response, get file mime-type

I've got a $response variable, which implements Psr\Http\Message\ResponseInterface. It contains info about downloaded file. How can I get mime-type of this file?
userlond
  • 3,632
  • 2
  • 36
  • 53
0
votes
1 answer

Flysystem S3 remote file download always corrupted

I recently started using Flysystem in an existing application with the intention of abstracting the local and remote (specifically, S3) filesystems. Everything was working ok on my development environment, on which I successfully configured the…
delolmo
  • 96
  • 8
0
votes
1 answer

PSR-7 UriInterface - Invalid Components with Percent Encoding

I've been working on an implementation of the PSR-7 UriInterface, and the specification regarding when an implementation should throw an InvalidArgumentException for some components is a little puzzling. For example, UriInterface::withPath specifies…
Derek
  • 827
  • 11
  • 23
0
votes
1 answer

How to implement PSR-7?

I've read about the PSR-7 but I simply couldn't understand how to implement it. Here's one example of something I did not understand: The withHeader method would call a header() function? If so, how do I implement the withoutHeader method? If thats…
Vinicius Dias
  • 664
  • 3
  • 15
0
votes
1 answer

having trouble with slimframework's Immutable responses

I am trying to setup a project for an API using slim framework version 3, I don't know who made the PSR-7 and marked the response object as immutable, I don't see any use in that (IMHO. please explain me if I am wrong). Things were much easier when…
Vignesh
  • 1,045
  • 2
  • 17
  • 34
0
votes
1 answer

Pass stream wrapped by Zend Diactoros PhpInputStream (PSR-7 StreamInterface) to fopen-like function?

I have to write something to process an XML document sent via POST. The document has base-64 encoded binaries inside so the request can be quite large. This works: $document = simplexml_load_file('php://input'); But I am using the Zend Diactoros…
Pocketsand
  • 1,261
  • 10
  • 15
0
votes
1 answer

Error passing an instance of an object into a class constructor

I'm having an issue passing a PSR-7 message response (generated by Guzzle) into a class constructor. The message is generated by: $client = new \GuzzleHttp\Client(); $res = $client->request('GET', 'http://pagecrawler/cache.html'); And my class…
Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99
0
votes
1 answer

Do not abort response on ErrorException

I'm writing a custom error handler for Slim/3.3.0 and I'm trying to figure out if it's worth reusing the same code to handle both errors and exceptions. To do so I've defined a custom error handler to convert errors into ErrorException…
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
0
votes
1 answer

How Can I use PSR7 Middlewares in PHP

I've installed the following composer packages: "require": { "beatswitch/lock": "0.2.0", "league/event": "2.1.2", "oscarotero/psr7-middlewares": "v3.16.1", "pdepend/pdepend": "2.2.4", "sebastian/phpcpd": "2.0.4", "instaclick/php-code-sniffer":…
hardking
  • 193
  • 2
  • 17