1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2013-2016 |
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\Builder; |
25
|
|
|
|
26
|
|
|
use Ouzo\Utilities\Arrays; |
27
|
|
|
use Ouzo\Utilities\Functions; |
28
|
|
|
use Ouzo\Utilities\Optional; |
29
|
|
|
use WSDL\Parser\Node; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Method |
33
|
|
|
* |
34
|
|
|
* @author Piotr Olaszewski <[email protected]> |
35
|
|
|
*/ |
36
|
|
|
class Method |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $name; |
42
|
|
|
/** |
43
|
|
|
* @var Parameter[] |
44
|
|
|
*/ |
45
|
|
|
private $parameters; |
46
|
|
|
/** |
47
|
|
|
* @var Parameter |
48
|
|
|
*/ |
49
|
|
|
private $return; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $name |
53
|
|
|
* @param Parameter[] $parameters |
54
|
|
|
* @param Parameter $return |
55
|
|
|
*/ |
56
|
6 |
|
public function __construct($name, array $parameters, Parameter $return = null) |
57
|
|
|
{ |
58
|
6 |
|
$this->name = $name; |
59
|
6 |
|
$this->parameters = $parameters; |
60
|
6 |
|
$this->return = $return; |
61
|
6 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
1 |
|
public function getName() |
67
|
|
|
{ |
68
|
1 |
|
return $this->name; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return Parameter[] |
73
|
|
|
*/ |
74
|
1 |
|
public function getParameters() |
75
|
|
|
{ |
76
|
1 |
|
return $this->parameters; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return Parameter|null |
81
|
|
|
*/ |
82
|
1 |
|
public function getHeaderParameter() |
83
|
|
|
{ |
84
|
|
|
return Arrays::find($this->parameters, function (Parameter $parameter) { |
85
|
1 |
|
return $parameter->isHeader(); |
86
|
1 |
|
}); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return Parameter[]|array |
91
|
|
|
*/ |
92
|
|
|
public function getNoHeaderParameters() |
93
|
|
|
{ |
94
|
1 |
|
return Arrays::filter($this->parameters, function (Parameter $parameter) { |
95
|
1 |
|
return !$parameter->isHeader(); |
96
|
1 |
|
}); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return Node[] |
101
|
|
|
*/ |
102
|
1 |
|
public function getNoHeaderParametersNodes() |
103
|
|
|
{ |
104
|
1 |
|
return Arrays::map($this->getNoHeaderParameters(), Functions::extractExpression('getNode()')); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return Parameter |
109
|
|
|
*/ |
110
|
1 |
|
public function getReturn() |
111
|
|
|
{ |
112
|
1 |
|
return $this->return; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return Parameter|null |
117
|
|
|
*/ |
118
|
1 |
|
public function getHeaderReturn() |
119
|
|
|
{ |
120
|
1 |
|
if (Optional::fromNullable($this->return)->isHeader()->or(false)) { |
121
|
|
|
return $this->return; |
122
|
|
|
} |
123
|
1 |
|
return null; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return Node|null |
128
|
|
|
*/ |
129
|
1 |
|
public function getReturnNode() |
130
|
|
|
{ |
131
|
1 |
|
return Optional::fromNullable($this->return)->getNode()->or(null); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|