Soap Server
A lightweight and modern SOAP server implementation for PHP 8.1+
Featuresβ
- π Modern PHP 8.1+ Attributes: Use PHP attributes to define SOAP services declaratively
 - π Auto-generated WSDL: Automatic WSDL generation from your service definitions
 - π¨ Beautiful Documentation UI: Modern, interactive HTML documentation with Jinja templates
 - π§ Flexible Configuration: Support for both attribute-based and programmatic configuration
 - π Type Safety: Full support for complex types, arrays, and optional parameters
 - π SOAP 1.1 & 1.2: Support for both SOAP versions
 - π― Discovery Support: Built-in DISCO (Discovery) document generation
 - π± Responsive Design: Mobile-friendly service documentation interface
 
Installationβ
composer require byjg/soap-server
Quick Startβ
Using PHP Attributes (Recommended)β
<?php
use ByJG\SoapServer\Attributes\{SoapService, SoapOperation, SoapParameter};
use ByJG\SoapServer\SoapAttributeParser;
use ByJG\SoapServer\ResponseWriter;
#[SoapService(
    serviceName: 'CalculatorService',
    namespace: 'http://example.com/calculator',
    description: 'A simple calculator web service'
)]
class Calculator
{
    #[SoapOperation(description: 'Adds two numbers together')]
    public function add(
        #[SoapParameter(description: 'First number')] int $a,
        #[SoapParameter(description: 'Second number')] int $b
    ): int {
        return $a + $b;
    }
    #[SoapOperation(description: 'Subtracts second from first')]
    public function subtract(int $a, int $b): int
    {
        return $a - $b;
    }
}
// Start the service
$handler = SoapAttributeParser::parse(Calculator::class);
$response = $handler->handle();
ResponseWriter::output($response);
Using Programmatic Configurationβ
<?php
use ByJG\SoapServer\{SoapHandler, SoapOperationConfig, SoapParameterConfig, SoapType};
use ByJG\SoapServer\ResponseWriter;
$addOperation = new SoapOperationConfig();
$addOperation->description = 'Adds two numbers';
$addOperation->args = [
    new SoapParameterConfig('a', SoapType::Integer),
    new SoapParameterConfig('b', SoapType::Integer)
];
$addOperation->returnType = SoapType::Integer;
$addOperation->executor = function(array $params) {
    return $params['a'] + $params['b'];
};
$handler = new SoapHandler(
    soapItems: ['add' => $addOperation],
    serviceName: 'CalculatorService'
);
$response = $handler->handle();
ResponseWriter::output($response);
Running the Serviceβ
Start PHP's built-in web server:
php -S localhost:8080 calculator.php
Then access:
- Service Documentation: http://localhost:8080
 - WSDL: http://localhost:8080?wsdl
 - DISCO: http://localhost:8080?DISCO
 
Running Testsβ
composer install
composer test
Running Static Analysisβ
composer psalm
Documentationβ
Comprehensive documentation is available:
- Getting Started - Create your first SOAP service
 - Using Attributes - Attribute-based configuration guide
 - Programmatic Configuration - API-based configuration
 - Complex Types - Working with custom classes and objects
 - Templates - Customizing the service documentation UI
 
License and Acknowledgmentsβ
This project is licensed under the MIT License.
Note: Parts of this codebase were derived from an older PHP class originally licensed under the PHP License. The original code has been modernized and adapted for this project. For detailed information about the licensing and acknowledgments, see License Acknowledgments.