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.
Examples
Section titled “Examples”// 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";}Methods
Section titled “Methods”__construct()
Section titled “__construct()”Servers constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | Reference to the main bot instance. |
Retrieves a server by ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
$id | string | The server ID. |
Returns \Server|null
getFirst()
Section titled “getFirst()”Returns the first (or only) server in the collection.
Perfect for single-server bots.
Returns \Server|null
offsetExists()
Section titled “offsetExists()”Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
Returns bool
offsetGet()
Section titled “offsetGet()”Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
Returns ?Server
offsetSet()
Section titled “offsetSet()”Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | |
$value | mixed |
Throws
\LogicException
offsetUnset()
Section titled “offsetUnset()”Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
Throws
\LogicException
count()
Section titled “count()”Returns int
getIterator()
Section titled “getIterator()”Returns \ArrayIterator<string,\Server>