Code Monkey home page Code Monkey logo

csaguzzlebundle's Introduction

CsaGuzzleBundle

Gitter

Latest Stable Version Latest Unstable Version Total Downloads License Travis Build Status SymfonyInsight Appveyor Build Status

Description

This bundle integrates Guzzle >=4.0 in Symfony. Versions 2.x and 3.x support Guzzle 6 and versions 1.x support Guzzle 4 and 5.

Currently, the bundle supports the following features:

  • Integration with Symfony's debug tools (web debug toolbar, profiler, logger, timeline, ...)
  • Configuring a Guzzle client simply using configuration
  • Multiple middleware / subscribers (logger, profiler, timeline, cache, mock, and more to come)
  • Service descriptions to describe your services in json format (only in the 1.3 branch, though)

Web debug Toolbar Profiler panel integration Profiler timeline integration

Installation

All the installation instructions are located in the documentation

Upgrade

Although I try to guarantee forward-compatibility of the bundle with previous versions. Here are the upgrade notes between each version.

See Upgrade.md.

Support

As Guzzle 4 and Guzzle 5 are no longer supported by its creator, you should aim to migrate to Guzzle 6.x as soon as possible. Versions 1.x of this bundle are no longer supported, and version 2.x of will be supported until Symfony 2.8 EOL (November 2018).

Documentation

Documentation for stable (3.x)

Documentation for legacy (2.x)

Contributing

CsaGuzzleBundle is an open source project. If you'd like to contribute, please read the Contributing Guidelines.

License

This library is under Apache License 2.0. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

csaguzzlebundle's People

Contributors

avariya avatar coil avatar cordoval avatar csarrazi avatar dependabot[bot] avatar dunglas avatar e-moe avatar gitter-badger avatar hervems avatar iamluc avatar ivoba avatar j0k3r avatar jderusse avatar kgilden avatar mateuszsip avatar mroca avatar nud avatar orasik avatar owlycode avatar roestvrijstaal avatar rolebi avatar rpg600 avatar rvanlaak avatar salahm avatar slayful avatar sofhad avatar sroze avatar tobion avatar tonydub avatar xkobal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csaguzzlebundle's Issues

Supplying auth to the service.

Previously i had a service that looked like this:

  guzzle.example:
    class: GuzzleHttp\Client
    factory: ["@csa_guzzle.client_factory", create]
    arguments:
      options:
        "base_url" : "http://127.0.0.1"
        defaults:
          "auth" : [ "user", "password" ]

That worked great.

I upgraded symfony/this bundle and started getting deprecation notices that the factory was going away.

I tried to rewrite it like this, according to the documentation:

csa_guzzle:
    profiler: %kernel.debug%
    clients:
        example:
            config:
                base_url: "http://127.0.0.1"
                defaults:
                    auth : [ "user", "password" ]

In my config.yml instead of the services.yml

The problem is that this doesnt seem to use the auth-information. How to i supply the auth-information (basic http authentication) this way?

Remove ClientFactory

As mentioned in #19, once the csa_guzzle.client tag will be implemented, the Csa\Bundle\GuzzleBundle\Factory\ClientFactory will be deprecated, and should be removed in v2.0.0.

ContextErrorException in GuzzleCollector.php line 65: Notice: Undefined index: response

Hello,

I just have updated the bundle today using the @stable branch, and I now encountering the following error:

ContextErrorException in GuzzleCollector.php line 65: Notice: Undefined index: response

I was still using the @stable branch a couple of days ago, and everything was fine.

For the record, here are my configurations when using the bundle:
config.yml:

csa_guzzle:
    clients:
        my_api:
            config:
                base_url: %api.url%
                defaults:
                    headers:
                        Accept: %api.headers.accept%

services.yml:

services:
    bundle_api.api_client:
        class: Api\ApiBundle\Service\ApiClient
        arguments:
            - "@request_stack"
            - "@csa_guzzle.client.my_api"
            - "%locale.default%"

ApiClient.php:

use Csa\Bundle\GuzzleBundle\HttpFoundation\StreamResponse;
use GuzzleHttp\Client as GuzzleClient;
use Symfony\Component\HttpFoundation\RequestStack;

class ApiClient
{
    private $client;
    private $currentLocale;

