Ok, I got this simple app working. Without changing any of the code!
What was the issue?
When I installed Slim-Http with composer with the following, composer installed version 0.4 without error.
composer require slim/http
I assumed that composer would install the latest stable version of the software. so I didn’t even notice the version number. Turns out that version 0.4 has no DecoratedServerRequestFactory or DecoratedResponseFactory. The latest version of Slim-Http is 1.3. When I tried to force that version with the following command I discovered that the newer versions of Slim-Http require the PHP extensions simplexml and fileinfo.
composer require slim/http:1.3
Because these extensions were missing, composer thought that it would be fine to use version 0.4.
Since I’m running this in a docker container on Alpine Linux, the fix is simply to:
apk add php81-simplexml php81-fileinfo
Then, remove and reinstall slim/http with composer.
Relevant Slim 4 Implementation Details
While adding echo statements all over Slim to figure out what’s going on, I found out the follow that may be helpful for others to know.
Slim-Http will decorate Nyholm, but it will also decorate slim/psr7 and probably the others too.
At least the isGet method worked. I haven’t done extensive testing.
You do not need any dependency injection classes or configuration for this to work.
App.run uses Slim\Factory\ServerRequestCreatorFactory to get the right Psr7 Request object. ServerRequestCreatorFactory uses Psr17FactoryProvider to look for the Psr7 implementation that is installed slim/psr7 nyholm/psr7, guzzlehttp, and laminas, then it will automatically wrap the ServerReqeust if (a recent version of) Slim-Http is installed.
The AppFactory class in Slim 4 does the same thing for creating Response objects.