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

Xml Soap Laravel Package

simplesamlphp/xml-soap

SimpleSAMLphp XML-SOAP utilities for handling SOAP-based XML messaging. Provides helper classes and components used in SAML-related integrations where SOAP bindings are required, intended for use within the SimpleSAMLphp ecosystem.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer in your Laravel project:

    composer require simplesamlphp/xml-soap
    

    Ensure your composer.json includes "minimum-stability": "dev" if required.

  2. First Use Case: SOAP Client Initialize a SOAP client in a Laravel service or controller:

    use SimpleSAML\XML\SOAP\Client;
    
    $client = new Client('https://example.com/soap-service?wsdl');
    $response = $client->call('TargetFunction', ['param1' => 'value1']);
    
  3. Where to Look First

    • Documentation: Check the SimpleSAMLphp XML-SOAP docs (if available).
    • Source Code: Browse the GitHub repo for usage examples.
    • Laravel Integration: Use Laravel’s Http facade or DI container to manage SOAP clients as singletons if needed.

Implementation Patterns

Workflows

  1. SOAP Requests in Controllers Encapsulate SOAP logic in a service class to avoid cluttering controllers:

    namespace App\Services;
    
    use SimpleSAML\XML\SOAP\Client;
    
    class SoapService {
        protected $client;
    
        public function __construct() {
            $this->client = new Client(config('soap.endpoint'));
        }
    
        public function fetchData($params) {
            return $this->client->call('fetchData', $params);
        }
    }
    

    Inject the service into controllers:

    public function showData(SoapService $soapService) {
        $data = $soapService->fetchData(['id' => 123]);
        return view('data', compact('data'));
    }
    
  2. Handling Responses Parse SOAP responses with Laravel’s collect() or custom helpers:

    $response = $soapService->fetchData(['id' => 123]);
    $data = collect($response)->first()->toArray();
    
  3. Error Handling Wrap SOAP calls in try-catch blocks:

    try {
        $response = $client->call('FaultyFunction', []);
    } catch (\SimpleSAML\XML\SOAP\Exception\SOAPException $e) {
        Log::error('SOAP Error: ' . $e->getMessage());
        return response()->json(['error' => 'Service unavailable'], 500);
    }
    

Integration Tips

  • Configuration: Store SOAP endpoints in Laravel’s config/soap.php:
    return [
        'endpoint' => env('SOAP_ENDPOINT', 'https://example.com/soap'),
        'timeout'  => 30,
    ];
    
  • Logging: Use Laravel’s logging to track SOAP interactions:
    Log::debug('SOAP Request:', ['params' => $params, 'endpoint' => $client->getEndpoint()]);
    
  • Testing: Mock SOAP responses in PHPUnit:
    $mockHandler = $this->getMockBuilder(\SimpleSAML\XML\SOAP\Client::class)
        ->disableOriginalConstructor()
        ->onlyMethods(['call'])
        ->getMock();
    $mockHandler->method('call')->willReturn(['mocked' => 'response']);
    

Gotchas and Tips

Pitfalls

  1. Namespace Conflicts The package uses SimpleSAML namespaces, which may conflict with Laravel’s Simple helpers. Alias the class:

    use SimpleSAML\XML\SOAP\Client as SOAPClient;
    
  2. WSDL Caching The package caches WSDL definitions aggressively. Clear cache if endpoints change:

    $client = new SOAPClient('endpoint', ['cache_wsdl' => WSDL_CACHE_NONE]);
    
  3. Strict Types SOAP responses may return SimpleXMLElement objects. Cast to arrays or use json_decode():

    $arrayResponse = json_decode(json_encode($response), true);
    
  4. Timeouts Default timeouts may be too short for slow SOAP services. Configure in the client:

    $client = new Client('endpoint', [
        'connection_timeout' => 60,
        'execution_timeout'  => 120,
    ]);
    

Debugging

  • Enable SOAP Traces Enable PHP’s SOAP extension traces for debugging:

    ini_set('soap.wsdl_cache_enabled', '0');
    ini_set('soap.wsdl_cache_ttl', '0');
    

    Check php://stderr or Laravel logs for raw SOAP requests/responses.

  • Validate XML Use DOMDocument to validate SOAP responses:

    $dom = new DOMDocument();
    if (!$dom->loadXML($response)) {
        throw new \Exception('Invalid SOAP response XML');
    }
    

Extension Points

  1. Custom Headers Add SOAP headers via the client’s constructor options:

    $client = new Client('endpoint', [
        'soapheaders' => new \SoapHeader('namespace', 'headerName', 'headerValue'),
    ]);
    
  2. Middleware for SOAP Create Laravel middleware to preprocess SOAP requests:

    namespace App\Http\Middleware;
    
    use Closure;
    
    class SoapAuthMiddleware {
        public function handle($request, Closure $next) {
            $soapClient = new \SimpleSAML\XML\SOAP\Client(config('soap.endpoint'));
            $soapClient->setAuthToken($request->bearerToken());
            return $next($request);
        }
    }
    
  3. Event Dispatching Dispatch Laravel events after SOAP calls:

    event(new SoapResponseReceived($response));
    
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
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