PHPackages                             echo-fusion/pluginmanager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. echo-fusion/pluginmanager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

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.

v1.0.0(1y ago)119MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0

Since Oct 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/echo-fusion/pluginmanager)[ Packagist](https://packagist.org/packages/echo-fusion/pluginmanager)[ RSS](/packages/echo-fusion-pluginmanager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

PluginManager
=============

[](#pluginmanager)

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
------------

[](#installation)

Install the package via Composer:

```
composer require echo-fusion/pluginmanager
```

Requirements
------------

[](#requirements)

The following versions of PHP are supported by this version.

- PHP 8.1
- PHP 8.2
- PHP 8.3

Usage
-----

[](#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);
}
```

2. 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();
}
```

3. Ensure that your plugins implement the PluginInterface:

```
