php-http / discovery

Finds installed clients and message factories
http://php-http.org
MIT License
1.28k stars 49 forks source link

DiscoveryFailedException Slim Request Factory #190

Closed NicoP-S closed 4 years ago

NicoP-S commented 4 years ago

PHP version: 7.3.23

Description

I am trying to get GitLabPHP/Client running with Slim Psr7 ( psr17 compliant ). It uses discovery.

The Docs say that slim framework should work:

A built-in strategy supporting the HTTPlug adapters, clients and factories (including Symfony, Guzzle, Diactoros and Slim Framework)

Error Message:

PHP Fatal error:  Uncaught Http\Discovery\Exception\DiscoveryFailedException: Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors
 - Puli Factory is not available
 - No valid candidate found using strategy "Http\Discovery\Strategy\CommonClassesStrategy". We tested the following candidates: .
 - 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.

 in /tmp/gitlabtest/vendor/php-http/discovery/src/Exception/DiscoveryFailedException.php:41
Stack trace:
#0 /tmp/gitlabtest/vendor/php-http/discovery/src/ClassDiscovery.php(79): Http\Discovery\Exception\DiscoveryFailedException::create(Array)
#1 /tmp in /tmp/gitlabtest/vendor/php-http/discovery/src/Psr17FactoryDiscovery.php on line 22

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

I don't know if it is a problem of slimphp/Slim-Psr7 or this repo. Or maybe my setup?

How to reproduce

composer require m4tthumphrey/php-gitlab-api:^10.0 guzzlehttp/guzzle:^7.0.1 slim/slim slim/psr7

test.php:

<?php
include('vendor/autoload.php');
$client = new \Gitlab\Client();

Possible Solution

Additional context

GitLabPHP/Client#586

NicoP-S commented 4 years ago

@webmaster777 like you said i checked the CommonPsr17ClassesStrategy.php https://github.com/slimphp/Slim-Psr7/issues/172#issuecomment-710064738

It references

'Http\Factory\Slim\RequestFactory'
'Http\Factory\Slim\ResponseFactory'
'Http\Factory\Slim\ServerRequestFactory'
'Http\Factory\Slim\StreamFactory'
'Http\Factory\Slim\UploadedFileFactory'
'Http\Factory\Slim\UriFactory'

I think the namespace is not correct anymore. Correct would be Slim\Psr7\Factory\... https://github.com/slimphp/Slim-Psr7/tree/master/src/Factory

Am i right? Sorry for asking.

dbu commented 4 years ago

are these Http\Factory\Slim* things a legacy thing and the current slim thing is Slim\Psr7\Factory*? if that is the case, it would be great if you can do a pull request to add the Slim\Psr7 classes in the appropriate places so that they can be discovered.

webmaster777 commented 4 years ago

I found the old repo for factories btw: https://github.com/http-interop/http-factory-slim It indeed predates the PSR-17 implementation of Slim.

In order to maintain BC we should only add the new Slim implementations, right?