Contracts
LifecycleAwareInterface
v1.0.0Lifecycle 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.
Works Well With
Methods
public function onSdkReady(SdkContext $ctx): voidRuns after the runtime builds SdkContext and before module work begins.
public function onActivate(): voidRuns when the module is activated.
public function onDeactivate(): voidRuns when the module is deactivated.
public function onUpgrade(string $previousVersion): voidRuns after an upgrade and receives the previous installed version.
public function onUninstall(): voidRuns 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();