mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-02 06:14:51 -04:00
This implements a clean plugin architecture based on PR #4255 discussion: Core Components: - PluginInterface: Standard contract all plugins must implement - BasePlugin: Abstract class with common functionality - PluginManager: Discovers and loads plugins from app/Plugins/ - Plugin_config: Model for plugin settings storage Architecture: - Each plugin registers its own event listeners via registerEvents() - No hardcoded plugin dependencies in core Events.php - Generic event triggers (item_sale, item_change, etc.) remain in core code - Plugins can be enabled/disabled via database settings - Clean separation: plugin orchestrators vs MVC components Example Implementations: - ExamplePlugin: Simple plugin demonstrating event logging - MailchimpPlugin: Integration with Mailchimp for customer sync Admin UI: - Plugin management controller at Controllers/Plugins/Manage.php - Plugin management view at Views/plugins/manage.php Database: - ospos_plugin_config table for plugin settings (key-value store) - Migration creates table with timestamps Documentation: - Comprehensive README with architecture patterns - Simple vs complex plugin examples - MVC directory structure guidance
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Config;
|
|
|
|
use CodeIgniter\Events\Events;
|
|
use CodeIgniter\Exceptions\FrameworkException;
|
|
use CodeIgniter\HotReloader\HotReloader;
|
|
use App\Events\Db_log;
|
|
use App\Events\Load_config;
|
|
use App\Events\Method;
|
|
use App\Libraries\Plugins\PluginManager;
|
|
|
|
Events::on('pre_system', static function (): void {
|
|
if (ENVIRONMENT !== 'testing') {
|
|
if (ini_get('zlib.output_compression')) {
|
|
throw FrameworkException::forEnabledZlibOutputCompression();
|
|
}
|
|
|
|
while (ob_get_level() > 0) {
|
|
ob_end_flush();
|
|
}
|
|
|
|
ob_start(static fn ($buffer) => $buffer);
|
|
}
|
|
|
|
if (CI_DEBUG && ! is_cli()) {
|
|
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
|
|
service('toolbar')->respond();
|
|
if (ENVIRONMENT === 'development') {
|
|
service('routes')->get('__hot-reload', static function (): void {
|
|
(new HotReloader())->run();
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
$config = new Load_config();
|
|
Events::on('post_controller_constructor', [$config, 'load_config']);
|
|
|
|
$db_log = new Db_log();
|
|
Events::on('DBQuery', [$db_log, 'db_log_queries']);
|
|
|
|
$method = new Method();
|
|
Events::on('pre_controller', [$method, 'validate_method']);
|
|
|
|
Events::on('post_system', static function (): void {
|
|
$pluginManager = new PluginManager();
|
|
$pluginManager->discoverPlugins();
|
|
$pluginManager->registerPluginEvents();
|
|
}); |