. // }}} /** * Module and plugin loader code, one of the main features of GNU social * * Loads plugins from `plugins/enabled`, instances them * and hooks its events * * @package GNUsocial * @category Modules * * @author Hugo Sales * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace App\Core; use Functional as F; use GSEvent as Event; abstract class ModulesManager { public static array $modules = []; public static function loadModules() { $plugins_paths = glob(INSTALLDIR . '/plugins/*'); foreach ($plugins_paths as $plugin_path) { $class_name = basename($plugin_path); $qualified = 'Plugin\\' . $class_name . '\\' . $class_name; require_once $plugin_path . '/' . $class_name . '.php'; $class = new $qualified; self::$modules[] = $class; // Register event handlers $methods = get_class_methods($class); $events = F\select($methods, F\partial_right('App\Util\Formatting::startsWith', 'on')); F\map($events, function (string $m) use ($class) { Event::addHandler(substr($m, 2), [$class, $m]); }); } } }