kduma/laravel-soap-server

Laravel SOAP service server

dev-master 2022-11-13 01:35 UTC

This package is auto-updated.

Last update: 2024-03-29 17:44:04 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

Laravel SOAP service server

Installation

You can install the package via composer:

composer require kduma/laravel-soap-server

Usage

Create server class - remember to provide correct typehints and doc blocks:

class SoapDemoServer
{
    /**
     * Adds two numbers
     *
     * @param float $a
     * @param float $b
     *
     * @return float
     */
    public function sum(float $a = 0, float $b = 0): float
    {
        return $a + $b;
    }

    /**
     * Returns your data
     *
     * @return Person
     */
    public function me(): Person
    {
        return new Person('John', 'Doe');
    }

    /**
     * Says hello to person provided
     *
     * @param Person $person
     *
     * @return string
     */
    public function hello(Person $person): string
    {
        return sprintf("Hello %s!", $person->first_name);
    }
}

...and DTO objects:

class Person
{
    /**
     * @var string
     */
    public $first_name;

    /**
     * @var string
     */
    public $last_name;

    /**
     * @param string $first_name
     * @param string $last_name
     */
    public function __construct(string $first_name, string $last_name)
    {
        $this->first_name = $first_name;
        $this->last_name = $last_name;
    }
}

Create controller class for your SOAP server:

class MySoapController extends \KDuma\SoapServer\AbstractSoapServerController
{
    protected function getService(): string
    {
        return SoapDemoServer::class;
    }

    protected function getEndpoint(): string
    {
        return route('my_soap_server');
    }

    protected function getWsdlUri(): string
    {
        return route('my_soap_server.wsdl');
    }

    protected function getClassmap(): array
    {
        return [
            'SoapPerson' => Person::class,
        ];
    }
}

Register routes in your routes file:

Route::name('my_soap_server.wsdl')->get('/soap.wsdl', [MySoapController::class, 'wsdlProvider']);
Route::name('my_soap_server')->post('/soap', [MySoapController::class, 'soapServer']);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email git@krystian.duma.sh instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.