PHP code example of hongyukeji / plugin

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

    

hongyukeji / plugin example snippets




use \Hongyukeji\Plugin\Hook as Hook;
use \Hongyukeji\Plugin\Event as Event;

// define an Event
Event::forge('triggerOnThis')->setCall(function($result){
	$result->set(123);
})->priority(2);

// the Hook triggers it
$result = Hook::forge('triggerOnThis')->execute();

// echoes 123
echo $result->get();



// define an Event
Event::forge('triggerOnThis')->setCall(function($result){
	$increment = $result->getParam('increment')
	$increment++;
	$result->setParam($increment);
	$result->set($increment);
});

// define another Event editing the parameters with lower priority (lower number is higher priority, default is 5)
Event::forge('triggerOnThis')->setCall(function($result){
	$increment = $result->getParam('increment')
	$increment++;
	$result->set($increment);
})->priority(8);

// the Hook triggers it
$result = Hook::forge('triggerOnThis')
	->setParam('increment', 0)
	->execute();

// echoes 2 (we increased the number in each event)
echo $result->get();

// echoes 1 (we edited the parameter only in the first event)
echo $result->getParam('increment');



$loader = Loader::forge()->setDir('main', '/path/to/plugins/');

$enabled_plugins = array('hongyukeji/fake', 'hongyukeji/kynet');

foreach ($loader->getPlugins('main') as $plugin)
{
	if (in_array($plugin->getConfig('name'), $enabled_plugins))
	{
		$plugin->execute();
	}
}

php artisan vendor:publish --provider="Hongyukeji\Plugin\PluginServiceProvider"