# RateLimiterEvent events

> 4 FeatherPanel plugin events on RateLimiterEvent (4 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/rate-limiter/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions.

## Setup

Import `RateLimiterEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\RateLimiterEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(RateLimiterEvent::onRateLimiterBulkUpdated(), function ($userUuid, $updatedRoutes, $errors): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:rate-limiter:bulk:update ' . json_encode(['user_uuid' => $userUuid, 'updated_routes' => $updatedRoutes, 'errors' => $errors]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `RateLimiterEvent::onRateLimiterBulkUpdated()`

- Name: `featherpanel:rate-limiter:bulk:update`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/RateLimiterEvent.php#L51)

Docblock: string|null user uuid, array updated routes, array errors.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string|null`from docblock |
| 2 | `updated_routes` | `$updatedRoutes` | `array` |
| 3 | `errors` | `$errors` | `array` |

When it fires (1 site)

-   [`RateLimitController::bulkUpdate`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/RateLimitController.php#L571) via `emitEvent()`[`PATCH /api/admin/rate-limits/bulk`](https://featherpanel.com/docs/api/reference/admin/rate-limits/#patch-admin-rate-limits-bulk)

```php
$event->on(RateLimiterEvent::onRateLimiterBulkUpdated(), function ($userUuid, $updatedRoutes, $errors): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:rate-limiter:bulk:update ' . json_encode(['user_uuid' => $userUuid, 'updated_routes' => $updatedRoutes, 'errors' => $errors]));
});
```

## `RateLimiterEvent::onRateLimiterDeleted()`

- Name: `featherpanel:rate-limiter:delete`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/RateLimiterEvent.php#L43)

Docblock: string|null user uuid, string route name.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string|null`from docblock |
| 2 | `route_name` | `$routeName` | `string` |

When it fires (1 site)

-   [`RateLimitController::delete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/RateLimitController.php#L465) via `emitEvent()`[`DELETE /api/admin/rate-limits/{routeName}`](https://featherpanel.com/docs/api/reference/admin/rate-limits/#delete-admin-rate-limits-routeName)

```php
$event->on(RateLimiterEvent::onRateLimiterDeleted(), function ($userUuid, $routeName): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:rate-limiter:delete ' . json_encode(['user_uuid' => $userUuid, 'route_name' => $routeName]));
});
```

## `RateLimiterEvent::onRateLimiterGlobalUpdated()`

- Name: `featherpanel:rate-limiter:global:update`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/RateLimiterEvent.php#L27)

Docblock: string|null user uuid, bool enabled.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string|null`from docblock |
| 2 | `enabled` | `$enabled` | `bool` |

When it fires (1 site)

-   [`RateLimitController::updateGlobal`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/RateLimitController.php#L220) via `emitEvent()`[`PATCH /api/admin/rate-limits/global`](https://featherpanel.com/docs/api/reference/admin/rate-limits/#patch-admin-rate-limits-global)

```php
$event->on(RateLimiterEvent::onRateLimiterGlobalUpdated(), function ($userUuid, $enabled): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:rate-limiter:global:update ' . json_encode(['user_uuid' => $userUuid, 'enabled' => $enabled]));
});
```

## `RateLimiterEvent::onRateLimiterUpdated()`

- Name: `featherpanel:rate-limiter:update`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/RateLimiterEvent.php#L35)

Docblock: string|null user uuid, string route name, array config.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string|null`from docblock |
| 2 | `route_name` | `$routeName` | `string` |
| 3 | `config` | `$config` | `array`from docblock |

When it fires (1 site)

-   [`RateLimitController::update`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/RateLimitController.php#L373) via `emitEvent()`[`PUT /api/admin/rate-limits/{routeName}`](https://featherpanel.com/docs/api/reference/admin/rate-limits/#put-admin-rate-limits-routeName)

```php
$event->on(RateLimiterEvent::onRateLimiterUpdated(), function ($userUuid, $routeName, $config): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:rate-limiter:update ' . json_encode(['user_uuid' => $userUuid, 'route_name' => $routeName, 'config' => $config]));
});
```
