Skip to content

Commit

Permalink
Make using ping an opt-in feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Mar 24, 2024
1 parent 706ca1e commit f27e4c8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/PhpseclibV3/SimpleConnectivityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,34 @@

class SimpleConnectivityChecker implements ConnectivityChecker
{
public function __construct(
private bool $usePing = false,
) {
}

public static function create(): SimpleConnectivityChecker
{
return new SimpleConnectivityChecker();
}

public function withUsingPing(bool $usePing): SimpleConnectivityChecker
{
$clone = clone $this;
$clone->usePing = $usePing;

return $clone;
}

public function isConnected(SFTP $connection): bool
{
if ( ! $connection->isConnected()) {
return false;
}

if ( ! $this->usePing) {
return true;
}

try {
return $connection->ping();
} catch (Throwable) {
Expand Down

0 comments on commit f27e4c8

Please sign in to comment.