6 * This mock module enable class encapsulation of legacy global function modules.
7 * After having provided the module file name, all the methods will behave like a normal Module class.
9 * @author Hypolite Petovan <mrpetovan@gmail.com>
11 class LegacyModule extends BaseModule
14 * The module name, which is the name of the file (without the .php suffix)
15 * It's used to check for existence of the module functions.
19 private static $moduleName = '';
22 * The only method that needs to be called, with the module/addon file name.
24 * @param string $file_path
26 public static function setModuleFile($file_path)
28 if (!is_readable($file_path)) {
29 throw new Exception(Core\L10n::t('Legacy module file not found: %s', $file_path));
32 self::$moduleName = basename($file_path, '.php');
34 require_once $file_path;
37 public static function init()
39 self::runModuleFunction('init');
42 public static function content()
44 return self::runModuleFunction('content');
47 public static function post()
49 self::runModuleFunction('post');
52 public static function afterpost()
54 self::runModuleFunction('afterpost');
58 * Runs the module function designated by the provided suffix if it exists, the BaseModule method otherwise
60 * @param string $function_suffix
63 private static function runModuleFunction($function_suffix)
65 $function_name = static::$moduleName . '_' . $function_suffix;
67 if (\function_exists($function_name)) {
69 return $function_name($a);
71 return parent::{$function_suffix}();