Contracts

LifecycleAwareInterface

v1.0.0

Lifecycle hooks invoked by the runtime when the SDK is ready or the module is activated, deactivated, upgraded, or uninstalled.

Namespace

use Meteorack\Sdk\Core\Contracts\LifecycleAwareInterface;

How To Use It

  • Override only the hooks you need. AbstractModule already stores SdkContext in onSdkReady() and provides no-op defaults for the rest.
  • Keep one-time setup, upgrade, and cleanup work inside the dedicated lifecycle hooks instead of mixing them into normal boot logic.

Methods

public function onSdkReady(SdkContext $ctx): void

Runs after the runtime builds SdkContext and before module work begins.

public function onActivate(): void

Runs when the module is activated.

public function onDeactivate(): void

Runs when the module is deactivated.

public function onUpgrade(string $previousVersion): void

Runs after an upgrade and receives the previous installed version.

public function onUninstall(): void

Runs when the module is fully uninstalled and can clean up persistent resources.

Example

bootstrap.php
<?php

declare(strict_types=1);

use Meteorack\Sdk\Core\SdkContext;
use Meteorack\Sdk\RuntimeWp\AbstractModule;

class ReportsModule extends AbstractModule
{
    public function getSlug(): string { return 'reports'; }
    public function getName(): string { return 'Reports'; }
    public function getVersion(): string { return '1.2.0'; }

    public function onSdkReady(SdkContext $ctx): void
    {
        parent::onSdkReady($ctx);
        $ctx->logger()->info('reports.boot', []);
    }

    public function onActivate(): void
    {
        $this->setSetting('enabled', true);
    }

    public function onUpgrade(string $previousVersion): void
    {
        $this->getSdkContext()->logger()->info('reports.upgraded', [
            'previous_version' => $previousVersion,
        ]);
    }
}

return new ReportsModule();