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) |
||
72 | |||
73 | /** |
||
74 | * init() is called once/if __construct has a module object. |
||
75 | * $this->module will have a module object that any further |
||
76 | * initialization can use. |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | abstract public function init(); |
||
81 | |||
82 | /** |
||
83 | * Set debug option on or off |
||
84 | * |
||
85 | * @param bool $bool true to turn on debug logging, false for off |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | 1 | public function setDebug($bool = true) |
|
93 | |||
94 | /** |
||
95 | * Add a message to the module log |
||
96 | * |
||
97 | * @param string $log log message |
||
98 | * |
||
99 | * @return void |
||
100 | */ |
||
101 | 1 | public function addLog($log) |
|
107 | } |
||
108 |
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: