csarrazi / csaguzzlebundle Goto Github PK
View Code? Open in Web Editor NEWA bundle integrating Guzzle >=4.0 in Symfony
A bundle integrating Guzzle >=4.0 in Symfony
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.
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:
csa_guzzle:
profiler: true
logger: true
clients:
api:
config:
base_url: http://localhost/
subscribers:
debug: true
stopwatch: true
logger: false
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');
}
Steps to reproduce:
cURL error 6: Couldn't resolve host 'foo'
error;_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.
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?
I'm looking for Symfony2 bundle that support Async call which is supported by Guzzle.
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.
great job man, i am glad to see good updated well taken care bundles like this, will contribute! ๐
If the middleware history create the history in a SplObjectStorage BEFORE a middleware that add something to the request, which generate a new request object, the request cannot be matched when the response come back.
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?
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
.
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 ;-)
Quoting https://github.com/namshi/cuzzle/
This library let's you dump a Guzzle request to a cURL command for debug and log purpose.
But sadly, Guzzle 6 is not yet supported. See namshi/cuzzle#8
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.
Hi,
I saw on https://github.com/csarrazi/CsaGuzzleBundle/blob/master/src/Resources/views/Calls/call.html.twig a call to jQuery 2. You can have some conflicts with the jQuery version you may possibly have into your real application, I suggest to use a require()
strategy with aliases or - better imo - to remove this dependency (I can make a PR this way if you agree).
What do you think ? @csarrazi
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)
Does the configuration support auth settings, something like this?
csa_guzzle:
clients:
github_api:
config:
base_url: https://api.github.com
auth:
username: login
password: xxxxx
defaults:
headers:
Accept: application/vnd.github.v3+json
This will enable the support for Guzzle services.
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.
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
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
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:
dev-master
of the bundleAs 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
.
Many changes have been made into 1.3
, a few of them need to be adapted for the master
branch.
This will be a part of release v2.0.0
Update web debug toolbar and profiler templates to support all versions of Symfony.
Guzzle 6.0 switched to PSR-7 request/response/streams.
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?
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.
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 ?
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.
Ping @iamluc
please tag it else it straight gives an error when using the last tagged version ~1.2.5
thanks
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:
- ^/
With release 1.3.2
, symfony services can now be injected in a client's configuration.
This should be documented in the 1.3
branch.
Currently, if you set a service ID for the config.handler
key of a guzzle client, it is overridden in the compiler pass.
This is not the correct behavior, and should be fixed. The handler provided by the user should have the middleware injected.
This will let users be in control of the service name, and transition more easily from and to this bundle.
Hi,
When working with multiple api/symfony's application, it will be very useful the have the X-Debug-Token-*
headers clickable. :)
I'm already have it working (before i saw that you already support services), but i need to rebuild it with your services support!
I will try to create a pull request today!
It's not very detailed docs. Actually can't understand how to use it after install at all. Please add some more info
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?
The mock feature stores http requests in a file with name containing '?'. This is not a valid character under windows.
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"
Is it possible to have an upgrade documentation from 1.0 to 1.1 ?
Example : https://github.com/symfony/symfony/blob/2.7/UPGRADE-2.6.md
Thanks
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.
Tree builder for cache
node 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
Like mentioned on the title. Release 1.2.0 should have an updated doc.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.