1
votes

Edit: resolved. I just downgraded to slim 3.

I'm getting the following error message. I already tried "composer require slim/http" and "composer require slim/psr7".

Uncaught RuntimeException: Could not detect any PSR-17 ResponseFactory implementations. Please install a supported implementation in order to use AppFactory::create(). See https://github.com/slimphp/Slim/blob/4.x/README.md for a list of supported implementations. in /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/Factory/AppFactory.php:166 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/Factory/AppFactory.php(92): Slim\Factory\AppFactory::determineResponseFactory() #1 /Applications/XAMPP/xamppfiles/htdocs/MyApi/public/index.php(12): Slim\Factory\AppFactory::create() #2 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/MyApi/vendor/slim/slim/Slim/Factory/AppFactory.php on line 166

1
This is the PR that decouples things from Slim and includes examples of using PSR-7 and PSR-17, maybe that will help. - Chris Haas
This Slim 4 Tutorial explains how to setup a basic Slim app. - odan

1 Answers

0
votes

I had the same problem on Slim 4, but I solved it by adding slim / psr7 with the composer. Try giving the command 'composer dump' after this. Below is how are the files "composer.json" and "index.php"

my composer.json;

{
    "name": ".../...",
    "description": "....",
    "type": "project",
    "license": "MIT",
    "authors": [
        {
            "name": "....",
            "email": "......."
        }
    ],
    "minimum-stability": "dev",
    "require": {
        "slim/slim": "4.*",
        "slim/psr7": "dev-master"
    }
    }
}

my index.php;

<?php

// https://github.com/slimphp/Slim/blob/4.x/README.md

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

/**
 * Instantiate App
 *
 * In order for the factory to work you need to ensure you have installed
 * a supported PSR-7 implementation of your choice e.g.: Slim PSR-7 and a supported
 * ServerRequest creator (included with Slim PSR-7)
 */
$app = AppFactory::create();

// Add Routing Middleware
$app->addRoutingMiddleware();

/**
 * Add Error Handling Middleware
 *
 * @param bool $displayErrorDetails -> Should be set to false in production
 * @param bool $logErrors -> Parameter is passed to the default ErrorHandler
 * @param bool $logErrorDetails -> Display error details in error log
 * which can be replaced by a callable of your choice.
 
 * Note: This middleware should be added last. It will not handle any exceptions/errors
 * for middleware added after it.
 */
$errorMiddleware = $app->addErrorMiddleware(true, true, true);

// My first Route
$app->get('/', function (Request $request, Response $response, $args) {

    $response->getBody()->write("Hello World!");
    return $response;
});

// Run app
$app->run();