    /**
     * Constructor
     * @param string $localeDefault 
     */
    public function __construct(RequestStack $requestStack, GuzzleClient $client, $localeDefault)
    {
        $this->client = $client;
        $this->currentLocale = (!$requestStack->getCurrentRequest()) ? $localeDefault : $requestStack->getCurrentRequest()->getLocale();
    }

Anyway, thank you for your bundle and the efforts you provide to keep it up-to-date ;-)

Custom client

I'm declaring my client as a service since I wish to inject some dependencies in it. My client declaration is:

services:
    api.client:
        class: FrontBundle\Client\ApiClient
        arguments:
            - @router
            - http://localhost/api
        tags: [ { name: csa_guzzle.client } ]

However this throw the following error:

PHP Fatal error:  Cannot use object of type Symfony\Component\DependencyInjection\Reference as array in /path/to/myProject/vendor/csa/guzzle-bundle/src/DependencyInjection/CompilerPass/MiddlewarePass.php on line 106

Any idea?

Edit:

  • Using Symfony2.7 and the version dev-master of the bundle

Add class parameter in client config

In order to use custom client classes, we actually need to declare a tagged service and inject the config array as argument.

A class config option should be a good functionality, for example :

csa_guzzle:
    profiler: %kernel.debug%
    logger: true
    clients:
        my_api:
            class: MyBundle\MyClient
            config:
                base_url: %api_url%
                defaults:
                    headers:
                        Accept: application/ld+json

Question: cURL error 3: <url> malformed

Hi,

I started to implementation but I quickly ran into the following strange error

cURL error 3: <url> malformed

Implementation

        $client = $this->get('csa_guzzle.client.api_test');
        $response = $client->request('GET', '/api');

Config

csa_guzzle:
    clients:
        api_test:
            config:
                base_url: "http://localhost:3000"
                defaults:
                    headers:
                        Accept: application/json
            middleware:       []
            class:            GuzzleHttp\Client

If I'm using the full URL, it's working fine

        $client = $this->get('csa_guzzle.client.api_test');
        $response = $client->request('GET', 'http://localhost:3000/api');

Can you point me what I'm doing wrong?
It most be something in my config?

Missing guzzlehttp/log-subscriber in 1.2.4

Hi,

I am having problems with the latest release of the bundle. The error is "Fatal error: Class 'GuzzleHttp\Subscriber\Log\Formatter' not found in .../src/DependencyInjection/Configuration.php on line 61"

I checked the composer.json of version 1.2.4 and could not find a requirement for guzzlehttp/log-subscriber or am I missing something?

missing class logger

please tag it else it straight gives an error when using the last tagged version ~1.2.5

thanks

good job

great job man, i am glad to see good updated well taken care bundles like this, will contribute! ๐Ÿ‘

GuzzleCollector undefined index `response`, and `error`.

In GuzzleCollector, on line 65 and 66, you are assuming these indexes exist, yet further down, you check if they have any value. If there isn't a response or error, PHP will throw an exception in 7 or a notice in 5. Either way, it's trying to access something that doesn't always exist.

Also, it's generally not a good idea to reuse the same variable name as a method parameter, which you are doing for $response.

Example of usage needed

It's not very detailed docs. Actually can't understand how to use it after install at all. Please add some more info

WebProfiler Error and Success counters

Hi.

I am doing tests for guzzle "events" and "transfer info", so I execute the first time an URI that response a 404 error and retrying using the correct URI. At the end, I have 1 error and 1 success but the web profiler shows 1 error en "2" success. I think this is an error.

I am using this code so you can understand:

service.yml:

csa_guzzle:
    profiler: true
    logger: true
    clients:
        api:
            config:
                base_url: http://localhost/
            subscribers:
                debug: true
                stopwatch: true
                logger: false

controller:


