8p / EightPointsGuzzleBundle

⛽️ Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony
MIT License
440 stars 71 forks source link

Error: You have requested a non-existent service #165

Closed ch1986 closed 6 years ago

ch1986 commented 6 years ago

Hi, when I try to use the guzzle client from a command I get an error associated with the name. For example,

CODE $client = $this->getContainer()->get('eight_points_guzzle.client.production_trading_api');

ERROR You have requested a non-existent service "eight_points_guzzle.middleware.request_time.production_trading_api". Did you mean one of these: "eight_points_guzzle.client.production_trading_api", "eight_points_guzzle.middleware.event_dispatch.production_policies_api", "eight_points_guzzle.middleware.event_dispatch.production_trading_api", "eight_points_guzzle.middleware.event_dispatch.sandbox_trading_api", "eight_points_guzzle.middleware.log.production_policies_api", "eight_points_guzzle.middleware.log.production_trading_api", "eight_points_guzzle.middleware.log.sandbox_trading_api"?

However, when I use the guzzle client from a controller it works fine. Could you please help me? Thanks

gregurco commented 6 years ago

@ch1986 could you provide your configuration of clients, please?

ch1986 commented 6 years ago

Hi, sure.

#config.yml
eight_points_guzzle:
    logging: true
    clients:   
        production_trading_api:
            base_url: "%ebay_production_trading_api_url%"
        sandbox_trading_api:
            base_url: "%ebay_sandbox_trading_api_url%"
        production_policies_api:
            base_url: "%ebay_production_policies_api_url%"
        sandbox_policies_api:
            base_url: "%ebay_sandbox_policies_api_url%"
        plesk_api:
            base_url: "%plesk_api_url%"
#parameters.yml
    ebay_production_trading_api_url: 'https://api.ebay.com'
    ebay_production_policies_api_url: 'https://svcs.ebay.com'
    ebay_sandbox_trading_api_url: 'https://api.sandbox.ebay.com'
    ebay_sandbox_policies_api_url: 'https://svcs.sandbox.ebay.com'
    plesk_api_url: 'https://51.140.186.85:8443'

Thanks

gregurco commented 6 years ago

@ch1986 I tested and it seems to be ok. I checked it from controller and from console command too and in dev and prod environments. Could you please try to clear cache for all environments and write here the result?

gregurco commented 6 years ago

@ch1986 I see there are all middlewares defined except request_time middleware. Probably you updated guzzle bundle and didn't clear cache.

ch1986 commented 6 years ago

Hi, I have cleared cache and problem persists. I don't understand why error says "eight_points_guzzle.middleware.request_time.production_trading_api" when the client is named "eight_points_guzzle.client.production_trading_api". Thanks

gregurco commented 6 years ago

@ch1986 each client has related services. In your case client is dependent on request_time middleware that is defined internally and used internally too. Somehow this service was not defined. Please try next steps:

  1. open file vendor/eightpoints/guzzle-bundle/src/DependencyInjection/EightPointsGuzzleExtension.php
  2. fine there $requestTimeMiddlewareDefinition->setPublic(false); and replace it by $requestTimeMiddlewareDefinition->setPublic(true); - public became true, not false. It's the only difference between this middleware and other, that are defined.
  3. clear cache
  4. try and write here the result.

And one more possibility. If the project is not private and you have possibility to share with me your code then you can zip the project and to send me by email (it's written on my profile page).

ch1986 commented 6 years ago

Hi, I follow the steps and the result is

[LogicException] Unable to register extension "Twig_Extension_Debug" as it is already registered.

Thanks

gregurco commented 6 years ago

@ch1986 I did an PR #166 with fix. Please run composer update eightpoints/guzzle-bundle to get latest version, clear cache and try one again. Thanks for your patience and help.

ch1986 commented 6 years ago

Hi, it works. Thank you so much

gregurco commented 6 years ago

@ch1986 Fine. I'm glad to see that it's ok now :slightly_smiling_face: thank you for reporting the problem and patience!

gregurco commented 6 years ago

@ch1986 could you write please which version of symfony do you use?

ch1986 commented 6 years ago

Hi, Symfony version 3.1.10 PHP version 7.1 Best regards

florianpreusner commented 6 years ago

Released in v7.3.0 (https://github.com/8p/EightPointsGuzzleBundle/releases/tag/7.3.0)