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
27 public static function setModuleFile($file_path)
29 if (!is_readable($file_path)) {
30 throw new \Exception(Core\L10n::t('Legacy module file not found: %s', $file_path));
33 self::$moduleName = basename($file_path, '.php');
35 require_once $file_path;
38 public static function init()
40 self::runModuleFunction('init');
43 public static function content()
45 return self::runModuleFunction('content');
48 public static function post()
50 self::runModuleFunction('post');
53 public static function afterpost()
55 self::runModuleFunction('afterpost');
59 * Runs the module function designated by the provided suffix if it exists, the BaseModule method otherwise
61 * @param string $function_suffix
65 private static function runModuleFunction($function_suffix)
67 $function_name = static::$moduleName . '_' . $function_suffix;
69 if (\function_exists($function_name)) {
71 return $function_name($a);
73 return parent::{$function_suffix}();