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

Web Gate Bundle Laravel Package

avtonom/web-gate-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require avtonom/web-gate-bundle
    

    Add to config/bundles.php (Symfony 4+):

    return [
        // ...
        Avtonom\WebGateBundle\AvtonomWebGateBundle::class => ['all' => true],
        Sensio\Bundle\BuzzBundle\SensioBuzzBundle::class => ['all' => true],
    ];
    
  2. Configure (config/packages/web_gate.yaml):

    web_gate:
        soap:
            environment: '%env(APP_ENV)%'
            connection_timeout: 15
        logger:
            logging_max_files: 0
            logging_level: 100
        rest:
            host: '%env(REST_HOST)%'
            env: '%env(REST_ENV)%'
            login: '%env(REST_LOGIN)%'
            password: '%env(REST_PASSWORD)%'
    
  3. First Use Case: Define a REST client service (config/services.yaml):

    services:
        app.rest.user_client:
            class: Avtonom\WebGateBundle\Service\RestService
            arguments:
                - '@web_gate.logger'
                - '@buzz.client'
                - 'GET'
                - '%web_gate.rest.host%'
                - '%web_gate.rest.env%/api/v1/user/'
                - '%env(REST_LOGIN)%'
                - '%env(REST_PASSWORD)%'
    

    Use in a controller:

    use Symfony\Component\HttpFoundation\Response;
    
    class UserController extends AbstractController
    {
        public function getUser(Request $request): Response
        {
            $client = $this->get('app.rest.user_client');
            $response = $client->send(['id' => 123], '/details');
    
            return $this->json($response);
        }
    }
    

Implementation Patterns

Common Workflows

  1. REST API Calls:

    • Service Definition: Define reusable clients for endpoints (e.g., app.rest.order_client).
      app.rest.order_client:
          class: Avtonom\WebGateBundle\Service\RestService
          arguments:
              - '@web_gate.logger'
              - '@buzz.client'
              - 'POST'
              - '%web_gate.rest.host%'
              - '%web_gate.rest.env%/api/v1/orders/'
      
    • Dynamic Endpoints: Use send() with path overrides:
      $client->send($data, '/custom-path'); // Overrides base path
      
  2. SOAP Integration:

    • Configure SOAP client in services.yaml:
      app.soap.client:
          class: Avtonom\WebGateBundle\Service\SoapService
          arguments:
              - '@web_gate.logger'
              - '%web_gate.soap.wsdl_url%'
              - '%web_gate.soap.environment%'
      
    • Call SOAP methods:
      $response = $this->get('app.soap.client')->call('GetUserDetails', ['userId' => 1]);
      
  3. Authentication:

    • Use environment variables for credentials (%env(REST_LOGIN)%).
    • Extend RestService to add custom auth headers:
      class CustomRestService extends RestService {
          protected function getHeaders(): array {
              return array_merge(parent::getHeaders(), [
                  'X-Custom-Auth' => $this->getAuthToken(),
              ]);
          }
      }
      
  4. Error Handling:

    • Log errors via Monolog (configured in web_gate.logger).
    • Catch exceptions in controllers:
      try {
          $response = $client->send($data);
      } catch (\Avtonom\WebGateBundle\Exception\GateException $e) {
          $this->addFlash('error', $e->getMessage());
      }
      
  5. Testing:

    • Mock BuzzClient in PHPUnit:
      $mockBuzz = $this->createMock(\Buzz\Client\ClientInterface::class);
      $mockBuzz->method('get')->willReturn(new \Buzz\Message\Response(200, [], '{}'));
      
      $container->set('buzz.client', $mockBuzz);
      

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony 2.x:

    • The bundle targets Symfony 2.3–3.0. For Symfony 4/5, expect compatibility issues (e.g., autowiring, config structure).
    • Fix: Use a wrapper service or fork the bundle.
  2. BuzzBundle Dependency:

    • Requires sensio/buzz-bundle (v1.0). Newer versions may break compatibility.
    • Tip: Pin the BuzzBundle version in composer.json:
      "require": {
          "sensio/buzz-bundle": "1.0.0"
      }
      
  3. SOAP Limitations:

    • No built-in support for WSDL caching or complex SOAP headers.
    • Workaround: Pre-process SOAP requests in a custom service layer.
  4. Logging Overhead:

    • logging_max_files: 0 disables log rotation. Set to 30 (e.g.) for production:
      web_gate.logger:
          logging_max_files: 30
      
  5. Hardcoded Paths:

    • Base paths (e.g., %web_gate.rest.env%/api/v1/) are concatenated in RestService. Override the getBaseUrl() method to customize:
      class CustomRestService extends RestService {
          protected function getBaseUrl(): string {
              return $this->host . '/custom-base/';
          }
      }
      

Debugging Tips

  1. Enable Verbose Logging:

    • Set logging_level: 100 (DEBUG) in config/packages/web_gate.yaml to log raw requests/responses.
  2. Buzz Client Debugging:

    • Use Symfony’s buzz.client debug mode:
      # config/packages/sensio_buzz.yaml
      sensio_buzz:
          client:
              debug: '%kernel.debug%'
      
  3. Common Exceptions:

    • GateException: Wraps HTTP errors (e.g., 404, 500). Check the underlying Buzz\Exception\ExceptionInterface.
    • SoapFault: SOAP-specific errors. Use try-catch to handle gracefully.

Extension Points

  1. Custom Response Handling:

    • Extend RestService to parse responses (e.g., JSON → DTOs):
      class JsonRestService extends RestService {
          protected function parseResponse(\Buzz\Message\Response $response): array {
              return json_decode($response->getContent(), true);
          }
      }
      
  2. Middleware Support:

    • Inject middleware into the Buzz client:
      services:
          app.rest.client:
              class: Avtonom\WebGateBundle\Service\RestService
              arguments:
                  - '@web_gate.logger'
                  - '@buzz.client.custom' # Custom client with middleware
      
      Define the custom client:
      buzz.client.custom:
          class: Buzz\Client\Client
          factory: ['@buzz.client', 'withMiddleware']
          arguments:
              - ['@app.middleware.auth']
      
  3. Dynamic Configuration:

    • Override RestService to load configs dynamically (e.g., from a database):
      class DynamicRestService extends RestService {
          public function __construct(
              LoggerInterface $logger,
              ClientInterface $client,
              string $method,
              string $host,
              string $env,
              ?callable $configLoader = null
          ) {
              $this->configLoader = $configLoader;
              parent::__construct($logger, $client, $method, $host, $env);
          }
      
          protected function getBaseUrl(): string {
              $config = $this->configLoader ? $this->configLoader() : [];
              return $this->host . ($config['base_path'] ?? '');
          }
      }
      
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware