Files
opensourcepos/app/Libraries/Plugins/BasePlugin.php
objec 4246a915c4 - Correct README.md reference to views and information about renderView()
- Fix the output of pluginContent in the pluginHelper
- Register view injection events
- Correct the parameter type in getMailchimpViewData
- Correct the statusOptions creation business logic
- Removed unnecessary view injection point
- Corrected which variable was passed to the customer_saved event
- Assigned $customer_data['person_id'] on customer update
- Added renderView() function to BasePlugin.php

Signed-off-by: objec <objecttothis@gmail.com>
2026-04-30 14:11:54 +04:00

77 lines
2.1 KiB
PHP

<?php
namespace App\Libraries\Plugins;
use App\Models\PluginConfig;
abstract class BasePlugin implements PluginInterface
{
protected PluginConfig $configModel;
public function __construct()
{
$this->configModel = new PluginConfig();
}
public function install(): bool
{
return true;
}
public function uninstall(): bool
{
return true;
}
public function isEnabled(): bool
{
$enabled = $this->configModel->getValue("{$this->getPluginId()}__enabled");
return $enabled === '1' || $enabled === 'true';
}
protected function getSetting(string $key, mixed $default = null): mixed
{
$value = $this->configModel->getValue("{$this->getPluginId()}_{$key}");
return $value ?? $default;
}
protected function setSetting(string $key, mixed $value): bool
{
$stringValue = is_array($value) || is_object($value)
? json_encode($value)
: (string)$value;
return $this->configModel->setValue("{$this->getPluginId()}_{$key}", $stringValue);
}
public function getSettings(): array
{
return $this->configModel->getPluginSettings($this->getPluginId());
}
public function saveSettings(array $settings): bool
{
$prefixedSettings = [];
foreach ($settings as $key => $value) {
if (is_array($value) || is_object($value)) {
$prefixedSettings["{$this->getPluginId()}_{$key}"] = json_encode($value);
} else {
$prefixedSettings["{$this->getPluginId()}_{$key}"] = (string)$value;
}
}
return $this->configModel->batchSave($prefixedSettings);
}
protected function log(string $level, string $message): void
{
log_message($level, "[Plugin:{$this->getPluginName()}] {$message}");
}
protected function renderView(string $viewName, array $data = []): string
{
$namespace = substr(get_class($this), 0, strrpos(get_class($this), '\\'));
return view($namespace . '\\Views\\' . $viewName, $data);
}
}