Skip to content

Servers

Class  ·  Sharkord\Collections\Servers

Class Servers

An array-accessible, iterable cache of Server objects keyed by server ID (string).

In practice SharkordPHP connects to a single server at a time, so getFirst() is the most commonly used method. The full collection interface is provided for consistency and forward compatibility.

// Single-server bots
$server = $sharkord->servers->collection()->getFirst();
// Look up by ID
$server = $sharkord->servers->collection()->get('abc123');
foreach ($sharkord->servers->collection() as $id => $server) {
echo "{$server->name}\n";
}

Servers constructor.

Parameters

ParameterTypeDescription
$sharkordSharkordReference to the main bot instance.

Retrieves a server by ID.

Parameters

ParameterTypeDescription
$idstringThe server ID.

Returns \Server|null


Returns the first (or only) server in the collection.

Perfect for single-server bots.

Returns \Server|null


Parameters

ParameterTypeDescription
$offsetmixed

Returns bool


Parameters

ParameterTypeDescription
$offsetmixed

Returns ?Server


Parameters

ParameterTypeDescription
$offsetmixed
$valuemixed

Throws

  • \LogicException

Parameters

ParameterTypeDescription
$offsetmixed

Throws

  • \LogicException

Returns int


Returns \ArrayIterator<string,\Server>