public function indexAction()
    {
        $client = $this->get('csa_guzzle.client.api');

        $response = $client->get(
            '/AndroidRestServices/web/index.php/tiendass',
            [
                'events' => [
                    'before' => function (BeforeEvent $e) use (&$transfer) {
                        $this->get('logger')->info('BEFORE EVENT');
                    },
                    'progress' => function (ProgressEvent $e) use (&$transfer) {

                        $progressInfo = 'Downloaded '.$e->downloaded.' of '.$e->downloadSize.' '
                            .'Uploaded '.$e->uploaded.' of '.$e->uploadSize.PHP_EOL;

                        $this->get('logger')->info('PROGRESS EVENT: '.$progressInfo);
                    },
                    'complete' => function (CompleteEvent $e) use (&$transfer) {
                        $this->get('logger')->info('COMPLETE EVENT');
                    },
                    'error' => function (ErrorEvent $e) use (&$transfer) {
                        $this->get('logger')->info('ERROR EVENT');

                        if ($e->getResponse()->getStatusCode() == Response::HTTP_NOT_FOUND) {
                            $e->getRequest()->setPath('/AndroidRestServices/web/index.php/tiendas');
                            $newResponse = $e->getClient()->send($e->getRequest());
                            $e->intercept($newResponse);
                        }
                    },
                    'end' => function (EndEvent $e) use (&$transfer) {
                        $this->get('logger')->info('END EVENT');

                        $transfer = $e->getTransferInfo();
                        dump($transfer);
                    },
                ]
            ]
        );

        return $this->render('default/index.html.twig');
    }

example

Division by zero warning in profiler for failed requests

Steps to reproduce:

  • Create a request with Guzzle to a host that can't be resolved;
  • You should see a cURL error 6: Couldn't resolve host 'foo'error;
  • Navigate to _profiler/__token__?panel=guzzle;

And you're welcomed with

An exception has been thrown during the rendering of a template ("Warning: Division by zero") in @CsaGuzzle/Calls/call.html.twig at line 26.

This happens because the total request time here is zero. Dunno how it should behave though in that case.

[Doc] Improve register bundle example

On the current documentation there is this example:

<?php
// in %kernel.root_dir%/AppKernel.php
$bundles[] = new Csa\Bundle\GuzzleBundle\CsaGuzzleBundle();

I think we should replace it to this:

$bundles = array(
    // ...
    new Csa\Bundle\GuzzleBundle\CsaGuzzleBundle(),
    // ...
);

Reason: I think this bundle is mostly used as normal bundle and not only in dev/test environments.

Ability to configure the client by service id.

I think it is very interesting to have ability to configure a client by service id.
(Using a proxy class for example )

csa_guzzle:
    clients:
        github_api:
            service: my_client.service
            config:
                base_url: https://api.github.com
                defaults:
                    headers:
                        Accept: application/vnd.github.v3+json

(I can work on)

Add support for guzzle/guzzle-services

This will enable the support for Guzzle services.

  • Add support for guzzle services in the semantic configuration
  • Add dependency recommendation in composer
  • Implement logic
  • Add documentation
  • Implement logic in the DI extension
  • Add unit tests
  • Add even more unit tests

Unknown "asset" function in CsaGuzzleBundle:Collector:guzzle.html.twig

Using Symfony 2.7, I receive Unknown "asset" function in CsaGuzzleBundle:Collector:guzzle.html.twig at line 54. on every profiler page.

I tried to find other examples, but I don't see other included profiler pages using asset(). Not sure why this doesn't work as I registered this bundle after the twig bundle which has the function.

Error while upgrade from 1.0.3 to dev-master

It should be written in the doc that the version of guzzle should be choosed in the project, as the bundle is now compatible with Guzzle 4 & 5.

And with guzzle 4, I have this error:

Catchable Fatal Error: Argument 1 passed to Csa\Bundle\GuzzleBundle\GuzzleHttp\Subscriber\StopwatchSubscriber::onFinish() must be an instance of GuzzleHttp\Event\AbstractRetryableEvent, instance of GuzzleHttp\Event\CompleteEvent given, called in /.../vendor/guzzlehttp/guzzle/src/Event/Emitter.php on line 105 and defined

[Doc] The configuration reference seems not up to date

Tree builder for cachenode have been recently changed, and the doc was not updated.
The old one :

cache:
        enabled:              false
        type:                 doctrine
        service:              ~

The new one :

cache:
        enabled:              false
        service:              ~
        adapter: 
            type:                 doctrine

[2.0] Support for Guzzle Services

Currently, there is no information about the future of guzzlehttp/guzzle-services. For now, support for Guzzle services is not available, and is the only blocking issue until there is further information.

[readme] add some screenshot of the profiler panel and more usage example

first thanks for the project, however I think the readme could be made a bit better in order to present fully the capacity of this bundle

