PHPackages                             morpholetto/soap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. morpholetto/soap

ActiveLibrary[HTTP &amp; Networking](/categories/http)

morpholetto/soap
================

A SOAP client that provides a clean interface for handling requests and responses.

v2(2y ago)06MITPHPPHP ^7.3|^7.4|~8.0|~8.1|~8.2

Since Dec 2Pushed 2y agoCompare

[ Source](https://github.com/Morpholetto/Soap)[ Packagist](https://packagist.org/packages/morpholetto/soap)[ RSS](/packages/morpholetto-soap/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (32)Used By (0)

Soap
====

[](#soap)

[![Tests](https://github.com/Ricorocks-Digital-Agency/Soap/workflows/Tests/badge.svg)](https://github.com/Ricorocks-Digital-Agency/Soap/workflows/Tests/badge.svg)

A Laravel SOAP client that provides a clean interface for handling requests and responses.

Docs
----

[](#docs)

- [Installation](#installation)
- [Using Soap](#using-soap)
- [Features/API](#features/api)
    - [Headers](#headers)
        - [Global Headers](#global-headers)
    - [To](#to)
    - [Functions](#functions)
    - [Call](#call)
        - [Parameters](#parameters)
            - [Nodes](#nodes)
    - [Options](#options)
        - [Tracing](#tracing)
        - [Authentication](#authentication)
        - [Global Options](#global-options)
- [Hooks](#hooks)
- [Faking](#faking)
- [Configuration](#configuration)
    - [Include](#include)
- [Ray Support](#ray-support)

Requirements
------------

[](#requirements)

- PHP 7.4 or greater
- Laravel 8.16 or greater

Installation
------------

[](#installation)

You can install the package via composer

```
composer require ricorocks-digital-agency/soap
```

> Note: As of v1.5.0 Soap requires PHP ^7.4

Using Soap
----------

[](#using-soap)

Soap can be accessed through the provided Facade

```
use RicorocksDigitalAgency\Soap\Facades\Soap

Soap::to()
```

Features/API
------------

[](#featuresapi)

### Headers

[](#headers)

You can set the headers for each soap request that will be passed to the Soap Client using the `withHeaders` method.

```
Soap::to('...')->withHeaders(...$headers)->call('...');
```

Each header should be a `Header` instance, which provides a fluent interface for constructing a new [PHP Soap Header](https://www.php.net/manual/en/soapheader.construct.php) and can be composed as follows:

```
$header = Soap::header()
            ->name('Authentication')
            ->namespace('test.com')
            ->data([
                'user' => '...',
                'password' => '...'
            ])
            ->mustUnderstand()
            ->actor('foo.co.uk')
```

This can also be expressed as:

```
$header = Soap::header('Authentication', 'test.com', [
                'user' => '...',
                'password' => '...'
            ])
            ->mustUnderstand()
            ->actor('foo.co.uk')
```

Plus, the `soap_header` helper method can be used:

```
$header = soap_header('Authentication', 'test.com')
            ->data([
                'user' => '...',
                'password' => '...'
            ])
```

> The `data` for the header can either be an array or a `SoapVar`, as per the `SoapHeader` constructor

#### Global Headers

[](#global-headers)

Soap allows you to set headers that should be included for every request:

```
Soap::headers(...$headers)
```

Again, each header should be an instance of `Header`.

You may also want to include headers on every request, but only for a certain endpoint or action:

```
// Only requests to this endpoint will include these headers
Soap::headers(soap_header('Auth', 'test.com'))->for('https://api.example.com');

// Only requests to this endpoint and the method Customers will include these headers
Soap::headers(soap_header('Brand', 'test.com'))->for('https://api.example.com', 'Customers');
```

These calls are usually placed in the `boot` method of one of your application's Service Providers.

### To

[](#to)

The endpoint to be accessed

```
Soap::to('github.com/api')
```

### Functions

[](#functions)

Retrieve the functions the endpoint provides

```
Soap::to('github.com/api')->functions()
```

This is a wrapper for the PHP SoapClient `_getFunctions()` method.

### Call

[](#call)

Call the method at the endpoint.

```
Soap::to('github.com/api')->call('merge')
```

The method can also be called as a Magic Method.

```
Soap::to('github.com/api')->merge()
```

#### Parameters

[](#parameters)

The [Call](#call) method of course accepts parameters. The parameters passed can be an array

```
Soap::to('github.com/api')->call('merge', ['branch' => 'staging', 'credentials' => ['password' => '...'])
```

##### Nodes

[](#nodes)

To simplify dealing with SOAP XML in your requests, Soap provides a method to fluently construct the nodes in the request.

For example, say the following node was desired in the XML request. Note it has no body.

```

```

The `array` to pass to the underlying php `SoapClient` to construct this node would be as follows

```
'PullRequest' => [
    '_' => '',
    'branch' => 'dev',
    'target' => 'main'
]
```

The `_` is required to set the information not as the body, but as the attributes for the node.

However, this is not required if the XML node has a body.

```

    Ricorocks

```

Now, the `array` would be as follows

```
'PullRequest' => [
    'Author' => 'Ricorocks',
    'branch' => 'dev',
    'target' => 'main'
]
```

So, to prevent confusion, the `Soap::node()` will allow for intelligent construction of the php `array` to be passed to `SoapClient`.

Imagine we are accessing the `information` method to see details about Pull Requests

```
Soap::to('...')
    ->information('PullRequest' => soap_node(['branch' => 'dev', 'target' => 'main']))

'PullRequest' => [
    '_' => '',
    'branch' => 'dev',
    'target' => 'main'
]

Soap::to('...')
    ->information('PullRequest' => soap_node(['branch' => 'dev', 'target' => 'main'])->body(['Author' => 'Ricorocks']))

'PullRequest' => [
    'Author' => 'Ricorocks',
    'branch' => 'dev',
    'target' => 'main'
]
```

Now, just by adding or removing a body to the `soap_node()` the outputted array is intelligently constructed.

A node can be made with either the Facade `Soap::node()` or the helper method `soap_node()`.

### Options

[](#options)

You can set custom options for each soap request that will be passed to the Soap Client using the `withOptions` method.

```
Soap::to('...')->withOptions(['soap_version' => SOAP_1_2])->call('...');
```

> See for more details and available options.

Soap also provides a number of methods that add syntactical sugar to the most commonly used options, which are detailed below.

#### Tracing

[](#tracing)

Soap allows you to easily trace your interactions with the SOAP endpoint being accessed.

To trace all requests, set the following in the register method of your `ServiceProvider`:

```
Soap::trace()
```

Now, all `Response` objects returned will have a `Trace` object attached, accessible via `$response->getTrace()`. This has four properties which are wrappers for the respective methods found on the `SoapClient`:

- `xmlRequest` (`__getLastRequest`)
- `xmlResponse` (`__getLastResponse`)
- `requestHeaders` (`__getLastRequestHeaders`)
- `responseHeaders` (`__getLastResponseHeaders`)

Tracing can also be declared locally:

```
Soap::to('...')->trace()->call('...')
```

Now, just this `Response` will have a valid `Trace`.

Tracing is null safe. If `$response->getTrace()` is called when a `Trace` hasn't been set, a new `Trace` is returned. This `Trace`'s properties will all return `null`.

#### Authentication

[](#authentication)

You can authenticate using Basic or Digest by calling `withBasicAuth` and `withDigestAuth` respectively.

```
Soap::to('...')->withBasicAuth('username', 'password')->call('...');
Soap::to('...')->withDigestAuth('username', 'password')->call('...');
```

#### Global Options

[](#global-options)

Sometimes, you may wish to include the same set of options on every SOAP request. You can do that using the `options`method on the `Soap` facade:

```
// Every request will include these options automatically
Soap::options(['login' => 'foo', 'password' => 'bar']);
```

You may also want to include options on every request, but only for a certain endpoint or action:

```
// Only requests to this endpoint will include these options
Soap::options(['login' => 'foo', 'password' => 'bar'])->for('https://api.example.com');

// Only requests to this endpoint and the method Customers will include these options
Soap::options(['login' => 'foo', 'password' => 'bar'])->for('https://api.example.com', 'Customers');
```

These calls are usually placed in the `boot` method of one of your application's Service Providers.

Hooks
-----

[](#hooks)

Hooks allow you to perform actions before and after Soap makes a request. These hooks can be local (per request), or global (applied to every request).

You can make changes to the `Request` object in `beforeRequesting` hooks if you wish. These changes will be reflected in the actual request. In fact, this is how the Soap `include` functionality works.

### Local

[](#local)

To create a local hook, chain `beforeRequesting` or `afterRequesting` to a `Request` object:

```
Soap::to('http://example.com')
	->beforeRequesting(fn() => Log::info('Request going in!'))
	->afterRequesting(fn() => Log::info('Request coming out!'))
	->call('Action', []);
```

Any before requesting hooks will receive the request as a parameter and after requesting hooks will receive the request and response as a parameter.

### Global

[](#global)

To create a global hook, use the `Soap::beforeRequesting` and `Soap::afterRequesting` methods.

```
Soap::beforeRequesting(fn() => Log::info('Request going in!'));
Soap::afterRequesting(fn() => Log::info('Request coming out!'));
```

Any before requesting hooks will receive the request as a parameter and after requesting hooks will receive the request and response as a parameter.

Faking
------

[](#faking)

Soap includes full support for faking endpoints and actions, as well as inspecting requests and responses.

To fake all SOAP requests, call `Soap:fake()`. This will return an empty response for every request. It is likely that you will want to be more specific, so you can pass the `fake` method an array of endpoints as keys and response objects as values:

```
Soap::fake(['http://endpoint.com' => Response::new(['foo' => 'bar'])]);
```

In the above example, any SOAP request made to `http://endpoint.com` will be faked, and a `Response` object with a body of `['foo' => 'bar']` will be returned instead.

What if you want to specify the SOAP action too? Easy! Just add `:{ActionName}` after your endpoint, like so:

```
Soap::fake(['http://endpoint.com:Details' => Response::new(['foo' => 'bar'])]);
```

Now, only SOAP requests to the `Details` actions will be mocked.

You can also specify multiple actions with the `|` operator:

```
Soap::fake(['http://endpoint.com:Details|Information|Overview' => Response::new(['foo' => 'bar'])]);
```

Now, only SOAP requests to the `Details`, `Information` and `Overview` actions will be mocked.

### Inspecting requests

[](#inspecting-requests)

If you've made a call to `Soap::fake()`, Soap will record all requests made. You can then inspect these requests as you see fit.

#### `Soap::assertSentCount($count)`

[](#soapassertsentcountcount)

If you just want to assert that `n` amount of SOAP requests were sent, you can use this method, passing in the desired count as a parameter.

#### `Soap::assertSent(callable $callback)`

[](#soapassertsentcallable-callback)

You can dive a little deeper and test that a particular request was actually sent, and that it returned the expected response. You should pass a closure into this method, which receives the `$request` and `$response` as parameters, and return `true` if they match your expectations.

#### `Soap::assertNotSent(callable $callback)`

[](#soapassertnotsentcallable-callback)

This is the opposite of `Soap::assertSent`. You can make sure that a particular request wasn't made. Again, returning `true` from the closure will cause it to pass.

#### `Soap::assertNothingSent()`

[](#soapassertnothingsent)

If you just want to make sure that absolutely nothing was sent out, you can call this. It does what it says on the tin.

Configuration
-------------

[](#configuration)

Configuration of Soap is via the `Soap` facade in the `boot()` method in your service provider.

### Include

[](#include)

Parameters can be set to be automatically included in all requests. These can be `arrays` or [nodes](#nodes)

```
Soap::include(['credentials' => soap_node(['user' => '...', 'password' => '...'])]);
```

You can even use dot syntax on your array keys to permeate deeper into the request body.

```
Soap::include(['login.credentials' => soap_node(['user' => '...', 'password' => '...'])]);
```

Often, you'll want to target specific endpoints or actions. You can chain the `for` method to achieve this.

```
// Only requests to https://api.example.com will include this data
Soap::include(['credentials' => soap_node(['user' => '...', 'password' => '...'])])->for('https://api.example.com');

// Only requests to https://api.example.com calling the Customers method will include this data
Soap::include(['credentials' => soap_node(['user' => '...', 'password' => '...'])])->for('https://api.example.com', 'Customers');
```

Ray Support
-----------

[](#ray-support)

This package comes with first party support for Ray, an awesome debugging tool by Spatie! We offer a couple of methods that you can use to start debugging immediately.

> Obviously, you'll need Ray installed in your project for this to work.

### `ray()->showSoapRequests()`

[](#ray-showsoaprequests)

This enables Ray support in the SOAP package. Any SOAP requests made will be recorded in the Ray app for you to inspect.

### `ray()->stopShowingSoapRequests()`

[](#ray-stopshowingsoaprequests)

This disables Ray support in the SOAP package. Requests will stop being recorded if previously enabled.

> If you want to use the Ray integration inside of your tests, remember to register the `RayServiceProvider` along with your other providers.

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ricorocks Digital Agency](https://github.com/ricorocks-digital-agency)
- [Luke Downing](https://github.com/lukeraymonddowning)
- [Sam Rowden](https://github.com/nedwors)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 61.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~34 days

Recently: every ~0 days

Total

27

Last Release

1088d ago

Major Versions

0.6.0 → 1.0.02021-02-10

PHP version history (4 changes)v1.5.0PHP ^7.4|^8.0

v1.6.0PHP ^7.4|^8.0|^8.1

v1.7.0PHP ^7.4|~8.0|~8.1|~8.2

1.7.1PHP ^7.3|^7.4|~8.0|~8.1|~8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/1888ff41d57ed9dfffeaf5ce61a21179d221106b220075d1a9b2814504837094?d=identicon)[Morpholetto](/maintainers/Morpholetto)

---

Top Contributors

[![lukeraymonddowning](https://avatars.githubusercontent.com/u/12202279?v=4)](https://github.com/lukeraymonddowning "lukeraymonddowning (99 commits)")[![nedwors](https://avatars.githubusercontent.com/u/59183434?v=4)](https://github.com/nedwors "nedwors (52 commits)")[![Morpholetto](https://avatars.githubusercontent.com/u/8161627?v=4)](https://github.com/Morpholetto "Morpholetto (4 commits)")[![SuperDJ](https://avatars.githubusercontent.com/u/6484766?v=4)](https://github.com/SuperDJ "SuperDJ (3 commits)")[![giraz82](https://avatars.githubusercontent.com/u/5285724?v=4)](https://github.com/giraz82 "giraz82 (1 commits)")[![ivan-bauer-zengo](https://avatars.githubusercontent.com/u/174011518?v=4)](https://github.com/ivan-bauer-zengo "ivan-bauer-zengo (1 commits)")[![thekonz](https://avatars.githubusercontent.com/u/2700089?v=4)](https://github.com/thekonz "thekonz (1 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/morpholetto-soap/health.svg)

```
[![Health](https://phpackages.com/badges/morpholetto-soap/health.svg)](https://phpackages.com/packages/morpholetto-soap)
```

###  Alternatives

[danharrin/livewire-rate-limiting

Apply rate limiters to Laravel Livewire actions.

40423.1M27](/packages/danharrin-livewire-rate-limiting)[mateusjunges/laravel-kafka

A kafka driver for laravel

7163.1M17](/packages/mateusjunges-laravel-kafka)[illuminate/http

The Illuminate Http package.

11936.0M5.1k](/packages/illuminate-http)[ricorocks-digital-agency/soap

A SOAP client that provides a clean interface for handling requests and responses.

4281.8M5](/packages/ricorocks-digital-agency-soap)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[laravel-shift/curl-converter

A command line tool to convert curl requests to Laravel HTTP requests.

935.3k](/packages/laravel-shift-curl-converter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
