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

Can't install this bundle in Symfony 4.2 or 4.3 #34

Open
walva opened this issue Aug 13, 2019 · 2 comments
Open

Can't install this bundle in Symfony 4.2 or 4.3 #34

walva opened this issue Aug 13, 2019 · 2 comments

Comments

@walva
Copy link

walva commented Aug 13, 2019

Hi there!

I am very interested in using this bundle for our project but we couldn't achieve to install it and make it work.

So I tried to reproduce our error in a brand new project.
Here are the step I followed:

  • symfony new httpclient
  • composer require symfony/maker-bundle
  • composer require template
  • composer require annotations
  • php bin\console make:controller
  • composer require happyr/google-analytics-bundle
  • composer require php-http/curl-client guzzlehttp/psr7 php-http/message

-> didn't work because of the error message:

Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors

  • composer require php-http/httplug-bundle php-http/curl-client guzzlehttp/psr7
  • composer require php-http/guzzle6-adapter

at this point, the kernel is compiling correctly and we created the branch master of our test project

Here is the error I have:

Argument 2 passed to Happyr\GoogleAnalyticsBundle\Http\HttpClient::__construct() must be an instance of Psr\Http\Message\RequestFactoryInterface, instance of Nyholm\Psr7\Factory\HttplugFactory given, called in C:\www\sportfinder\httpclient\var\cache\dev\ContainerIewfoAf\getTrackerService.php on line 14

Because the bundle still wasn't working, I tried to use Symfony HttpClient in the other branch use-symfony-client

  • git checkout use-symfony-client
  • composer require symfony/http-client
  • composer require psr/http-client
  • composer require nyholm/psr7

Here is the error:

Argument 2 passed to Happyr\GoogleAnalyticsBundle\Http\HttpClient::__construct() must be an instance of Psr\Http\Message\RequestFactoryInterface, instance of Nyholm\Psr7\Factory\HttplugFactory given, called in C:\www\sportfinder\httpclient\var\cache\dev\ContainerD52DYTq\getTrackerService.php on line 14

At this point, I honestly don't know what to do :s
I'm here to help with my limited knowledge of php http client ecosystem.

Best regards,
Benjamin

@jon-ht
Copy link

jon-ht commented Sep 21, 2019

Hi @SulivanDotEu

I encountered the same problem as you and tested most of your installs. In the end, here is what I've done to fix it :

  1. composer require symfony/http-client (if not already in your dependencies)
  2. psr/http-client is required by this bundle, but you can add it as root dependency
  3. composer require nyholm/psr7
  4. composer require happyr/google-analytics-bundle. Here my setup for the bundle
    happyr_google_analytics:
        tracking_id: '%env(GOOGLE_ANALYTICS_TRACKING_ID)%'
        http_client: 'Psr\Http\Client\ClientInterface'
        http_message_factory: 'nyholm.psr7.psr17_factory'

Symfony autowiring is able to resolve Psr\Http\Client\ClientInterface because, in my case, there is only one implementation.

I also made it work with HTTPlug Bundle by configuring a client and then use

happyr_google_analytics:
    tracking_id: '%env(GOOGLE_ANALYTICS_TRACKING_ID)%'
    http_client: 'httplug.client.happyr_analytics'
    http_message_factory: 'nyholm.psr7.psr17_factory'

And httplug.client.happyr_analytics relies on

httplug:
    # ...
    clients:
        # ...
        happyr_analytics:
            http_methods_client: true

I hope it will help

@grekpg
Copy link

grekpg commented Apr 2, 2020

I install (Symfony 4.3)

composer require symfony/http-client (if not already in your dependencies)
psr/http-client is required by this bundle, but you can add it as root dependency
composer require nyholm/psr7
composer require happyr/google-analytics-bundle

and
composer require php-http/httplug-bundle

config :

happyr_google_analytics:
tracking_id: 11111
http_client: 'httplug.client.happyr_analytics'
http_message_factory: 'nyholm.psr7.psr17_factory'

httplug:
plugins:
retry:
retry: 1

discovery:
    client: 'auto'

clients:
    happyr_analytics:
        http_methods_client: true
    app:
        http_methods_client: true
        plugins:
            - 'httplug.plugin.content_length'
            - 'httplug.plugin.redirect'

But still have an error

Argument 1 passed to Happyr\GoogleAnalyticsBundle\Http\HttpClient::__construct() must be an instance of Psr\Http\Client\ClientInterface, instance of Http\Client\Common\HttpMethodsClient given,

ok I change

happyr_google_analytics:
tracking_id: UA-1634831-41
http_client: 'Psr\Http\Client\ClientInterface'
http_message_factory: 'nyholm.psr7.psr17_factory'

now it work.
installing this bundle is very complicated

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

No branches or pull requests

3 participants