InstallablePackageRecord - viames/pair GitHub Wiki
Pair framework: InstallablePackageRecord
Pair\Packages\InstallablePackageRecord is the abstract base for ActiveRecord models created from installable package manifests.
When to use
Use it when creating installable domain models that are tied to package manifests and version compatibility rules.
Main methods
isCompatibleWithApp(): boolisCompatibleWithAppMajorVersion(): bool- Abstract contract:
getPackageBaseFolder(): stringgetInstallablePackage(): InstallablePackagepackageRecordExists(string $name): boolstoreFromPackageManifest(SimpleXMLElement $options): bool
Implementation examples
Minimal implementation
final class CustomModule extends \Pair\Packages\InstallablePackageRecord {
/**
* Return the folder where this module package installs its files.
*/
public function getPackageBaseFolder(): string
{
return APPLICATION_PATH . '/modules/custom';
}
/**
* Build the installer object for this package record.
*/
public function getInstallablePackage(): \Pair\Packages\InstallablePackage
{
return new \Pair\Packages\InstallablePackage();
}
/**
* Check whether a package record with this name already exists.
*/
public static function packageRecordExists(string $name): bool
{
return false;
}
/**
* Store package-specific values read from manifest options.
*/
public function storeFromPackageManifest(\SimpleXMLElement $options): bool
{
return $this->store();
}
}
Compatibility gate
$module = \Pair\Models\Module::find($id);
if ($module && !$module->isCompatibleWithApp()) {
throw new \RuntimeException('Package is not compatible with this app version');
}
Common pitfalls
- Skipping compatibility checks before enabling a package.
- Mixing package filesystem concerns with controller logic.
See also: InstallablePackage, Module.