# HostingPackagesEvent events

> 3 FeatherPanel plugin events on HostingPackagesEvent (3 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/hosting-packages/

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 `HostingPackagesEvent` 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\HostingPackagesEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(HostingPackagesEvent::onHostingPackageDeleted(), function ($packageId, $package): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:hosting_packages:package:deleted ' . json_encode(['package_id' => $packageId, 'package' => $package]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `HostingPackagesEvent::onHostingPackageCreated()`

- Name: `featherpanel:admin:hosting_packages:package:created`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/HostingPackagesEvent.php#L27)

Docblock: array package data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `package` | `$package` | `array`from docblock |

When it fires (1 site)

-   [`HostingPackagesController::create`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/HostingPackagesController.php#L66) via `emitPluginEvent()`[`PUT /api/admin/hosting-packages`](https://featherpanel.com/docs/api/reference/admin/hosting-packages/#put-admin-hosting-packages)

```php
$event->on(HostingPackagesEvent::onHostingPackageCreated(), function ($package): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:hosting_packages:package:created ' . json_encode(['package' => $package]));
});
```

## `HostingPackagesEvent::onHostingPackageDeleted()`

- Name: `featherpanel:admin:hosting_packages:package:deleted`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/HostingPackagesEvent.php#L43)

Docblock: int package id, array package data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `package_id` | `$packageId` | `int` |
| 2 | `package` | `$package` | `array`from docblock |

When it fires (1 site)

-   [`HostingPackagesController::delete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/HostingPackagesController.php#L109) via `emitPluginEvent()`[`DELETE /api/admin/hosting-packages/{id}`](https://featherpanel.com/docs/api/reference/admin/hosting-packages/#delete-admin-hosting-packages-id)

```php
$event->on(HostingPackagesEvent::onHostingPackageDeleted(), function ($packageId, $package): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:hosting_packages:package:deleted ' . json_encode(['package_id' => $packageId, 'package' => $package]));
});
```

## `HostingPackagesEvent::onHostingPackageUpdated()`

- Name: `featherpanel:admin:hosting_packages:package:updated`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/HostingPackagesEvent.php#L35)

Docblock: int package id, array package data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `package_id` | `$packageId` | `int` |
| 2 | `package` | `$package` | `array`from docblock |

When it fires (1 site)

-   [`HostingPackagesController::update`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/HostingPackagesController.php#L89) via `emitPluginEvent()`[`PATCH /api/admin/hosting-packages/{id}`](https://featherpanel.com/docs/api/reference/admin/hosting-packages/#patch-admin-hosting-packages-id)

```php
$event->on(HostingPackagesEvent::onHostingPackageUpdated(), function ($packageId, $package): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:hosting_packages:package:updated ' . json_encode(['package_id' => $packageId, 'package' => $package]));
});
```
