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

Soap Wsdl Laravel Package

besimple/soap-wsdl

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require besimple/soap-wsdl:0.2.*@dev
    

    Verify the package loads by checking vendor/composer/autoload_psr4.php for BeSimple\SoapWsdl.

  2. First Use Case: Consuming a SOAP Service

    use BeSimple\SoapWsdl\Client;
    
    $client = new Client('http://example.com/soap-service?wsdl');
    $response = $client->__soapCall('MethodName', ['param1' => 'value1']);
    
  3. Where to Look First:

    • Documentation: Check the GitHub repo for basic usage examples (though sparse, focus on Client class).
    • Source Code: Explore src/Client.php for core methods like __soapCall(), setOptions(), and getFunctions().
    • Tests: Review tests/ for real-world integration patterns (if available).

Implementation Patterns

Core Workflows

  1. Service Consumption:

    • Dynamic Method Calls:
      $client = new Client('http://example.com/wsdl');
      $result = $client->__soapCall('GetUserData', ['userId' => 123]);
      
    • Static Typing (PHP 8+): Use getFunctions() to fetch available methods and validate inputs:
      $methods = $client->getFunctions();
      if (in_array('GetUserData', $methods)) {
          $client->__soapCall('GetUserData', ['userId' => 123]);
      }
      
  2. Request Customization:

    • Headers/Options:
      $client->setOptions([
          'trace' => 1,
          'exceptions' => true,
          'soap_version' => SOAP_1_2,
          'login' => 'user',
          'password' => 'pass',
      ]);
      
    • WSDL Caching: Store WSDL locally to avoid repeated downloads:
      $client = new Client('file:///path/to/local/wsdl.xml');
      
  3. Laravel Integration:

    • Service Provider:
      // app/Providers/SoapServiceProvider.php
      public function register()
      {
          $this->app->singleton('soap.client', function () {
              return new Client(config('soap.wsdl_url'));
          });
      }
      
    • Config File (config/soap.php):
      return [
          'wsdl_url' => env('SOAP_WSDL_URL', 'http://default.com/wsdl'),
          'default_options' => [
              'trace' => true,
          ],
      ];
      
    • Facade:
      // app/Facades/Soap.php
      public static function call($method, $params = [])
      {
          return app('soap.client')->__soapCall($method, $params);
      }
      
  4. Error Handling:

    • SoapFault Handling:
      try {
          $client->__soapCall('FaultyMethod', []);
      } catch (SoapFault $fault) {
          Log::error("SOAP Error: {$fault->getMessage()}");
          throw new \RuntimeException('Service unavailable', 503);
      }
      

Gotchas and Tips

Pitfalls

  1. WSDL Parsing Issues:

    • Problem: Complex WSDLs may fail silently or throw cryptic errors.
    • Fix: Use getFunctions() to validate the WSDL is parsed correctly before calling methods.
    • Debugging: Enable trace in options to inspect raw SOAP requests/responses:
      $client->setOptions(['trace' => 1]);
      $response = $client->__soapCall(...);
      var_dump($client->__getLastRequest(), $client->__getLastResponse());
      
  2. Namespace Conflicts:

    • Problem: The package may clash with native SoapClient if autoloading isn’t isolated.
    • Fix: Use fully qualified class names:
      use BeSimple\SoapWsdl\Client as SoapWsdlClient;
      
  3. Version Locking:

    • Problem: The package is in 0.2.*@dev state; updates may break compatibility.
    • Fix: Pin the version in composer.json:
      "besimple/soap-wsdl": "0.2.0"
      
  4. Laravel Caching Quirks:

    • Problem: WSDL caching may interfere with dynamic WSDL updates.
    • Fix: Clear Laravel cache when WSDL changes:
      php artisan cache:clear
      php artisan view:clear
      

Tips

  1. Performance:

    • Reuse Clients: Instantiate Client once (e.g., as a singleton) to avoid WSDL re-parsing:
      $client = new Client('http://example.com/wsdl');
      // Reuse $client for multiple calls
      
  2. Testing:

    • Mock SOAP Responses: Use Laravel’s Mockery to stub SoapClient:
      $mock = Mockery::mock('overload:BeSimple\SoapWsdl\Client');
      $mock->shouldReceive('__soapCall')->andReturn(['data' => 'test']);
      
  3. Extension Points:

    • Custom SOAP Headers:
      $client->setOptions([
          'headers' => [
              new SoapHeader('http://namespace', 'AuthHeader', ['token' => 'abc123']),
          ],
      ]);
      
    • Middleware: Extend Client to add pre/post-processing:
      class CustomClient extends Client {
          public function __soapCall($method, $params) {
              $this->logRequest($method, $params);
              return parent::__soapCall($method, $params);
          }
      }
      
  4. Logging:

    • Track SOAP Calls: Use Laravel’s logging to monitor API usage:
      $client->setOptions(['trace' => 1]);
      $client->__soapCall('Method', []);
      Log::info('SOAP Request:', [
          'request' => $client->__getLastRequest(),
          'response' => $client->__getLastResponse(),
      ]);
      
  5. Fallback to Native SoapClient:

    • For unsupported features, drop into native PHP:
      $nativeClient = new \SoapClient('http://example.com/wsdl');
      $nativeClient->__setLocation('http://override.com/endpoint');
      
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.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium