slimphp / Slim-Psr7

PSR-7 implementation for use with Slim 4
MIT License
134 stars 45 forks source link

psr17 discorvery not working #172

Closed NicoP-S closed 4 years ago

NicoP-S commented 4 years ago

Hi, i am trying to get slim psr-7 running in an project where https://github.com/php-http/discovery is used. But I get following error.

{
    "message": "Slim Application Error",
    "exception": [
        {
            "type": "Http\\Discovery\\Exception\\NotFoundException",
            "code": 0,
            "message": "No PSR-17 request factory found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation",
            "file": "/srv/www/clients/client1/web52/web/vendor/php-http/discovery/src/Psr17FactoryDiscovery.php",
            "line": 22
        },
        {
            "type": "Http\\Discovery\\Exception\\DiscoveryFailedException",
            "code": 0,
            "message": "Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors\n - Puli Factory is not available\n - No valid candidate found using strategy \"Http\\Discovery\\Strategy\\CommonClassesStrategy\". We tested the following candidates: .\n - No valid candidate found using strategy \"Http\\Discovery\\Strategy\\CommonPsr17ClassesStrategy\". We tested the following candidates: Phalcon\\Http\\Message\\RequestFactory, Nyholm\\Psr7\\Factory\\Psr17Factory, Zend\\Diactoros\\RequestFactory, GuzzleHttp\\Psr7\\HttpFactory, Http\\Factory\\Diactoros\\RequestFactory, Http\\Factory\\Guzzle\\RequestFactory, Http\\Factory\\Slim\\RequestFactory, Laminas\\Diactoros\\RequestFactory.\n\n",
            "file": "/srv/www/clients/client1/web52/web/vendor/php-http/discovery/src/Exception/DiscoveryFailedException.php",
            "line": 41
        }
    ]
}

It tests for Http\Factory\Slim\RequestFactory. I have checked my vendor dir. I only have Slim\Psr7\Factory\RequestFactory

Am I doing something wrong ? Or is this a bug in one of slim/psr7 or php-http/discovery ?

webmaster777 commented 4 years ago

Meh, it's not a bug. The factories in this repo are just not in any of the default strategies (e.g. CommonClassesStrategy)

The factories it does look for are in an other repo (https://github.com/slimphp/Slim-Http). However, you should be able to configure your container to use the factories in this repo.

webmaster777 commented 4 years ago

You could also provide your own strategy to resolve into the classes in this repo, or send a PR to php-http/discovery to add these classes to the CommonClassesStrategy

webmaster777 commented 4 years ago

ref: https://github.com/GitLabPHP/Client/issues/586

NicoP-S commented 4 years ago

I also tried with slim/http but it gives the same error.

$ composer require slim/http

I will go the way you mentioned https://github.com/GitLabPHP/Client/issues/586#issuecomment-710072846

$builder = new Gitlab\HttpClient\Builder( null, // PSR-18 client autodetect new Slim\Psr7\Factory\RequestFactory(), new Slim\Psr7\Factory\StreamFactory(), new Slim\Psr7\Factory\UriFactory() );

$client = new Gitlab\Client($builder);

Thanks for your help!

webmaster777 commented 4 years ago

I also tried with slim/http but it gives the same error.


$ composer require slim/http

Makes sense, slim/http only decorates the classes, it does not provide actual psr-7 or psr-17 implementation itself I think.