Skip to content

Commit f27e4c8

Browse files
committed
Make using ping an opt-in feature.
1 parent 706ca1e commit f27e4c8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/PhpseclibV3/SimpleConnectivityChecker.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,34 @@
99

1010
class SimpleConnectivityChecker implements ConnectivityChecker
1111
{
12+
public function __construct(
13+
private bool $usePing = false,
14+
) {
15+
}
16+
17+
public static function create(): SimpleConnectivityChecker
18+
{
19+
return new SimpleConnectivityChecker();
20+
}
21+
22+
public function withUsingPing(bool $usePing): SimpleConnectivityChecker
23+
{
24+
$clone = clone $this;
25+
$clone->usePing = $usePing;
26+
27+
return $clone;
28+
}
29+
1230
public function isConnected(SFTP $connection): bool
1331
{
1432
if ( ! $connection->isConnected()) {
1533
return false;
1634
}
1735

36+
if ( ! $this->usePing) {
37+
return true;
38+
}
39+
1840
try {
1941
return $connection->ping();
2042
} catch (Throwable) {

0 commit comments

Comments
 (0)