mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Consolidate handlePageAction in plugin class, remove functions.php from plugin
This commit is contained in:
parent
7d4e6c1eaa
commit
04a6d007fd
@ -1033,10 +1033,3 @@ function renderStatus($hostapd_led, $hostapd_status, $memused_led, $memused, $cp
|
||||
<?php
|
||||
}
|
||||
|
||||
// Returns a classname without its associated namespace
|
||||
function getClassName($class)
|
||||
{
|
||||
if ($pos = strrpos($class, '\\')) return substr($class, $pos + 1);
|
||||
return $pos;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
*
|
||||
* @description Architecture to support user plugins for RaspAP
|
||||
* @author Bill Zimmerman <billzimmerman@gmail.com>
|
||||
* Special thanks to GitHub user @assachs
|
||||
* @license https://github.com/raspap/raspap-webgui/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@ -91,34 +92,18 @@ class PluginManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over each registered plugin and calls its associated method
|
||||
* Iterates over registered plugins and calls its associated method
|
||||
* @param string $page
|
||||
* @return boolean
|
||||
*/
|
||||
public function handlePageAction(string $page) {
|
||||
public function handlePageAction(string $page): bool {
|
||||
foreach ($this->getInstalledPlugins() as $pluginClass) {
|
||||
$pluginName = (new \ReflectionClass($pluginClass))->getShortName();
|
||||
$plugin = new $pluginClass($this->pluginPath, $pluginName);
|
||||
$plugin = new $pluginClass($this->pluginPath, $pluginClass);
|
||||
|
||||
if ($plugin instanceof PluginInterface) {
|
||||
// check if the page matches this plugin's action
|
||||
if (strpos($page, "/plugin__{$plugin->getName()}") === 0) {
|
||||
$functions = "{$this->pluginPath}/{$plugin->getName()}/functions.php";
|
||||
|
||||
if (file_exists($functions)) {
|
||||
require_once $functions;
|
||||
|
||||
// define the namespaced function
|
||||
$function = '\\' . $plugin->getName() . '\\handlePageAction';
|
||||
|
||||
// call the function if it exists, passing the page and PluginManager instance
|
||||
if (function_exists($function)) {
|
||||
$function($page, $this, $pluginName);
|
||||
if ($plugin->handlePageAction($page, $this)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
throw new \Exception("Functions file not found for plugin: {$plugin->getName()}");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user