Category
Class · Sharkord\Models\Category
Class Category
Represents a channel category on the server.
Examples
Section titled “Examples”// Rename a category$sharkord->categories->get(3)?->edit('Renamed Category')->then(function() { echo "Category renamed.\n";});
// Delete a category$sharkord->categories->get(3)?->delete()->then(function() { echo "Category deleted.\n";});
// Re-fetch the latest data from the server$sharkord->categories->get(3)?->fetch()->then(function(\Sharkord\Models\Category $category) { echo "Refreshed: {$category->name}\n";});Methods
Section titled “Methods”__construct()
Section titled “__construct()”Category constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | Reference to the main bot instance. |
$rawData | array | The raw array of data from the API. |
static fromArray()
Section titled “static fromArray()”Factory method to create a Category from raw API data.
Parameters
| Parameter | Type | Description |
|---|---|---|
$raw | array | The raw category data from the server. |
$sharkord | Sharkord | Reference to the main bot instance. |
Returns self
fetch()
Section titled “fetch()”Re-fetches this category’s data from the server and updates the local model.
Useful when you need guaranteed up-to-date data outside of a subscription event (e.g. after a reorder).
Returns \PromiseInterface — Resolves with this Category model (updated in place), rejects on failure.
Example
$sharkord->categories->get(3)?->fetch()->then(function(\Sharkord\Models\Category $category) { echo "Current position: {$category->position}\n";});edit()
Section titled “edit()”Renames this category.
The server will push a categories.onUpdate event once the change is
accepted. The cached model is updated automatically via the subscription
handler.
Requires the MANAGE_CATEGORIES permission.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The new category name. |
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
$sharkord->categories->get(3)?->edit('🏉 Footy Talk')->then(function() { echo "Category renamed.\n";});delete()
Section titled “delete()”Permanently deletes this category from the server.
Requires the MANAGE_CATEGORIES permission. The category is removed from the local cache once the server emits the corresponding categorydelete event.
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
$sharkord->categories->get(7)?->delete()->then(function() { echo "Category deleted.\n";});toArray()
Section titled “toArray()”Returns all the attributes as a plain array. Useful for debugging.
Returns array<string,mixed>
Example
var_dump($sharkord->categories->get(3)?->toArray());__isset()
Section titled “__isset()”Magic isset check. Allows isset() and empty() to work correctly against dynamic properties stored in the attributes array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns bool
__get()
Section titled “__get()”Magic getter. Triggered whenever you try to access a property that isn’t explicitly defined (e.g. $category->name or $category->position).
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns mixed