<?php
namespace Lia;
class Addon {
/**
* Fully qualified name for accessing this addon
*/
public string $fqn;
/**
* The short name of this addon
*/
public string $name;
/** Package */
public ?\Lia\Package $package;
public ?\Lia $lia;
public function __construct(?\Lia\Package $package=null){
$this->package = $package;
$this->lia = $package->lia ?? null;
if (!isset($this->name)){
$addon_name = strtolower(get_class($this));
$pos = strrpos($addon_name, '\\');
if ($pos!==false)$pos +=1;
$this->name = substr($addon_name, $pos);
}
if ($this->fqn==null){
throw new \Exception("Every addon must declare `public string \$fqn = 'fqn'`, where fqn should be like `vendor:package.addon_name`\n\n");
}
if ($package!=null){
$this->lia->addons[$this->name] = $this;
$this->lia->fqn_addons[$this->fqn] = $this;
$package->addons[$this->name] = $this;
}
}
/** to setup global methods, prefixes, or anything else on liaison */
public function init_lia(){}
/**
* When the package has been fully loaded
*/
public function onPackageReady(){}
// public function onWillCreate(){}
// public function onDidCreate(){}
// public function __call($method, $args){
// return $this->lia->methods[$method](...$args);
// }
}