Oficial documentation?


use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;

why not

use Slim\Psr7\Request; // implements Psr\Http\Message\ServerRequestInterface
use Slim\Psr7\Response; // implements Psr\Http\Message\ResponseInterface

we installed slim/psr7


Because it’s best practice to implement against an interface (if one exists), instead of implementing against a real implementation. Slim will pass the proper PSR-7 for you (for example slim/psr7).

It is not very clear why we are pulling the dependency on slim / psr7 in which the interface is implemented, if it is good practice to implement the interface directly ??? ))) Is this some kind of brilliant idea?
Why do we need to install slim / psr7 then ??? Does anyone make money from downloading? )))

Slim itself does not pull in or rely on Slim-Psr7 as you can see from the composer.json. Instead we rely on the standard PSR7 interfaces, so that someone can use Slim with any PSR-7 implementation (e.g. Diactoros).

However, a working Slim application needs a PSR-7 implementation, so we provided one in Slim-Psr7. This is an independent component from Slim itself though and you aren’t required to use it. However, I expect most Slim applications use Slim-Psr7 as it’s a reasonable implementation of the PSR-7 standard and it’s provided in the Skeleton application.

The main advantage of Slim relying on the interface is that you are not required to use Slim-Psr7. You can replace it with one that doesn’t very easily as that’s how coding to an interface works. i.e. by using an interface, we have coded to the “D” in the SOLID principles to make our users’ lives easier when they need alternatives to our code.

Unfortunately, we don’t make money directly from Slim downloads. However, feel free to sponsor us via Open Collective or Tidelift!

  1. Interface
  2. Library that implements the interface
  3. A framework that requires point 2, BUT implements point 1 on its own

Can you tell me where the logical connection is broken in this place? )))

I don’t understand your question.

The PSR-7 interface is defined in psr/http-message, not by Slim.

Slim Framework requires a component that implements this interface. There are many to chose from such as guzzlehttp/psr7, zend/diactoros, nyholm/psr7, ringcentral/psr7 & slim/psr7. Any of these PSR-7 implementations will work with Slim 4.