|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2013-2015 |
|
4
|
|
|
* Piotr Olaszewski <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
8
|
|
|
* in the Software without restriction, including without limitation the rights |
|
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
11
|
|
|
* furnished to do so, subject to the following conditions: |
|
12
|
|
|
* |
|
13
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
14
|
|
|
* all copies or substantial portions of the Software. |
|
15
|
|
|
* |
|
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
22
|
|
|
* SOFTWARE. |
|
23
|
|
|
*/ |
|
24
|
|
|
namespace WSDL\Service; |
|
25
|
|
|
|
|
26
|
|
|
use SoapClient; |
|
27
|
|
|
use stdClass; |
|
28
|
|
|
use WSDL\Parser\MethodParser; |
|
29
|
|
|
use WSDL\Types\Arrays; |
|
30
|
|
|
use WSDL\Types\Simple; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Service |
|
34
|
|
|
* |
|
35
|
|
|
* @author Piotr Olaszewski <[email protected]> |
|
36
|
|
|
*/ |
|
37
|
|
|
class Service |
|
38
|
|
|
{ |
|
39
|
|
|
public $template; |
|
40
|
|
|
|
|
41
|
|
|
private $wsdl; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var MethodParser[] |
|
44
|
|
|
*/ |
|
45
|
|
|
private $methods; |
|
46
|
|
|
private $location; |
|
47
|
|
|
|
|
48
|
|
|
public function __construct($location, $wsdl, $methods) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->location = $location; |
|
51
|
|
|
$this->wsdl = $wsdl; |
|
52
|
|
|
$this->methods = $methods; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function render($name, $namespace) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->template = new stdClass(); |
|
58
|
|
|
$this->template->serviceName = $name; |
|
59
|
|
|
$this->template->serviceNamespace = $namespace; |
|
60
|
|
|
$this->template->methods = $this->_wrapperMethods(); |
|
61
|
|
|
require_once 'service_template.phtml'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
private function _wrapperMethods() |
|
65
|
|
|
{ |
|
66
|
|
|
$methods = array(); |
|
67
|
|
|
foreach ($this->methods as $method) { |
|
68
|
|
|
$soapClient = new SoapClient($this->wsdl, array( |
|
69
|
|
|
'uri' => "http://foo.bar/", |
|
70
|
|
|
'location' => $this->location, |
|
71
|
|
|
'trace' => true, |
|
72
|
|
|
'cache_wsdl' => WSDL_CACHE_NONE |
|
73
|
|
|
)); |
|
74
|
|
|
call_user_func_array(array($soapClient, $method->getName()), $this->getParams($method)); |
|
75
|
|
|
$methods[] = new MethodWrapper($method->getName(), $method->getRawParameters(), $method->getRawReturn(), $soapClient->__getLastRequest()); |
|
76
|
|
|
} |
|
77
|
|
|
return $methods; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function getParams(MethodParser $method) |
|
81
|
|
|
{ |
|
82
|
|
|
$result = array(); |
|
83
|
|
|
foreach ($method->parameters() as $parameter) { |
|
84
|
|
|
if ($parameter instanceof Simple) { |
|
85
|
|
|
$result[] = '?'; |
|
86
|
|
|
} |
|
87
|
|
|
if ($parameter instanceof Arrays) { |
|
88
|
|
|
$result[] = array('?', '?', '?'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
return $result; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|