承接 echo-fusion/pluginmanager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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:

  1. 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);
}
  1. 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();
}
  1. 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
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固