echo-fusion/pluginmanager
最新稳定版本:v1.0.0
Composer 安装命令:
composer require echo-fusion/pluginmanager
包简介
A flexible PHP package for managing and integrating plugins, allowing dynamic loading and registration based on application environments. Enhance the modularity and extensibility of your applications with ease.
关键字:
README 文档
README
The PluginManager is a versatile package for managing and integrating plugins into your PHP applications. It allows you to dynamically load and register plugins based on the environment, making your application modular and extensible.
Installation
Install the package via Composer:
composer require echo-fusion/pluginmanager
Requirements
The following versions of PHP are supported by this version.
- PHP 8.1
- PHP 8.2
- PHP 8.3
Usage
Here’s how to use the PluginManager to set up and run:
- Instantiate the PluginManager with an array of plugins, specifying the environments in which they should be loaded:
use EchoFusion\PluginManager\PluginManager; use Psr\Container\ContainerInterface; $createPluginManager = function(ContainerInterface $container) { $plugins = [ MyPlugin::class, AnotherPlugin::class, ]; return new PluginManager($container, $plugins); }
- Register the plugins based on the current environment:
// Usage $container = // Your container implementation here $pluginManager = $createPluginManager($container); try { // Register plugins for a specific environment (e.g., 'dev') $pluginManager->register('dev'); } catch (PluginManagerException $e) { // Handle any exceptions related to plugin management echo 'Error registering plugins: ' . $e->getMessage(); } catch (Throwable $e) { // General fallback for other types of exceptions echo 'An unexpected error occurred: ' . $e->getMessage(); }
- Ensure that your plugins implement the PluginInterface:
<?php declare(strict_types=1); namespace YourNamespace\Plugins; use EchoFusion\PluginManager\PluginInterface; use EchoFusion\PluginManager\Environment; class ExamplePlugin implements PluginInterface { private $service; public function register(): void { // Initialize the service $this->service = $this->initializeService(); // Set up configurations $this->configureSettings(); // Register event listeners $this->registerEventListeners(); echo "ExamplePlugin has been registered successfully.\n"; } public function getSupportedEnvironments(): array { return ['dev','prod']; } //... }
Testing
Testing includes PHPUnit and PHPStan (Level 7).
$ composer test
Credits
Developed and maintained by Amir Shadanfar.
Connect on LinkedIn.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-17