Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Buzz Bundle Laravel Package

sensio/buzz-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require "sensio/buzz-bundle":"dev-master"
    

    Add to AppKernel.php:

    new Sensio\Bundle\BuzzBundle\SensioBuzzBundle(),
    
  2. First Use Case: Inject the buzz service into a controller or service:

    use Buzz\Browser;
    
    class MyController extends Controller
    {
        public function fetchDataAction()
        {
            $client = $this->get('buzz');
            $response = $client->get('https://api.example.com/data');
            return new Response($response->getContent());
        }
    }
    
  3. Key Entry Points:

    • buzz service (default Buzz\Browser instance).
    • Configure via config.yml (see below).

Implementation Patterns

Core Workflows

  1. Basic HTTP Requests:

    $client = $this->container->get('buzz');
    $response = $client->get('https://api.example.com');
    $content = $response->getContent();
    
  2. Custom Headers/Authentication:

    $client = $this->container->get('buzz');
    $client->setHeader('Authorization', 'Bearer token123');
    $client->setHeader('Accept', 'application/json');
    
  3. POST Requests with Data:

    $client = $this->container->get('buzz');
    $client->post('https://api.example.com/submit', [], [
        'Content-Type' => 'application/json',
        'data' => json_encode(['key' => 'value'])
    ]);
    
  4. Handling Responses:

    $response = $client->get('https://api.example.com');
    if ($response->getStatusCode() === 200) {
        $data = json_decode($response->getContent(), true);
    }
    

Integration Tips

  • Dependency Injection: Bind the buzz service to a custom client class for reusable logic:

    # app/config/services.yml
    services:
        my.custom.client:
            class: AppBundle\Service\CustomBuzzClient
            arguments: ['@buzz']
    
  • Configuration: Override default Buzz\Browser settings in config.yml:

    sensio_buzz:
        client:
            timeout: 30
            user_agent: 'MyApp/1.0'
    
  • Middleware/Plugins: Extend Buzz\Browser with custom plugins (e.g., logging, retries):

    $client = $this->container->get('buzz');
    $client->getEventDispatcher()->addListener('request', function ($event) {
        // Pre-request logic
    });
    
  • Symfony HTTP Client Alternative: For modern Laravel (Symfony 5+), prefer symfony/http-client or guzzlehttp/guzzle over Buzz, as this bundle is archived and lacks active maintenance.


Gotchas and Tips

Pitfalls

  1. Archived Status:

    • The bundle is no longer maintained. Use at your own risk; consider migrating to symfony/http-client or guzzlehttp/guzzle.
    • No Symfony 5+ compatibility; may break with newer PHP/Framework versions.
  2. Deprecated Buzz Features:

    • Buzz v0.10+ is outdated. Avoid relying on undocumented behavior (e.g., setHeader vs. addHeader).
    • No native support for middleware (unlike Guzzle/Symfony HTTP Client).
  3. Configuration Overrides:

    • Custom config.yml settings may not persist across requests if the service is stateless. Reconfigure the client instance directly if needed:
      $client = $this->container->get('buzz');
      $client->setTimeout(30); // Override per-request
      

Debugging Tips

  1. Response Inspection: Dump raw responses for debugging:

    $response = $client->get('https://api.example.com');
    var_dump($response->getStatusCode(), $response->getHeaders(), $response->getContent());
    
  2. Error Handling: Catch Buzz\Exception\NetworkException for network issues:

    try {
        $response = $client->get('https://api.example.com');
    } catch (\Buzz\Exception\NetworkException $e) {
        // Handle timeout/connection errors
    }
    
  3. Logging: Use Symfony’s logger to track requests:

    $this->get('logger')->info('API Request', [
        'url' => 'https://api.example.com',
        'status' => $response->getStatusCode(),
    ]);
    

Extension Points

  1. Custom Client Class: Extend Buzz\Browser for reusable logic:

    class ApiClient extends \Buzz\Browser
    {
        public function __construct()
        {
            $this->setHeader('Authorization', 'Bearer ' . $this->getAuthToken());
        }
    
        private function getAuthToken() { /* ... */ }
    }
    

    Register as a service:

    services:
        api.client:
            class: AppBundle\Service\ApiClient
    
  2. Event Listeners: Hook into Buzz events (e.g., request, response) via Symfony’s event dispatcher:

    $dispatcher = $client->getEventDispatcher();
    $dispatcher->addListener('request', function ($event) {
        $event->getRequest()->setHeader('X-Custom-Header', 'value');
    });
    
  3. Proxy Support: Configure proxy settings via config.yml:

    sensio_buzz:
        client:
            proxy: 'http://proxy.example.com:8080'
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
ilhamsyabani/laravel-volt-starter
thethunderturner/filament-latex
ghostcompiler/laravel-querybuilder
webrek/laravel-telescope-mongodb
anousss007/blatui
zatona-eg/zatona-eg-api
cocosmos/filament-sticky-save-bar
patrickbussmann/oauth2-apple
3brs/enterprise-security-bundle
anousss007/vigilance
supportpal/eloquent-model
ardenexal/fhir-models
laravel-at/laravel-image-sanitize
romalytar/yammi-audit-log-laravel
ardenexal/fhir-validation
arshaviras/weather-widget
laravel-chronicle/core
sunchayn/nimbus
daikazu/eloquent-salesforce-objects
unseen-codes/chat