Code Monkey home page Code Monkey logo

laravel-soap's Introduction

Laravel SoapClient Wrapper

A SoapClient wrapper integration for Laravel / Lumen.
The documentation will be updated in time.

Installation

Laravel

Add artisaninweb/laravel-soap as requirement to composer.json

{
    "require": {
        "artisaninweb/laravel-soap": "0.2.*"
    }
}

Add the service provider in app/config/app.php.

'Artisaninweb\SoapWrapper\ServiceProvider'

To use the facade add this to the facades in app/config/app.php.

'SoapWrapper' => 'Artisaninweb\SoapWrapper\Facades\SoapWrapper'

Lumen

Open bootstrap/app.php and register the required service provider:

$app->register(Artisaninweb\SoapWrapper\ServiceProvider::class);

register class alias:

class_alias('Artisaninweb\SoapWrapper\Facades\SoapWrapper', 'SoapWrapper');

Facades must be enabled.

Usage

How to add a service to the wrapper and use it.

<?php

use Artisaninweb\SoapWrapper\Facades\SoapWrapper;

class SoapController {

    public function demo()
    {
        // Add a new service to the wrapper
        SoapWrapper::add(function ($service) {
            $service
                ->name('currency')
                ->wsdl('http://currencyconverter.kowabunga.net/converter.asmx?WSDL')
                ->trace(true)                                                   // Optional: (parameter: true/false)
                ->header()                                                      // Optional: (parameters: $namespace,$name,$data,$mustunderstand,$actor)
                ->customHeader($customHeader)                                   // Optional: (parameters: $customerHeader) Use this to add a custom SoapHeader or extended class                
                ->cookie()                                                      // Optional: (parameters: $name,$value)
                ->location()                                                    // Optional: (parameter: $location)
                ->certificate()                                                 // Optional: (parameter: $certLocation)
                ->cache(WSDL_CACHE_NONE)                                        // Optional: Set the WSDL cache
                ->options(['login' => 'username', 'password' => 'password']);   // Optional: Set some extra options
        });

        $data = [
            'CurrencyFrom' => 'USD',
            'CurrencyTo'   => 'EUR',
            'RateDate'     => '2014-06-05',
            'Amount'       => '1000'
        ];

        // Using the added service
        SoapWrapper::service('currency', function ($service) use ($data) {
            var_dump($service->getFunctions());
            var_dump($service->call('GetConversionAmount', [$data])->GetConversionAmountResult);
        });
    }

}

Usage as model extension

Like Eloquent you can extent the SoapService on your model. See example:

<?php

use Artisaninweb\SoapWrapper\Extension\SoapService;

class Soap extends SoapService {

    /**
     * @var string
     */
    protected $name = 'currency';

    /**
     * @var string
     */
    protected $wsdl = 'http://currencyconverter.kowabunga.net/converter.asmx?WSDL';
    
    /**
     * @var boolean
     */
    protected $trace = true;

    /**
     * Get all the available functions
     *
     * @return mixed
     */
    public function functions()
    {
        return $this->getFunctions();
    }

}

laravel-soap's People

Contributors

feedbackmatters avatar vitorbari avatar vshushkov avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.