Files
opensourcepos/app/Libraries/Plugins/PluginInterface.php
Ollama a9669ddf19 feat(plugins): Implement modular plugin system with self-registering events
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
2026-03-09 21:58:53 +01:00

96 lines
2.5 KiB
PHP

<?php
namespace App\Libraries\Plugins;
/**
* Plugin Interface
*
* All plugins must implement this interface to be discovered and loaded by the PluginManager.
* This ensures a standard contract for plugin lifecycle and event registration.
*/
interface PluginInterface
{
/**
* Get the unique identifier for this plugin.
* Should be lowercase with underscores, e.g., 'mailchimp_integration'
*/
public function getPluginId(): string;
/**
* Get the human-readable name of the plugin.
*/
public function getPluginName(): string;
/**
* Get the plugin description.
*/
public function getPluginDescription(): string;
/**
* Get the plugin version.
*/
public function getVersion(): string;
/**
* Register event listeners for this plugin.
*
* Use Events::on() to register callbacks for OSPOS events.
* This method is called when the plugin is loaded and enabled.
*
* Example:
* Events::on('item_sale', [$this, 'onItemSale']);
* Events::on('item_change', [$this, 'onItemChange']);
*/
public function registerEvents(): void;
/**
* Install the plugin.
*
* Called when the plugin is first enabled. Use this to:
* - Create database tables
* - Set default configuration values
* - Run any setup required
*
* @return bool True if installation succeeded
*/
public function install(): bool;
/**
* Uninstall the plugin.
*
* Called when the plugin is being removed. Use this to:
* - Remove database tables
* - Clean up configuration
*
* @return bool True if uninstallation succeeded
*/
public function uninstall(): bool;
/**
* Check if the plugin is enabled.
*/
public function isEnabled(): bool;
/**
* Get the path to the plugin's configuration view file.
* Returns null if the plugin has no configuration UI.
*
* Example: 'Plugins/mailchimp/config'
*/
public function getConfigView(): ?string;
/**
* Get plugin-specific settings for the configuration view.
*
* @return array Settings array to pass to the view
*/
public function getSettings(): array;
/**
* Save plugin settings from configuration form.
*
* @param array $settings The settings to save
* @return bool True if settings were saved successfully
*/
public function saveSettings(array $settings): bool;
}