1 | <?php |
||
28 | abstract class AbstractHelper |
||
29 | { |
||
30 | /** |
||
31 | * @var XoopsModule |
||
32 | */ |
||
33 | protected $module; |
||
34 | |||
35 | /** |
||
36 | * @var bool true if debug is enabled |
||
37 | */ |
||
38 | protected $debug; |
||
39 | |||
40 | /** |
||
41 | * Instantiate a XoopsModule object for the helper to use. |
||
42 | * The module is determined as follows: |
||
43 | * - if null is passed, use the current module |
||
44 | * - if a string is passed, use as dirname to load |
||
45 | * |
||
46 | * @param string|null $dirname dirname |
||
47 | */ |
||
48 | public function __construct($dirname = null) |
||
77 | |||
78 | /** |
||
79 | * init() is called once/if __construct has a module object. |
||
80 | * $this->module will have a module object that any further |
||
81 | * initialization can use. |
||
82 | * |
||
83 | * @return void |
||
84 | */ |
||
85 | abstract public function init(); |
||
86 | |||
87 | /** |
||
88 | * Set debug option on or off |
||
89 | * |
||
90 | * @param bool $bool true to turn on debug logging, false for off |
||
91 | * |
||
92 | * @return void |
||
93 | */ |
||
94 | 1 | public function setDebug($bool = true) |
|
98 | |||
99 | /** |
||
100 | * Add a message to the module log |
||
101 | * |
||
102 | * @param string $log log message |
||
103 | * |
||
104 | * @return void |
||
105 | */ |
||
106 | 1 | public function addLog($log) |
|
112 | } |
||
113 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: