Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim RequestFactory not working #586

Closed
NicoP-S opened this issue Oct 15, 2020 · 5 comments
Closed

Slim RequestFactory not working #586

NicoP-S opened this issue Oct 15, 2020 · 5 comments

Comments

@NicoP-S
Copy link

NicoP-S commented Oct 15, 2020

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
Copy link
Member

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

@NicoP-S
Copy link
Author

NicoP-S commented Oct 15, 2020

@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
Copy link
Member

Maybe this is an issue with the discovery package.

@webmaster777
Copy link
Contributor

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
Copy link
Member

Replaced by php-http/discovery#190.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants