[MODULES] Add function to defer module initialization and cleanup to plugin and component. Add example in Avatar component
Forward onInitializeModule to onInitializePlugin if the component is a plugin
This commit is contained in:
parent
bda839be7b
commit
033c4db914
|
@ -32,6 +32,10 @@ use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class Avatar extends Component
|
class Avatar extends Component
|
||||||
{
|
{
|
||||||
|
public function onInitializeComponent()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function onAddRoute($r): bool
|
public function onAddRoute($r): bool
|
||||||
{
|
{
|
||||||
$r->connect('avatar', '/{gsactor_id<\d+>}/avatar/{size<full|big|medium|small>?full}', [Controller\Avatar::class, 'avatar_view']);
|
$r->connect('avatar', '/{gsactor_id<\d+>}/avatar/{size<full|big|medium|small>?full}', [Controller\Avatar::class, 'avatar_view']);
|
||||||
|
|
|
@ -60,4 +60,25 @@ abstract class Module
|
||||||
}
|
}
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------- Module initialize and cleanup ----------
|
||||||
|
|
||||||
|
private function defer(string $cycle)
|
||||||
|
{
|
||||||
|
$type = ucfirst(static::MODULE_TYPE);
|
||||||
|
if (method_exists($this, $method = "on{$cycle}{$type}")) {
|
||||||
|
$this->{$method}();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Can't use __call or it won't be found by our event function finder
|
||||||
|
public function onInitializeModule()
|
||||||
|
{
|
||||||
|
$this->defer('Initialize');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onCleanupModule()
|
||||||
|
{
|
||||||
|
$this->defer('Cleanup');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user