Coder Social home page Coder Social logo

Comments (17)

e-moe avatar e-moe commented on July 20, 2024 1

service definition looks good and should work. please check Symfony documentation for more details: https://symfony.com/doc/current/service_container.html#referencing-injecting-services

as for headers you can do it like this:
$client->get('http://example.com', ['headers' => ['X-Foo' => 'this is an extra header to include']]);
http://docs.guzzlephp.org/en/latest/quickstart.html

from guzzle6-bundle.

davidromani avatar davidromani commented on July 20, 2024 1

thanks again @e-moe

finally all works fine

from guzzle6-bundle.

e-moe avatar e-moe commented on July 20, 2024

@davidromani , could you please show me your config.yml file? Or share your code (if possible) so I can debug it

from guzzle6-bundle.

davidromani avatar davidromani commented on July 20, 2024

yes, for sure

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: sonata.yml }
    - { resource: media.yml }

parameters:
    locale: es

# Symfony
framework:
    translator:      { fallbacks: [ "%locale%" ] }
    secret:          "%secret%"
    router:
        resource:            "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: [ "twig" ]
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        name:        CKSESSID
        handler_id:  ~
    fragments:       ~
    http_method_override: true
    serializer:
        enabled: true
        enable_annotations: true

# Twig
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    form_themes:
        - "SonataCoreBundle:Form:datepicker.html.twig"
        - "::OhGoogleMaps/google_maps_form_widget.html.twig"
    globals:
        google_maps_api_key:      "%google_maps_api_key%"
        google_analytics_enabled: "%google_analytics_enabled%"
        google_analytics_account: "%google_analytics_account%"
        admin_tag_version:        "v1.0.19"

# Doctrine
doctrine:
    dbal:
        driver:         "pdo_mysql"
        host:           "%database_host%"
        port:           "%database_port%"
        dbname:         "%database_name%"
        user:           "%database_user%"
        password:       "%database_password%"
        charset:        "UTF8"
        server_version: "%database_server_version%"
        types:
            json: Sonata\Doctrine\Types\JsonType
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy:             doctrine.orm.naming_strategy.underscore
        auto_mapping:                true
        filters:
            softdeleteable:
                class:    Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
                enabled:  true

doctrine_migrations:
    dir_name:  "%kernel.root_dir%/../src/ClubKinder/AppBundle/DoctrineMigrations"
    namespace: ClubKinder\AppBundle\DoctrineMigrations

# Swiftmailer
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

# Assetic
assetic:
    debug:          "%kernel.debug%"
    use_controller: "%kernel.debug%"
    bundles:        [ "OhGoogleMapFormTypeBundle" ]
    filters:
        cssrewrite: ~

# Doctrine Extensions
stof_doctrine_extensions:
    default_locale:       "%locale%"
    translation_fallback: true
    orm:
        default:
            translatable:   false
            softdeleteable: true
            timestampable:  true
            sluggable:      true
            tree:           false
            sortable:       false

# FOS User
fos_user:
    db_driver:      orm
    firewall_name:  admin
    user_class:     Application\Sonata\UserBundle\Entity\User
    group:
        group_class:   Sonata\UserBundle\Entity\BaseGroup
        group_manager: sonata.user.orm.group_manager
    service:
        user_manager: sonata.user.orm.user_manager

# Ivory Google Map
ivory_google_map:
    map:
        language: "%locale%"
        api_key:  "%google_maps_api_key%"

# Ivory CKEditor
ivory_ck_editor:
    inline: false
    configs:
        my_config:
            toolbar: standard

# Guzzle Http Api Rest Client
emoe_guzzle:
    log:
        enabled: true
        format:  'Guzzle: [{ts}] \"{method} {uri} HTTP/{version}\" {code}'

from guzzle6-bundle.

e-moe avatar e-moe commented on July 20, 2024

Just checked bundle on fresh Symfony install and it worked correctly. Looks like you have some conflicts with dependencies. Is it possible to see your composer.json/lock as well?

from guzzle6-bundle.

davidromani avatar davidromani commented on July 20, 2024

I'm on a PHP 7.1 osx Liip distro https://php-osx.liip.ch

{
    "name": "<zzz>/<yyy>",
    "description": "<DESC>",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "": "src/"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },
    "require": {
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",
        "doctrine/doctrine-fixtures-bundle": "^2.3",
        "doctrine/doctrine-migrations-bundle": "^1.2",
        "doctrine/migrations": "^1.0",
        "egeloen/ckeditor-bundle": "^4.0",
        "egeloen/google-map-bundle": "^3.0",
        "egulias/email-validator": "^1.2",
        "e-moe/guzzle6-bundle": "^1.0",
        "hampe/zurb-ink-bundle": "^2.2",
        "hautelook/alice-bundle": "^1.0",
        "incenteev/composer-parameter-handler": "~2.0",
        "ircmaxell/password-compat": "~1.0",
        "liip/functional-test-bundle": "^1.0",
        "liip/imagine-bundle": "^1.0",
        "ocramius/proxy-manager": "1.0.2",
        "oh/google-map-form-type-bundle": "v1.0",
        "php": ">=5.6",
        "presta/sitemap-bundle": "^1.3",
        "symfony/symfony": "2.8.*",
        "symfony/assetic-bundle": "^2.8",
        "symfony/swiftmailer-bundle": "^2.3",
        "symfony/monolog-bundle": "^2.11",
        "sensio/distribution-bundle": "~5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "sonata-project/admin-bundle": "^3.0",
        "sonata-project/doctrine-orm-admin-bundle": "^3.0",
        "sonata-project/user-bundle": "^3.0",
        "stof/doctrine-extensions-bundle": "^1.2",
        "twig/twig": "^1.0",
        "twig/extensions": "^1.3",
        "vich/uploader-bundle": "^1.4"
    },
    "require-dev": {
        "cypresslab/gitelephant-bundle": "^0.0.6",
        "phpunit/phpunit": "^5.0",
        "sensio/generator-bundle": "~3.0"
    },
    "scripts": {
        "symfony-scripts": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-install-cmd": [
            "@symfony-scripts"
        ],
        "post-update-cmd": [
            "@symfony-scripts"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        }
    }
}

