PHP code example of bethropolis / plugin-system

1. Go to this page and download the library: Download bethropolis/plugin-system 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/ */

    

bethropolis / plugin-system example snippets


composer 





use Bethropolis\PluginSystem\System;

$dir = __DIR__ . "/examples/"; # directory to load plugins from
System::loadPlugins($dir);


use Bethropolis\PluginSystem\System;

// Link a plugin function to a hook
System::linkPluginToHook('my_hook', $callback);

use Bethropolis\PluginSystem\System;

// Trigger a hook
System::executeHook('my_hook', $pluginName, ...$args);

// trigger multiple hooks
System::executeHooks(['my_hook1', 'my_hook2'], $pluginName, ...$args);

# Events
// Register an event
System::registerEvent('my_event');

// Add an action to the event
System::addAction('my_event', function ($arg) {
    // Action code here
});

// Trigger the event
System::triggerEvent('my_event', ...$args);


// eg. FILE: /plugins-folder/examplepugin.php

class ExamplePlugin extends \Bethropolis\PluginSystem\Plugin
{

    public function initialize()
    {
        $this->linkHook('my_hook', array($this, 'myCallback'));
    }



    public function myCallback($name = [])
    {
        $name = array_shift($name);
        return "hello {$name}";
    }
}