Repository: artisaninweb/laravel-soap
Branch: master
Commit: 809073fe1116
Files: 12
Total size: 19.4 KB
Directory structure:
gitextract_te66_s1h/
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
└── src/
└── Artisaninweb/
└── SoapWrapper/
├── Client.php
├── Exceptions/
│ ├── ServiceAlreadyExists.php
│ ├── ServiceMethodNotExists.php
│ └── ServiceNotFound.php
├── Facade.php
├── Service.php
├── ServiceProvider.php
└── SoapWrapper.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.idea
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2014 Michael van de Rijt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
Laravel SoapClient Wrapper
===========================
A SoapClient wrapper integration for Laravel.
Makes it easy to use Soap in a Laravel application.
Please report any bugs or features here:
https://github.com/artisaninweb/laravel-soap/issues/
Installation
============
## Laravel
####Installation for Laravel 5.2 and above:
Run `composer require artisaninweb/laravel-soap`
Add the service provider in `app/config/app.php`.
```php
Artisaninweb\SoapWrapper\ServiceProvider::class,
```
To use the alias, add this to the aliases in `app/config/app.php`.
```php
'SoapWrapper' => Artisaninweb\SoapWrapper\Facade\SoapWrapper::class,
```
####Installation for Laravel 5.1 and below :
Add `artisaninweb/laravel-soap` as requirement to composer.json
```javascript
{
"require": {
"artisaninweb/laravel-soap": "0.3.*"
}
}
```
> If you're using Laravel 5.5 or higher you can skip the two config setups below.
Add the service provider in `app/config/app.php`.
```php
'Artisaninweb\SoapWrapper\ServiceProvider'
```
To use the facade add this to the facades in `app/config/app.php`.
```php
'SoapWrapper' => 'Artisaninweb\SoapWrapper\Facade'
```
## Lumen
Open `bootstrap/app.php` and register the required service provider:
```php
$app->register(Artisaninweb\SoapWrapper\ServiceProvider::class);
```
register class alias:
```php
class_alias('Artisaninweb\SoapWrapper\Facade', 'SoapWrapper');
```
*Facades must be enabled.*
Usage
============
How to add a service to the wrapper and use it.
```php
soapWrapper = $soapWrapper;
}
/**
* Use the SoapWrapper
*/
public function show()
{
$this->soapWrapper->add('Currency', function ($service) {
$service
->wsdl('http://currencyconverter.kowabunga.net/converter.asmx?WSDL')
->trace(true)
->classmap([
GetConversionAmount::class,
GetConversionAmountResponse::class,
]);
});
// Without classmap
$response = $this->soapWrapper->call('Currency.GetConversionAmount', [
'CurrencyFrom' => 'USD',
'CurrencyTo' => 'EUR',
'RateDate' => '2014-06-05',
'Amount' => '1000',
]);
var_dump($response);
// With classmap
$response = $this->soapWrapper->call('Currency.GetConversionAmount', [
new GetConversionAmount('USD', 'EUR', '2014-06-05', '1000')
]);
var_dump($response);
exit;
}
}
```
Service functions
============
```php
$this->soapWrapper->add('Currency', function ($service) {
$service
->wsdl() // The WSDL url
->trace(true) // Optional: (parameter: true/false)
->header() // Optional: (parameters: $namespace,$name,$data,$mustunderstand,$actor)
->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
// Optional: Set some extra options
->options([
'login' => 'username',
'password' => 'password'
])
// Optional: Classmap
->classmap([
GetConversionAmount::class,
GetConversionAmountResponse::class,
]);
});
```
Classmap
============
If you are using classmap you can add folders like for example:
- App\Soap
- App\Soap\Request
- App\Soap\Response
Request: App\Soap\Request\GetConversionAmount
```php
CurrencyFrom = $CurrencyFrom;
$this->CurrencyTo = $CurrencyTo;
$this->RateDate = $RateDate;
$this->Amount = $Amount;
}
/**
* @return string
*/
public function getCurrencyFrom()
{
return $this->CurrencyFrom;
}
/**
* @return string
*/
public function getCurrencyTo()
{
return $this->CurrencyTo;
}
/**
* @return string
*/
public function getRateDate()
{
return $this->RateDate;
}
/**
* @return string
*/
public function getAmount()
{
return $this->Amount;
}
}
```
Response: App\Soap\Response\GetConversionAmountResponse
```php
GetConversionAmountResult = $GetConversionAmountResult;
}
/**
* @return string
*/
public function getGetConversionAmountResult()
{
return $this->GetConversionAmountResult;
}
}
```
================================================
FILE: composer.json
================================================
{
"name": "artisaninweb/laravel-soap",
"description": "A SoapClient wrapper integration for Laravel",
"keywords": ["laravel", "soap", "client", "wrapper"],
"license": "MIT",
"authors": [
{
"name": "Michael van de Rijt",
"email": "me@mvdrijt.com"
}
],
"require": {
"php": ">=5.4.0",
"ext-soap": "*"
},
"autoload": {
"psr-0": {
"Artisaninweb\\SoapWrapper": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Artisaninweb\\SoapWrapper\\ServiceProvider"
],
"aliases": {
"SoapWrapper": "Artisaninweb\\SoapWrapper\\Facade"
}
}
}
}
================================================
FILE: src/Artisaninweb/SoapWrapper/Client.php
================================================
headers($headers);
}
}
/**
* Get all functions from the service
*
* @return mixed
*/
public function getFunctions()
{
return $this->__getFunctions();
}
/**
* Get the last request
*
* @return mixed
*/
public function getLastRequest()
{
return $this->__getLastRequest();
}
/**
* Get the last response
*
* @return mixed
*/
public function getLastResponse()
{
return $this->__getLastResponse();
}
/**
* Get the last request headers
*
* @return mixed
*/
public function getLastRequestHeaders()
{
return $this->__getLastRequestHeaders();
}
/**
* Get the last response headers
*
* @return mixed
*/
public function getLastResponseHeaders()
{
return $this->__getLastResponseHeaders();
}
/**
* Get the types
*
* @return mixed
*/
public function getTypes()
{
return $this->__getTypes();
}
/**
* Get all the set cookies
*
* @return mixed
*/
public function getCookies()
{
return $this->__getCookies();
}
/**
* Set a new cookie
*
* @param string $name
* @param string $value
*
* @return $this
*/
public function cookie($name, $value)
{
$this->__setCookie($name, $value);
return $this;
}
/**
* Set the location
*
* @param string $location
*
* @return $this
*/
public function location($location = '')
{
$this->__setLocation($location);
return $this;
}
/**
* Set the Soap headers
*
* @param array $headers
*
* @return $this
*/
protected function headers(array $headers = [])
{
$this->__setSoapHeaders($headers);
return $this;
}
/**
* Do soap request
*
* @param string $request
* @param string $location
* @param string $action
* @param string $version
* @param string $one_way
*
* @return mixed
*/
public function doRequest($request, $location, $action, $version, $one_way)
{
return $this->__doRequest($request, $location, $action, $version, $one_way);
}
/**
* Do a soap call on the webservice client
*
* @param string $function
* @param array $params
*
* @return mixed
*/
public function call($function, $params)
{
return call_user_func_array([$this, $function], $params);
}
/**
* Allias to do a soap call on the webservice client
*
* @param string $function
* @param array $params
* @param array $options
* @param null $inputHeader
* @param null $outputHeaders
*
* @return mixed
*/
public function SoapCall($function,
array $params,
array $options = null,
$inputHeader = null,
&$outputHeaders = null
) {
return $this->__soapCall($function, $params, $options, $inputHeader, $outputHeaders);
}
}
================================================
FILE: src/Artisaninweb/SoapWrapper/Exceptions/ServiceAlreadyExists.php
================================================
wsdl = null;
$this->client = null;
$this->certificate = false;
$this->options = [];
$this->classmap = [];
$this->headers = [];
}
/**
* Set a custom client
*
* @param SoapClient $client
*
* @return $this
*/
public function client(SoapClient $client)
{
$this->client = $client;
return $this;
}
/**
* Get the custom client
*
* @return SoapClient
*/
public function getClient()
{
return $this->client;
}
/**
* Set the wsdl of the service
*
* @param string $wsdl
*
* @return $this
*/
public function wsdl($wsdl)
{
$this->wsdl = $wsdl;
return $this;
}
/**
* Get the wsdl from the service
*
* @return string
*/
public function getWsdl()
{
return $this->wsdl;
}
/**
* Set trace option - enables tracing of request
*
* @param boolean $trace
*
* @return $this
*/
public function trace($trace)
{
$this->trace = $trace;
return $this;
}
/**
* Get the trace option
*
* @return boolean
*/
public function getTrace()
{
return $this->trace;
}
/**
* Set the WSDL cache
*
* @param $cache
*
* @return $this
*/
public function cache($cache)
{
$this->cache = $cache;
return $this;
}
/**
* Get the WSDL cache
*
* @return string
*/
public function getCache()
{
return $this->cache;
}
/**
* @param array $classmap
*
* @return $this
*/
public function classMap(array $classmap)
{
$this->classmap = $classmap;
return $this;
}
/**
* Get the classmap
*
* @return array
*/
public function getClassmap()
{
$classmap = $this->classmap;
$classes = [] ;
if (!empty($classmap)) {
foreach ($classmap as $class) {
// Can't use end because of strict mode :(
$name = current(array_slice(explode('\\', $class), -1, 1, true));
$classes[$name] = $class;
}
}
return $classes;
}
/**
* Set the extra options on the SoapClient
*
* @param array $options
*
* @return $this
*/
public function options(array $options)
{
$this->options = $options;
return $this;
}
/**
* Get the extra options
*
* @return array
*/
public function getOptions()
{
$options = [
'trace' => $this->getTrace(),
'cache_wsdl' => $this->getCache(),
'classmap' => $this->getClassmap(),
];
if ($this->certificate) {
$options['local_cert'] = $this->certificate;
}
$this->options = array_merge($options, $this->options);
return $this->options;
}
/**
* Set the certificate location
*
* @param string $certificate
*
* @return $this
*/
public function certificate($certificate)
{
if ($certificate) {
$this->certificate = $certificate;
}
return $this;
}
/**
* Get the headers
*
* @return array
*/
public function getHeaders()
{
return $this->headers;
}
/**
* Create a new SoapHeader
*
* @param string $namespace
* @param string $name
* @param null $data
* @param bool $mustUnderstand
* @param null $actor
*
* @return $this
*/
public function header($namespace, $name, $data = null, $mustUnderstand = false, $actor = null)
{
if ($actor) {
$this->headers[] = new SoapHeader($namespace, $name, $data, $mustUnderstand, $actor);
} else {
$this->headers[] = new SoapHeader($namespace, $name, $data, $mustUnderstand);
}
return $this;
}
/**
* Set the Soap headers
*
* @param SoapHeader $header
*
* @return $this
*/
public function customHeader($header)
{
$this->headers[] = $header;
return $this;
}
}
================================================
FILE: src/Artisaninweb/SoapWrapper/ServiceProvider.php
================================================
app['config']['soapwrapper'])) {
$soapWrapper->addByArray($this->app['config']['soapwrapper']);
}
$this->app->bindIf(SoapWrapper::class, function () use ($soapWrapper) {
return $soapWrapper;
});
}
}
================================================
FILE: src/Artisaninweb/SoapWrapper/SoapWrapper.php
================================================
services = [];
}
/**
* Add a new service to the wrapper
*
* @param string $name
* @param Closure $closure
*
* @return $this
* @throws ServiceAlreadyExists
*/
public function add($name, Closure $closure)
{
if (!$this->has($name)) {
$service = new Service();
$closure($service);
$this->services[$name] = $service;
return $this;
}
throw new ServiceAlreadyExists("Service '" . $name . "' already exists.");
}
/**
* Add services by array
*
* @param array $services
*
* @return $this
*
* @throws ServiceAlreadyExists
* @throws ServiceMethodNotExists
*/
public function addByArray(array $services = [])
{
if (!empty($services)) {
foreach ($services as $name => $methods) {
if (!$this->has($name)) {
$service = new Service();
foreach ($methods as $method => $value) {
if (method_exists($service, $method)) {
$service->{$method}($value);
} else {
throw new ServiceMethodNotExists(sprintf(
"Method '%s' does not exists on the %s service.",
$method,
$name
));
}
}
$this->services[$name] = $service;
continue;
}
throw new ServiceAlreadyExists(sprintf(
"Service '%s' already exists.",
$name
));
}
}
return $this;
}
/**
* Get the client
*
* @param string $name
* @param Closure $closure
*
* @return mixed
* @throws ServiceNotFound
*/
public function client($name, Closure $closure = null)
{
if ($this->has($name)) {
/** @var Service $service */
$service = $this->services[$name];
if (is_null($service->getClient())) {
$client = new Client($service->getWsdl(), $service->getOptions(), $service->getHeaders());
$service->client($client);
} else {
$client = $service->getClient();
}
return $closure($client);
}
throw new ServiceNotFound("Service '" . $name . "' not found.");
}
/**
* A easy access call method
*
* @param string $call
* @param array $data
*
* @return mixed
*/
public function call($call, $data = [], $options = [])
{
list($name, $function) = explode('.', $call, 2);
return $this->client($name, function ($client) use ($function, $data, $options) {
/** @var Client $client */
return $client->SoapCall($function, $data, $options);
});
}
/**
* Check if wrapper has service
*
* @param string $name
*
* @return bool
*/
public function has($name)
{
return (array_key_exists($name, $this->services));
}
}