from guzzle6-bundle.

davidromani avatar davidromani commented on July 20, 2024

@e-moe still need composer.lock? I can provide it, no problem

from guzzle6-bundle.

e-moe avatar e-moe commented on July 20, 2024

@davidromani , please check my branch https://github.com/e-moe/guzzle6-bundle/tree/issue_11
I tried to install the same bundles as you have. Default controller (https://github.com/e-moe/guzzle6-bundle/blob/issue_11/src/AppBundle/Controller/DefaultController.php) successfully making requests and all guzzle related data is visible in Debug Profiler.

could you pls use this branch to reproduce the issue and send to me your changes?

from guzzle6-bundle.

davidromani avatar davidromani commented on July 20, 2024

@e-moe it works

captura de pantalla 2017-03-24 a les 12 10 59

from guzzle6-bundle.

e-moe avatar e-moe commented on July 20, 2024

Do you mean my branch? Would it be possible for you to apply changes into this code so it will be possible for me to reproduce the issue?

from guzzle6-bundle.

davidromani avatar davidromani commented on July 20, 2024

I cloned this branch and I've tried directly with php app/console server:run command. Maybe is a problem related with my Apache+PHP local config...

from guzzle6-bundle.

e-moe avatar e-moe commented on July 20, 2024

ok, please let me know if it will be possible to reproduce.

from guzzle6-bundle.

davidromani avatar davidromani commented on July 20, 2024

Nop, I've tried a simple request like in your example and it works fine. So probably, I've a problem here...

// src/(...)/AppBundle/Service/ApiRestClientService.php
<?php

namespace (...)\AppBundle\Service;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request as GuzzleRequest;
use Psr\Http\Message\ResponseInterface as Response;
use Symfony\Component\HttpKernel\KernelInterface;

/**
 * Class ApiRestClientService.
 *
 * @category Service
 */
class ApiRestClientService
{
    const METHOD_GET = 'GET';
    const METHOD_POST = 'POST';

    const FORMAT = 'json';

    const API_BRAND = '(...)';
    const API_KEY = '(...)';

    const BASE_URI_PROD = 'http://<xxx>/<yyy>/webresources/';
    const BASE_URI = 'http://<xxx_dev>/<yyy_dev>/webresources/';

    /**
     * @var Client
     */
    private $gc;

    /**
     * @var KernelInterface
     */
    private $kernel;

    /**
     * @var array
     */
    private $headers;

    /**
     * Methods.
     */

    /**
     * Constructor.
     *
     * @param KernelInterface $kernel
     */
    public function __construct(KernelInterface $kernel)
    {
        $this->headers =
            [
                'Accept' => 'application/'.self::FORMAT,
                'Content-Type' => 'application/'.self::FORMAT,
                'DPSApiKey' => self::API_KEY,
            ];

        $this->kernel = $kernel;
        if ($this->kernel->getEnvironment() == 'prod') {
            $this->gc = new Client(['base_uri' => self::BASE_URI_PROD]);
        } else {
            $this->gc = new Client(['base_uri' => self::BASE_URI]);
        }
    }

// (...)

from guzzle6-bundle.

e-moe avatar e-moe commented on July 20, 2024

Oh, I see. The reason is here: when you are creating guzzle Client objects in your code this bundle has no idea about them and of course can't log all events from it. If you want to have full integration with Symfony Debug Profiler you need to define guzzle clients objects as a services with guzzle.client tag:

services:
    guzzle.client_one:
        class: GuzzleHttp\Client
        tags:
            - { name: guzzle.client }

Or you can just use predefined service guzzle.client:

$response = $this->get('guzzle.client')->get('example.com');

from guzzle6-bundle.

e-moe avatar e-moe commented on July 20, 2024

Since it's not a bug I'm closing this issue.

from guzzle6-bundle.

davidromani avatar davidromani commented on July 20, 2024

@e-moe thanks for your time and my apologies.

One last question... how can I use it in my service definitions? I need to inject it in my own service an this doesn't works:

// services.yml
(...)
    guzzle.client_one:
        class: GuzzleHttp\Client
        tags:
            - { name: guzzle.client }
    app.api_rest_client:
        class:     (...)\AppBundle\Service\ApiRestClientService
        arguments:
            - "@kernel"
            - "@guzzle.client_one"
class ApiRestClientService
{
    // (...)

    public function __construct(KernelInterface $kernel, Client $gc)
    {
        $this->kernel = $kernel;
        $this->gc = $gc;

Have you ever tried to reuse guzzle.client_one into another service as a dependency? And lastly... how can I modify GuzzleClient headers after construct it?

from guzzle6-bundle.

e-moe avatar e-moe commented on July 20, 2024

welcome :)

from guzzle6-bundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.