yohns/plugable

插件、钩子和过滤器,可添加到您的网站,以便在网站加载时在设定的时间注入不同的功能。

维护者

详细信息

github.com/Yohn/Plugable

源代码

问题

安装: 1

依赖: 0

建议者: 0

安全: 0

星级: 0

关注者: 1

分支: 0

开放问题: 0

类型:项目

0.1.0 2024-08-18 00:23 UTC

This package is auto-updated.

Last update: 2024-09-18 00:38:14 UTC


README

<?php
use Yohns\Core\Plugable;

// Define the plugin directory
$pluginDir = __DIR__.'/pluggable/plugins/';

// Define the plugins to load
$plugins = ['Events', 'News', 'Pictures'];

// Load the plugins with the directory variable
$loadedPlugins = Plugable::loadPlugins($plugins, $pluginDir);

echo "<pre>Loaded Plugins:\n";
print_r($loadedPlugins);
echo "</pre>";

// Add hooks
Plugable::addHook('startup', function() {
	echo "Startup hook executed!<br>";
});

Plugable::addHook('shutdown', function() {
	echo "Shutdown hook executed!<br>";
});

// Execute the 'startup' event hooks
Plugable::doHook('startup');

// Add a filter
Plugable::addFilter('content_filter', ['content' => 'Original content']);

// Execute the filter for 'content_filter'
$result = Plugable::doFilter('content_filter', function(array $data) {
	// Modify the filtered data
	$data[0]['content'] = 'Filtered content';
	return $data;
});

echo "<pre>Filtered Data:\n";
print_r($result);
echo "</pre>";

// Execute the 'shutdown' event hooks
Plugable::doHook('shutdown');
//--   loading plugins
foreach ($loadedPlugins as $k => $v) {
	if ($v['IncludeFiles'] != '') {
		if (is_array($v['IncludeFiles'])) {
			foreach ($v['IncludeFiles'] as $fi) {
				if (is_file($pluginDir . $k . '/' . $fi)) {
					include ($pluginDir . $k . '/' . $fi);
				} else {
					die($pluginDir . $k . '/' . $fi . ' file was not found');
				}
			}
		}
	}
	if ($v['Route'] != '') {
		$Routes[] = $v['Route'];
	}
}