11Laravel SoapClient Wrapper
22===========================
33
4- A SoapClient wrapper integration for Laravel / Lumen.<br />
5- The documentation will be updated in time.
4+ A SoapClient wrapper integration for Laravel.<br />
5+ Makes it easy to use Soap in a Laravel application.<br />
6+
7+ Please report any bugs or features here: <br />
8+ https://github.com/artisaninweb/laravel-soap/issues/
69
710Installation
811============
@@ -14,7 +17,7 @@ Add `artisaninweb/laravel-soap` as requirement to composer.json
1417``` javascript
1518{
1619 " require" : {
17- " artisaninweb/laravel-soap" : " 0.2 .*"
20+ " artisaninweb/laravel-soap" : " 0.3 .*"
1821 }
1922}
2023```
@@ -54,81 +57,210 @@ How to add a service to the wrapper and use it.
5457``` php
5558<?php
5659
57- use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
58-
59- class SoapController {
60-
61- public function demo()
62- {
63- // Add a new service to the wrapper
64- SoapWrapper::add(function ($service) {
65- $service
66- ->name('currency')
67- ->wsdl('http://currencyconverter.kowabunga.net/converter.asmx?WSDL')
68- ->trace(true) // Optional: (parameter: true/false)
69- ->header() // Optional: (parameters: $namespace,$name,$data,$mustunderstand,$actor)
70- ->customHeader($customHeader) // Optional: (parameters: $customerHeader) Use this to add a custom SoapHeader or extended class
71- ->cookie() // Optional: (parameters: $name,$value)
72- ->location() // Optional: (parameter: $location)
73- ->certificate() // Optional: (parameter: $certLocation)
74- ->cache(WSDL_CACHE_NONE) // Optional: Set the WSDL cache
75- ->options(['login' => 'username', 'password' => 'password']); // Optional: Set some extra options
76- });
77-
78- $data = [
79- 'CurrencyFrom' => 'USD',
80- 'CurrencyTo' => 'EUR',
81- 'RateDate' => '2014-06-05',
82- 'Amount' => '1000'
83- ];
84-
85- // Using the added service
86- SoapWrapper::service('currency', function ($service) use ($data) {
87- var_dump($service->getFunctions());
88- var_dump($service->call('GetConversionAmount', [$data])->GetConversionAmountResult);
89- });
90- }
60+ namespace App\Http\Controllers;
61+
62+ use Artisaninweb\SoapWrapper\SoapWrapper;
63+ use App\Soap\Request\GetConversionAmount;
64+ use App\Soap\Response\GetConversionAmountResponse;
9165
66+ class SoapController
67+ {
68+ /**
69+ * @var SoapWrapper
70+ */
71+ protected $soapWrapper;
72+
73+ /**
74+ * SoapController constructor.
75+ *
76+ * @param SoapWrapper $soapWrapper
77+ */
78+ public function __construct(SoapWrapper $soapWrapper)
79+ {
80+ $this->soapWrapper = $soapWrapper;
81+ }
82+
83+ /**
84+ * Use the SoapWrapper
85+ */
86+ public function show()
87+ {
88+ $this->soapWrapper->add('Currency', function ($service) {
89+ $service
90+ ->wsdl('http://currencyconverter.kowabunga.net/converter.asmx?WSDL')
91+ ->trace(true)
92+ ->classmap([
93+ GetConversionAmount::class,
94+ GetConversionAmountResponse::class,
95+ ]);
96+ });
97+
98+ // Without classmap
99+ $response = $this->soapWrapper->call('Currency.GetConversionAmount', [
100+ 'CurrencyFrom' => 'USD',
101+ 'CurrencyTo' => 'EUR',
102+ 'RateDate' => '2014-06-05',
103+ 'Amount' => '1000',
104+ ]);
105+
106+ var_dump($response);
107+
108+ // With classmap
109+ $response = $this->soapWrapper->call('Currency.GetConversionAmount', [
110+ new GetConversionAmount('USD', 'EUR', '2014-06-05', '1000')
111+ ]);
112+
113+ var_dump($response);
114+ exit;
115+ }
92116}
93117```
94118
95- Usage as model extension
119+ Service functions
120+ ============
121+ ``` php
122+ $this->soapWrapper->add('Currency', function ($service) {
123+ ->name() // The name you want to five your service
124+ ->wsdl() // The WSDL url
125+ ->trace(true) // Optional: (parameter: true/false)
126+ ->header() // Optional: (parameters: $namespace,$name,$data,$mustunderstand,$actor)
127+ ->customHeader() // Optional: (parameters: $customerHeader) Use this to add a custom SoapHeader or extended class
128+ ->cookie() // Optional: (parameters: $name,$value)
129+ ->location() // Optional: (parameter: $location)
130+ ->certificate() // Optional: (parameter: $certLocation)
131+ ->cache(WSDL_CACHE_NONE) // Optional: Set the WSDL cache
132+
133+ // Optional: Set some extra options
134+ ->options([
135+ 'login' => 'username',
136+ 'password' => 'password'
137+ ])
138+
139+ // Optional: Classmap
140+ ->classmap([
141+ GetConversionAmount::class,
142+ GetConversionAmountResponse::class,
143+ ]);
144+ });
145+ ```
146+
147+ Classmap
96148============
97149
98- Like Eloquent you can extent the SoapService on your model.
99- See example:
150+ If you are using classmap you can add folders like for example:
151+ - App\Soap
152+ - App\Soap\Request
153+ - App\Soap\Response
154+
155+ Request: App\Soap\Request\GetConversionAmount
100156
101157``` php
102158<?php
103159
104- use Artisaninweb\SoapWrapper\Extension\SoapService ;
160+ namespace App\Soap\Request ;
105161
106- class Soap extends SoapService {
162+ class GetConversionAmount
163+ {
164+ /**
165+ * @var string
166+ */
167+ protected $CurrencyFrom;
168+
169+ /**
170+ * @var string
171+ */
172+ protected $CurrencyTo;
173+
174+ /**
175+ * @var string
176+ */
177+ protected $RateDate;
178+
179+ /**
180+ * @var string
181+ */
182+ protected $Amount;
183+
184+ /**
185+ * GetConversionAmount constructor.
186+ *
187+ * @param string $CurrencyFrom
188+ * @param string $CurrencyTo
189+ * @param string $RateDate
190+ * @param string $Amount
191+ */
192+ public function __construct($CurrencyFrom, $CurrencyTo, $RateDate, $Amount)
193+ {
194+ $this->CurrencyFrom = $CurrencyFrom;
195+ $this->CurrencyTo = $CurrencyTo;
196+ $this->RateDate = $RateDate;
197+ $this->Amount = $Amount;
198+ }
199+
200+ /**
201+ * @return string
202+ */
203+ public function getCurrencyFrom()
204+ {
205+ return $this->CurrencyFrom;
206+ }
207+
208+ /**
209+ * @return string
210+ */
211+ public function getCurrencyTo()
212+ {
213+ return $this->CurrencyTo;
214+ }
215+
216+ /**
217+ * @return string
218+ */
219+ public function getRateDate()
220+ {
221+ return $this->RateDate;
222+ }
223+
224+ /**
225+ * @return string
226+ */
227+ public function getAmount()
228+ {
229+ return $this->Amount;
230+ }
231+ }
232+ ```
107233
108- /**
109- * @var string
110- */
111- protected $name = 'currency';
234+ Response: App\Soap\Response\GetConversionAmountResponse
112235
113- /**
114- * @var string
115- */
116- protected $wsdl = 'http://currencyconverter.kowabunga.net/converter.asmx?WSDL';
117-
118- /**
119- * @var boolean
120- */
121- protected $trace = true;
122-
123- /**
124- * Get all the available functions
125- *
126- * @return mixed
127- */
128- public function functions()
129- {
130- return $this->getFunctions();
131- }
236+ ``` php
237+ <?php
132238
239+ namespace App\Soap\Response;
240+
241+ class GetConversionAmountResponse
242+ {
243+ /**
244+ * @var string
245+ */
246+ protected $GetConversionAmountResult;
247+
248+ /**
249+ * GetConversionAmountResponse constructor.
250+ *
251+ * @param string
252+ */
253+ public function __construct($GetConversionAmountResult)
254+ {
255+ $this->GetConversionAmountResult = $GetConversionAmountResult;
256+ }
257+
258+ /**
259+ * @return string
260+ */
261+ public function getGetConversionAmountResult()
262+ {
263+ return $this->GetConversionAmountResult;
264+ }
133265}
134266```
0 commit comments