first, while I was trying to decide which guzzle bundle to use (there's quite some), the guzzle>4 was truly a selling point, but however some others were directly staging and presenting their symfony2 profiler panel, which I thought at first your project didn't have , stating it clearly with screenshots may help.

also putting a bit more example of usage may also help people (on this regard I found the readme of https://github.com/LeaseWeb/LswGuzzleBundle quite good), because your readme stop at configurating the service but not on how to use it.

Tag pre-existing guzzle clients

I just got bit from another guzzle bundle which seems to be abandoned. It would be nice if this bundle had a few service container tags to tag guzzle clients not created by this bundle's factory. Something along the lines of

<service id="my_client" class="GuzzleHttp\Client">
    <tag name="csa_guzzle.use_subscriber" subscriber="debug" />
</service>

And bam! my client's debug data would show up in the profiler. Furthermore, since guzzle services now essentially wrap clients, they would be covered as well. Very little coupling with the bundle.

What do you think? Are PR-s welcome?

Nice bundle btw.

More friendly URLs

When requesting an URI with query like GET /api/mandates?filter[order][startAt]=desc, the effective URL generated for the request is http://localhost/api/mandates?filter%5Border%5D%5BstartAt%5D=desc. While it's fine, could it be possible to have the urldecode() version displayed in the profiler? The decoded version is... a pain to read.

Using the 1.3 version of the bundle with Guzzle 3.9.

GuzzleCollector undefined index `response`

When running a basic setup I get the following exception:

ContextErrorException in GuzzleCollector.php line 65:
Notice: Undefined index: response

My config is

csa_guzzle:
  profiler:
    enabled: %kernel.debug%
  logger:
    enabled: true
  clients:
    github:
      config:
        base_uri: http://github.com

My controller is simple:

    public function indexAction()
    {
        $response = $this->get('csa_guzzle.client.github')->get('/');
        return new Response($response->getBody()->getContents());
   }

This is using "csa/guzzle-bundle": "^2.0"

[Doc] The documentation should be updated

Like mentioned on the title. Release 1.2.0 should have an updated doc.

  • Add documentation for semantic configuration
  • Configuration reference
  • Add documentation for subscribers
    • Profiler
    • Logger
    • Cache

Bug with tag csa_guzzle.client

Hello @csarrazi

First of all,

I read the documentation for the migration to 1.3 which tells us to register clients in the following way:

<service id="acme.client" class="%acme.client.class%">
    <tag name="csa_guzzle.client"/>
</service>

But it seems to be useless to add the tag csa_guzzle.client if we do not have subscribers to tie to our client, so the following config seems to be right:

<service id="acme.client" class="%acme.client.class%"/>

And only if we have a subscriber to tie, we need to use this tag csa_guzzle.client:

<service id="acme.client" class="%acme.client.class%">
    <tag name="csa_guzzle.client" subscribers="some_subscriber"/>
</service>

Am I wrong ?

baseUrl path has no effect

baseUrl is set to https://example.com/api
The url I would like to call is https://example.com/api/category/some-category-slug

I should really be using $client->get('category/some-category-slug').

If I do this, however, it does not work.
It tries to call https://example.com/category/some-category-slug, which is invalid.

Server file from remote server

Hi @csarrazi

I'm using the v1.3.9 of and I'm trying to get a file from a remote apache server and serve this file to the client like this:

apache -> get request with csaGuzzleBundle -> download to the client

I'm trying to use something like this: https://github.com/csarrazi/CsaGuzzleBundle/blob/1.3/src/Resources/doc/response_streaming.md

$response = $this->getClient()->get('http://drive.google.com/uc?export=view&id=0B2dRtLeD_v77NHpuWk1GdUZoUGs');
return new StreamResponse($response);

but I got this error:

php.CRITICAL: Fatal Error: Call to a member function seek() on string {"type":1,"file":"/opt/sicp-frontend/vendor/csa/guzzle-bundle/src/HttpFoundation/StreamResponse.php","line":34,"level":-1,"stack":[]} {"token":"562a8421956ea"}

Do you know if this is a bug?

Guzzle 404 error

Hi.

In production environment I am configuring monolog to exclude 404 errors but "Csa\Bundle\GuzzleBundle\GuzzleHttp\Subscriber\LoggerSubscriber" logs guzzle 404 errors at onError method, so monolog logs the guzzle and page both 404 errors.

The page is the frontend for some REST services and a 404 error into the service means a 404 error page too.

Is there a way to configure CsaGuzzleBundle to stop logging errors 404? or I should have to override this functionality?

I am using this code into my monolog config

excluded_404s:
    - ^/

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.