PHP code example of power-modules / plugin

1. Go to this page and download the library: Download power-modules/plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

power-modules / plugin example snippets


use Modular\Framework\Container\ConfigurableContainerInterface;
use Modular\Framework\PowerModule\Contract\PowerModule;
use Modular\Plugin\Contract\Plugin;
use Modular\Plugin\Contract\PluginRegistry;
use Modular\Plugin\Contract\ProvidesPlugins;
use Modular\Plugin\PluginMetadata;

// 1. Define a plugin
final class MyPlugin implements Plugin
{
    public static function getPluginMetadata(): PluginMetadata
    {
        return new PluginMetadata('My Plugin', '1.0.0', 'Example plugin');
    }
}

// 2. Provide it from a module
final class MyModule implements PowerModule, ProvidesPlugins
{
    public static function getPlugins(): array
    {
        return [PluginRegistry::class => [MyPlugin::class]];
    }

    public function register(ConfigurableContainerInterface $container): void
    {
        $container->set(MyPlugin::class, MyPlugin::class);
    }
}

// 3. The application automatically discovers and registers it
$app = (new ModularAppBuilder(__DIR__))
    ->withPowerSetup(...PluginRegistrySetup::withDefaults())
    ->withModules(MyModule::class)
    ->build();

// 4. Use it
/** @var PluginRegistry<MyPlugin> $registry */
$registry = $app->get(PluginRegistry::class);
$plugin = $registry->makePlugin(MyPlugin::class);