1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
15
|
|
|
* |
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
17
|
|
|
* and is licensed under the LGPL. For more information please see |
18
|
|
|
* <http://phing.info>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Phing\Task\Ext; |
22
|
|
|
|
23
|
|
|
use Phing\Exception\BuildException; |
24
|
|
|
use Phing\Project; |
25
|
|
|
use Phing\Type\DataType; |
26
|
|
|
use Phing\Util\StringHelper; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class that holds parameters for an ssh2_connect $methods parameter |
30
|
|
|
* This corresponds to the optional $methods parameter |
31
|
|
|
* for the ssh2_connect function |
32
|
|
|
* |
33
|
|
|
* @see http://php.net/ssh2_connect |
34
|
|
|
* |
35
|
|
|
* @author Derek Gallo <http://github.com/drock> |
36
|
|
|
* |
37
|
|
|
* @package phing.tasks.ext |
38
|
|
|
*/ |
39
|
|
|
class Ssh2MethodParam extends DataType |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $kex; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $hostkey; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var Ssh2MethodConnectionParam |
53
|
|
|
*/ |
54
|
|
|
private $client_to_server; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var Ssh2MethodConnectionParam |
58
|
|
|
*/ |
59
|
|
|
private $server_to_client; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $hostkey |
63
|
|
|
*/ |
64
|
|
|
public function setHostkey($hostkey) |
65
|
|
|
{ |
66
|
|
|
$this->hostkey = $hostkey; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param Project $p |
71
|
|
|
* @throws BuildException |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function getHostkey(Project $p) |
75
|
|
|
{ |
76
|
|
|
if ($this->isReference()) { |
77
|
|
|
return $this->getRef($p)->getHostkey($p); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->hostkey; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $kex |
85
|
|
|
*/ |
86
|
|
|
public function setKex($kex) |
87
|
|
|
{ |
88
|
|
|
$this->kex = $kex; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param Project $p |
93
|
|
|
* @throws BuildException |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function getKex(Project $p) |
97
|
|
|
{ |
98
|
|
|
if ($this->isReference()) { |
99
|
|
|
return $this->getRef($p)->getKex($p); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $this->kex; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param Project $p |
107
|
|
|
* @throws BuildException |
108
|
|
|
* @return Ssh2MethodConnectionParam |
109
|
|
|
*/ |
110
|
|
|
public function getClientToServer(Project $p) |
111
|
|
|
{ |
112
|
|
|
if ($this->isReference()) { |
113
|
|
|
return $this->getRef($p)->getClientToServer($p); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $this->client_to_server; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param Project $p |
121
|
|
|
* @throws BuildException |
122
|
|
|
* @return Ssh2MethodConnectionParam |
123
|
|
|
*/ |
124
|
|
|
public function getServerToClient(Project $p) |
125
|
|
|
{ |
126
|
|
|
if ($this->isReference()) { |
127
|
|
|
return $this->getRef($p)->getServerToClient($p); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $this->server_to_client; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Handles the <client /> nested element |
135
|
|
|
* |
136
|
|
|
* @return Ssh2MethodConnectionParam |
137
|
|
|
*/ |
138
|
|
|
public function createClient() |
139
|
|
|
{ |
140
|
|
|
$this->client_to_server = new Ssh2MethodConnectionParam(); |
141
|
|
|
|
142
|
|
|
return $this->client_to_server; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Handles the <server /> nested element |
147
|
|
|
* |
148
|
|
|
* @return Ssh2MethodConnectionParam |
149
|
|
|
*/ |
150
|
|
|
public function createServer() |
151
|
|
|
{ |
152
|
|
|
$this->server_to_client = new Ssh2MethodConnectionParam(); |
153
|
|
|
|
154
|
|
|
return $this->server_to_client; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Convert the params to an array that is suitable to be passed in the ssh2_connect $methods parameter |
159
|
|
|
* |
160
|
|
|
* @param Project $p |
161
|
|
|
* @return array |
162
|
|
|
*/ |
163
|
|
|
public function toArray(Project $p) |
164
|
|
|
{ |
165
|
|
|
$client_to_server = $this->getClientToServer($p); |
166
|
|
|
$server_to_client = $this->getServerToClient($p); |
167
|
|
|
|
168
|
|
|
$array = [ |
169
|
|
|
'kex' => $this->getKex($p), |
170
|
|
|
'hostkey' => $this->getHostkey($p), |
171
|
|
|
'client_to_server' => null !== $client_to_server ? $client_to_server->toArray() : null, |
172
|
|
|
'server_to_client' => null !== $server_to_client ? $server_to_client->toArray() : null |
173
|
|
|
]; |
174
|
|
|
|
175
|
|
|
return array_filter($array, [$this, 'filterParam']); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param $var |
180
|
|
|
* @return boolean |
181
|
|
|
*/ |
182
|
|
|
protected function filterParam($var) |
183
|
|
|
{ |
184
|
|
|
if (is_array($var)) { |
185
|
|
|
return !empty($var); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return null !== $var; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* |
193
|
|
|
* @param Project $p |
194
|
|
|
* @throws BuildException |
195
|
|
|
* @return Ssh2MethodParam |
196
|
|
|
*/ |
197
|
|
|
public function getRef(Project $p) |
|
|
|
|
198
|
|
|
{ |
199
|
|
|
$dataTypeName = StringHelper::substring(__CLASS__, strrpos(__CLASS__, '\\') + 1); |
200
|
|
|
return $this->getCheckedRef(__CLASS__, $dataTypeName); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.