protected-resources-list/classes/Plugin.php

42 lines
909 B
PHP

<?php
abstract class Plugin implements IPluggable
{
protected PluginContext $context;
protected array $config;
public function onServerStarted()
{
}
public function onSync()
{
}
public function onInit(PluginContext $context): void
{
$this->context = $context;
$this->checkConfig();
$this->config = $this->context->getConfig()[$context->getName()];
}
protected function checkConfig(): void
{
$config = $this->context->getConfig();
$defaults = $this->context->getMetadata()["config"];
$name = $this->context->getName();
if (!isset($config[$name])) {
$config[$name] = $defaults;
return;
}
foreach ($defaults as $key => $value) {
if (!isset($config[$name][$key])) {
$config[$name][$key] = $value;
}
}
}
}