Y
Y
YakutD2018-09-30 13:24:23
PHP
YakutD, 2018-09-30 13:24:23

Why do you need psr-7?

Please do not beat me with sticks for this question, I really cannot understand what its essence is, and I will be glad to clarify it with specific examples. I quote what confuses me on the example of Slim 2 and Slim 3.
For example, here:
5bb0a230b7162225396266.png
Why is it proposed to receive data from a get and a post in this way and not through the usual $_GET or $_POST?
Or here is an example of using the Twig template engine in Slim 2: and in Slim 3: The same bullshit with a redirect:
$app->render('test.html');
$this->view->render($response,'test.html');

//Slim 2
$app->redirect('/test');
//Slim 3
return $response->withRedirect('/test');

As for me, the options from Slim 2 are simpler and clearer. Tell me, what is the very feature of this standard, and in what cases is it really necessary, and in what cases can you do without it?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maksim Fedorov, 2018-09-30
@Maksclub

An exhaustive video on PSR-7 (the first of the entire cycle)
https://www.youtube.com/watch?v=w4iqxN0nfTs&list=P...
The video will answer - why do you need to wrap global variables in objects ?
To your code could be passed to other tools that also work with Request / Response objects ... moreover, other parts of the framework / other frameworks work with these objects - they modify, enrich, etc. ... For example, intermediaries, routers, controllers, etc. .d... And the standard itself is needed so that the creators of libraries / adapters / frameworks do everything through a single interface, which helps to exchange solutions or do it for several platforms at once
Well, then work with him, there is no torture in our time (for such work with globals)

A
Alexander Taratin, 2018-09-30
@Taraflex

To make Java/nodejs out of php (in a good way).

Y
Yuri, 2018-09-30
@riky

a wrapper over $_GET/$_POST is needed to make it convenient to write tests on your controllers later. Slim can be used both for small projects (where tests are almost never written), and for microservices, where it will be hard without tests.
secondly, you are immediately accustomed to good things by switching to another framework - you will already know how request / response works. In theory, it is easier to migrate to another framework both in code and in terms of learning.
If you have studied PSR7 once, then it is automatically easier for you to use all the libraries that use it, for example, Guzzle, PHPReact, etc.

O
OnYourLips, 2018-09-30
@OnYourLips

Why is it proposed to receive data from get and post in this way and not through the usual $_GET or $_POST?
Because global variables are evil.
Moreover, when the application starts, there can be many such requests, and passing them through global variables is doubly evil.
Moreover, psr-7 offers additional convenient methods for working with them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question