GitLabPHP / Client

GitLab API v4 client for PHP
MIT License
933 stars 452 forks source link

Slim RequestFactory not working #586

Closed NicoP-S closed 4 years ago

NicoP-S commented 4 years ago

Hello I am trying to get GitlabPHP running in my slim project. The docs at https://docs.php-http.org/en/latest/httplug/users.html said it should work with slim too.

$ composer require php-http/message slim/slim

Part of my composer.json:

        "slim/slim": "^4.5",
        "slim/http": "^1.0",
        "slim/psr7": "^1.2",
        "php-di/php-di": "^6.2",
        "m4tthumphrey/php-gitlab-api": "^10.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "php-http/message": "^1.9"

Error Message:

{
    "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?

GrahamCampbell commented 4 years ago

Those docs are for how to use the legacy http plug interfaces. We now use PSR-17 and PSR-18.

NicoP-S commented 4 years ago

@GrahamCampbell I think slim/psr7 is psr-17 compliant

https://github.com/slimphp/Slim-Psr7/blob/master/composer.json#L46-L49

I also tryied writing the part from the psr-17 docs into my controller https://docs.php-http.org/en/latest/discovery.html#psr-17-factory-discovery Is there an example anywhere?

GrahamCampbell commented 4 years ago

Maybe this is an issue with the discovery package.

webmaster777 commented 4 years ago

You can force the factories by providing them to the Builder class:

$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);

Or more fancy using DI-containers.

GrahamCampbell commented 4 years ago

Replaced by https://github.com/php-http/discovery/issues/190.