We need to figure out a way to run a script after we do composer require slim/Slim which will ask you to pick a PSR-7 implementation of your choice (or none) so we can keep the UX of Slim installation smooth.
I think that this should be a vanilla CLI with no dependencies that simply asks the following question:
_____ _ _ _ _
/ ____| (_) | || |
| (___ | |_ _ __ ___ __ _| || |_
\___ \| | | '_ ` _ \ \ \ / /__ _|
____) | | | | | | | | \ V / | |
|_____/|_|_|_| |_| |_| \_/ |_|
Slim 4 requires you to install a PSR-7 implementation and ServerRequest generator.
Please choose one of the following PSR-7 Implementations:
1. Slim-Psr7
2. Nyholm/Psr7 & Nyholm/Psr7Server
3. Zend-Diactoros
4. Guzzle PSR-7 and Guzzle Factory
I'm not married to the wording here, I'm looking for some input.
Are you sure that we need it for the Slim framework itself? Some people use Slim as "library" and not directly as application. IMO this script is fine, but it should be part of an extra Slim 4 skeleton package. For example slimphp/slim4-skeleton. What do you think?
Yeah I'm not sure @odan where specifically this fits in, @akrabat and I had an internal conversation about it and if someone was to do composer require slim/Slim we think that it should be triggered. Definitely needs to be in slimphp/slim4-skeleton.
Loosely, I'm looking for a way to make it as easy to use Slim 4 without the skeleton as it is to use Slim 3 today. I'm open to ideas.
Currently you can do composer require slim/slim and then create an index.php with:
<?php
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
and you're done.
I want something as easy.
One idea is to ask the user which PSR-7 they want when you do composer require slim/slim.
Another is to simply message: composer require slim/slim slim/psr7.
In either case, we also need a way to make what's in index.php nice and simple too, which is covered by #2621.
If we do message composer require slim/slim slim/psr7 for the "simple" solution, then there's definitely an argument for having the PSR-7 selection in the skeleton regardless.
As a user I think Slim should come with Slim PSR-7 implementation by default and a separate script should be available to swap between other implementations.
A beginner user may not even know about this different implementations, what makes easier for them to start working with Slim.
In the other hand a user that understands the implications of changing to a different implementation should be alright with an extra command to the cli, since it's a one time job.
@JeanPaiva we are not shipping Slim 4 with a PSR-7 implementation. We will be creating a skeleton project that will ship with one though for less advanced users who don鈥檛 know how to make that choice.
maybe https://github.com/narrowspark/automatic can help you. It has automatic configuration for packages, a skeleton generator if you need it and a bit more
Thank you for the suggestion @prisis!
One more thing, you can find some skeleton generator in this repo https://github.com/narrowspark/skeleton-generators and if you need custom configurations https://github.com/narrowspark/configurators/
And https://github.com/narrowspark/narrowspark has a working example for you
I'm hoping beginners will use the skeleton.
However, our messaging around installing "plain and simple" Slim will be either composer require slim/slim slim/psr7 or a post-install script that asks the user.
I added some descriptive error messages when using AppFactory::create(). When no PSR-7 implementation can be detected you will be told to install one.
This post-install script does not seem to be deemed necessary due to the recent changes made. If we get a lot of users requesting help with this matter I will re-open the issue.