Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Xoops often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Xoops, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
33 | class Xoops |
||
34 | { |
||
35 | const VERSION = 'XOOPS 2.6.0-Alpha 3'; |
||
36 | |||
37 | /** |
||
38 | * @var null|Xoops\Core\Session\Manager |
||
39 | */ |
||
40 | public $sessionManager = null; |
||
41 | |||
42 | /** |
||
43 | * @var null|XoopsModule |
||
44 | */ |
||
45 | public $module = null; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | public $config = array(); |
||
51 | |||
52 | /** |
||
53 | * @var array |
||
54 | */ |
||
55 | public $moduleConfig = array(); |
||
56 | |||
57 | /** |
||
58 | * @var array |
||
59 | */ |
||
60 | public $moduleDirname = ''; |
||
61 | |||
62 | /** |
||
63 | * @var XoopsUser|string |
||
64 | */ |
||
65 | public $user = ''; |
||
66 | |||
67 | /** |
||
68 | * @var bool |
||
69 | */ |
||
70 | public $userIsAdmin = false; |
||
71 | |||
72 | /** |
||
73 | * @var array |
||
74 | */ |
||
75 | public $option = array(); |
||
76 | |||
77 | /** |
||
78 | * @var XoopsTpl|null |
||
79 | */ |
||
80 | private $tpl = null; |
||
81 | |||
82 | /** |
||
83 | * @var XoopsTheme|null |
||
84 | */ |
||
85 | private $theme = null; |
||
86 | |||
87 | /** |
||
88 | * @var array |
||
89 | */ |
||
90 | public $paths = array( |
||
91 | 'XOOPS' => array(), 'www' => array(), 'var' => array(), 'lib' => array(), 'modules' => array(), |
||
92 | 'themes' => array(), 'media' => array() |
||
93 | ); |
||
94 | |||
95 | /** |
||
96 | * @var string |
||
97 | */ |
||
98 | public $tpl_name = ''; |
||
99 | |||
100 | /** |
||
101 | * @var HandlerFactory |
||
102 | */ |
||
103 | private $handlerFactory; |
||
104 | |||
105 | /** |
||
106 | * @var array |
||
107 | */ |
||
108 | private $kernelHandlers = array(); |
||
109 | |||
110 | /** |
||
111 | * @var array |
||
112 | */ |
||
113 | private $moduleHandlers = array(); |
||
114 | |||
115 | /** |
||
116 | * @var null|array |
||
117 | */ |
||
118 | private $activeModules = null; |
||
119 | |||
120 | /** |
||
121 | * @var array |
||
122 | */ |
||
123 | private $moduleConfigs = array(); |
||
124 | |||
125 | /** |
||
126 | * @var bool |
||
127 | */ |
||
128 | public $isAdminSide = false; |
||
129 | |||
130 | /** |
||
131 | * Actual Xoops OS |
||
132 | */ |
||
133 | private function __construct() |
||
156 | |||
157 | /** |
||
158 | * Access the only instance of this class |
||
159 | * |
||
160 | * @return Xoops |
||
161 | */ |
||
162 | 385 | public static function getInstance() |
|
171 | |||
172 | /** |
||
173 | * get database connection instance |
||
174 | * |
||
175 | * @return Xoops\Core\Database\Connection |
||
176 | */ |
||
177 | 138 | public function db() |
|
181 | |||
182 | /** |
||
183 | * get a \Xoops\Core\Cache\Access object for a named cache |
||
184 | * |
||
185 | * @param string $cacheName a named cached pool |
||
186 | * |
||
187 | * @return \Xoops\Core\Cache\Access |
||
188 | */ |
||
189 | 25 | public function cache($cacheName = 'default') |
|
199 | |||
200 | /** |
||
201 | * get the system logger instance |
||
202 | * |
||
203 | * @return \Xoops\Core\Logger |
||
204 | */ |
||
205 | 17 | public function logger() |
|
209 | |||
210 | |||
211 | /** |
||
212 | * get the event processor |
||
213 | * |
||
214 | * @return \Xoops\Core\Events instance |
||
215 | */ |
||
216 | 129 | public function events() |
|
220 | |||
221 | /** |
||
222 | * Deprecated - use events() instead |
||
223 | * |
||
224 | * @return XoopsPreload |
||
225 | */ |
||
226 | 16 | public function preload() |
|
230 | |||
231 | /** |
||
232 | * get the asset utility |
||
233 | * |
||
234 | * @return Xoops\Core\Assets instance |
||
235 | */ |
||
236 | 4 | public function assets() |
|
244 | |||
245 | /** |
||
246 | * get the service manager |
||
247 | * |
||
248 | * @param string $service - service name |
||
249 | * |
||
250 | * @return Xoops\Core\Service\Provider instance |
||
251 | */ |
||
252 | 4 | public function service($service) |
|
260 | |||
261 | /** |
||
262 | * provide a common registry instance |
||
263 | * |
||
264 | * @return Xoops\Core\Registry |
||
265 | */ |
||
266 | 4 | public function registry() |
|
274 | |||
275 | /** |
||
276 | * get security instance |
||
277 | * |
||
278 | * @return XoopsSecurity |
||
279 | */ |
||
280 | 4 | public function security() |
|
288 | |||
289 | /** |
||
290 | * get current template engine |
||
291 | * |
||
292 | * @return null|XoopsTpl |
||
293 | */ |
||
294 | 9 | public function tpl() |
|
298 | |||
299 | /** |
||
300 | * set current template engine |
||
301 | * |
||
302 | * @param XoopsTpl $tpl template engine |
||
303 | * |
||
304 | * @return XoopsTpl |
||
305 | */ |
||
306 | 6 | public function setTpl(XoopsTpl $tpl) |
|
310 | |||
311 | /** |
||
312 | * establish the theme |
||
313 | * |
||
314 | * @param null|string $tpl_name base template |
||
315 | * |
||
316 | * @return null|XoopsTheme |
||
317 | */ |
||
318 | 6 | public function theme($tpl_name = null) |
|
360 | |||
361 | /** |
||
362 | * set theme |
||
363 | * |
||
364 | * @param XoopsTheme $theme theme |
||
365 | * |
||
366 | * @return XoopsTheme |
||
367 | */ |
||
368 | 4 | public function setTheme(XoopsTheme $theme) |
|
372 | |||
373 | /** |
||
374 | * Convert a XOOPS path to a physical one |
||
375 | * |
||
376 | * @param string $url url to derive path from |
||
377 | * @param bool $virtual virtual |
||
378 | * |
||
379 | * @return string |
||
380 | */ |
||
381 | 31 | public function path($url, $virtual = false) |
|
402 | |||
403 | /** |
||
404 | * Convert path separators to unix style |
||
405 | * |
||
406 | * @param string $path path to normalize |
||
407 | * |
||
408 | * @return string normalized path |
||
409 | */ |
||
410 | 31 | public function normalizePath($path) |
|
414 | |||
415 | /** |
||
416 | * Convert a XOOPS path to an URL |
||
417 | * |
||
418 | * @param string $url path (or url) |
||
419 | * |
||
420 | * @return string |
||
421 | */ |
||
422 | 5 | public function url($url) |
|
426 | |||
427 | /** |
||
428 | * Build an URL with the specified request params |
||
429 | * |
||
430 | * @param string $url base url |
||
431 | * @param array $params parameters to add to the url |
||
432 | * |
||
433 | * @return string |
||
434 | */ |
||
435 | 1 | public function buildUrl($url, $params = array()) |
|
454 | |||
455 | /** |
||
456 | * Check if a path exists |
||
457 | * |
||
458 | * @param string $path filesystem path |
||
459 | * @param string $error_type error level i.e. Psr\Log\LogLevel |
||
460 | * |
||
461 | * @return string|false |
||
462 | */ |
||
463 | 2 | public function pathExists($path, $error_type) |
|
478 | |||
479 | /** |
||
480 | * Start gzipCompression output buffer |
||
481 | * |
||
482 | * @return void |
||
483 | */ |
||
484 | 1 | public function gzipCompression() |
|
503 | |||
504 | /** |
||
505 | * Translate a path |
||
506 | * |
||
507 | * @return void |
||
508 | */ |
||
509 | 1 | public function pathTranslation() |
|
535 | |||
536 | /** |
||
537 | * Select Theme |
||
538 | * |
||
539 | * @return void |
||
540 | */ |
||
541 | 1 | public function themeSelect() |
|
555 | |||
556 | /** |
||
557 | * Gets module, type and file from a tpl name |
||
558 | * |
||
559 | * @param string $tpl_name in form type:module/filename.tpl |
||
560 | * |
||
561 | * @return array|false associative array of 'tpl_name', 'type', 'module', 'file' |
||
562 | * or false on error |
||
563 | */ |
||
564 | 9 | public function getTplInfo($tpl_name) |
|
606 | |||
607 | /** |
||
608 | * Render Header |
||
609 | * |
||
610 | * @param string|null $tpl_name template name |
||
611 | * |
||
612 | * @return null|boolean |
||
613 | */ |
||
614 | public function header($tpl_name = null) |
||
677 | |||
678 | /** |
||
679 | * Render Footer |
||
680 | * |
||
681 | * @return false|null |
||
682 | */ |
||
683 | public function footer() |
||
710 | |||
711 | /** |
||
712 | * Check if a module is set |
||
713 | * |
||
714 | * @return bool |
||
715 | */ |
||
716 | 12 | public function isModule() |
|
720 | |||
721 | /** |
||
722 | * Check if a user is set |
||
723 | * |
||
724 | * @return bool |
||
725 | */ |
||
726 | 7 | public function isUser() |
|
730 | |||
731 | /** |
||
732 | * Check if user is admin |
||
733 | * |
||
734 | * @return bool |
||
735 | */ |
||
736 | 1 | public function isAdmin() |
|
740 | |||
741 | /** |
||
742 | * Get handler of Block |
||
743 | * |
||
744 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
745 | * |
||
746 | * @return \Xoops\Core\Kernel\Handlers\XoopsBlockHandler |
||
747 | */ |
||
748 | 4 | public function getHandlerBlock($optional = false) |
|
752 | |||
753 | /** |
||
754 | * Get handler of Block Module Link |
||
755 | * |
||
756 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
757 | * |
||
758 | * @return \Xoops\Core\Kernel\Handlers\XoopsBlockModuleLinkHandler |
||
759 | */ |
||
760 | 1 | public function getHandlerBlockModuleLink($optional = false) |
|
764 | |||
765 | /** |
||
766 | * Get handler of Config |
||
767 | * |
||
768 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
769 | * |
||
770 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigHandler |
||
771 | */ |
||
772 | 1 | public function getHandlerConfig($optional = false) |
|
776 | |||
777 | /** |
||
778 | * Get handler of Config Item |
||
779 | * |
||
780 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
781 | * |
||
782 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigItemHandler |
||
783 | */ |
||
784 | 18 | public function getHandlerConfigItem($optional = false) |
|
788 | |||
789 | /** |
||
790 | * Get handler of Config Option |
||
791 | * |
||
792 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
793 | * |
||
794 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigOptionHandler |
||
795 | */ |
||
796 | 18 | public function getHandlerConfigOption($optional = false) |
|
800 | |||
801 | /** |
||
802 | * Get handler of Group |
||
803 | * |
||
804 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
805 | * |
||
806 | * @return \Xoops\Core\Kernel\Handlers\XoopsGroupHandler |
||
807 | */ |
||
808 | 2 | public function getHandlerGroup($optional = false) |
|
812 | |||
813 | /** |
||
814 | * Get handler of Group Permission |
||
815 | * |
||
816 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
817 | * |
||
818 | * @return \Xoops\Core\Kernel\Handlers\XoopsGroupPermHandler |
||
819 | */ |
||
820 | 4 | public function getHandlerGroupPermission($optional = false) |
|
824 | |||
825 | /** |
||
826 | * Get handler of Member |
||
827 | * |
||
828 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
829 | * |
||
830 | * @return \Xoops\Core\Kernel\Handlers\XoopsMemberHandler |
||
831 | */ |
||
832 | 15 | public function getHandlerMember($optional = false) |
|
836 | |||
837 | /** |
||
838 | * Get handler of Membership |
||
839 | * |
||
840 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
841 | * |
||
842 | * @return \Xoops\Core\Kernel\Handlers\XoopsMembershipHandler |
||
843 | */ |
||
844 | 2 | public function getHandlerMembership($optional = false) |
|
848 | |||
849 | /** |
||
850 | * Get handler of Module |
||
851 | * |
||
852 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
853 | * |
||
854 | * @return \Xoops\Core\Kernel\Handlers\XoopsModuleHandler |
||
855 | */ |
||
856 | 10 | public function getHandlerModule($optional = false) |
|
860 | |||
861 | /** |
||
862 | * Get handler of Online |
||
863 | * |
||
864 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
865 | * |
||
866 | * @return \Xoops\Core\Kernel\Handlers\XoopsOnlineHandler |
||
867 | */ |
||
868 | 2 | public function getHandlerOnline($optional = false) |
|
872 | |||
873 | /** |
||
874 | * Get handler of Private Message |
||
875 | * |
||
876 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
877 | * |
||
878 | * @return \Xoops\Core\Kernel\Handlers\XoopsPrivateMessageHandler |
||
879 | */ |
||
880 | 1 | public function getHandlerPrivateMessage($optional = false) |
|
884 | |||
885 | /** |
||
886 | * Get the session manager |
||
887 | * |
||
888 | * @return Xoops\Core\Session\Manager |
||
889 | */ |
||
890 | 1 | public function session() |
|
897 | |||
898 | /** |
||
899 | * Get handler of Template File |
||
900 | * |
||
901 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
902 | * |
||
903 | * @return \Xoops\Core\Kernel\Handlers\XoopsTplFileHandler |
||
904 | */ |
||
905 | 2 | public function getHandlerTplFile($optional = false) |
|
909 | |||
910 | /** |
||
911 | * Get handler of Template Set |
||
912 | * |
||
913 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
914 | * |
||
915 | * @return \Xoops\Core\Kernel\Handlers\XoopsTplSetHandler |
||
916 | */ |
||
917 | 1 | public function getHandlerTplSet($optional = false) |
|
921 | |||
922 | /** |
||
923 | * Get handler of User |
||
924 | * |
||
925 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
926 | * |
||
927 | * @return \Xoops\Core\Kernel\Handlers\XoopsUserHandler |
||
928 | */ |
||
929 | 2 | public function getHandlerUser($optional = false) |
|
933 | |||
934 | /** |
||
935 | * Get handler |
||
936 | * |
||
937 | * @param string $name name of handler |
||
938 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
939 | * |
||
940 | * @return XoopsObjectHandler|XoopsPersistableObjectHandler|null |
||
941 | */ |
||
942 | 59 | protected function getHandler($name, $optional = false) |
|
960 | |||
961 | /** |
||
962 | * Get Module Handler |
||
963 | * |
||
964 | * @param string|null $name name of handler |
||
965 | * @param string|null $module_dir dirname of module |
||
966 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
967 | * |
||
968 | * @return XoopsObjectHandler|XoopsPersistableObjectHandler|bool |
||
969 | */ |
||
970 | 2 | public function getModuleHandler($name = null, $module_dir = null, $optional = false) |
|
999 | |||
1000 | /** |
||
1001 | * Get Module Form |
||
1002 | * |
||
1003 | * @param XoopsObject $obj object to populate form |
||
1004 | * @param string $name name of form |
||
1005 | * @param string $module_dir dirname of associated module |
||
1006 | * |
||
1007 | * @return Xoops\Form\Form|bool |
||
1008 | */ |
||
1009 | 1 | public function getModuleForm($obj, $name, $module_dir = null) |
|
1035 | |||
1036 | /** |
||
1037 | * Get Module Helper |
||
1038 | * |
||
1039 | * @param string $dirname dirname of module |
||
1040 | * |
||
1041 | * @return bool|Xoops\Module\Helper\HelperAbstract |
||
1042 | */ |
||
1043 | 1 | public static function getModuleHelper($dirname) |
|
1047 | |||
1048 | /** |
||
1049 | * XOOPS language loader wrapper |
||
1050 | * Temporary solution, not encouraged to use |
||
1051 | * |
||
1052 | * @param string $name Name of language file to be loaded, without extension |
||
1053 | * @param mixed $domain string: Module dirname; global language file will be loaded if |
||
1054 | * $domain is set to 'global' or not specified |
||
1055 | * array: example; array('Frameworks/moduleclasses/moduleadmin') |
||
1056 | * @param string $language Language to be loaded, current language content will be loaded if not specified |
||
1057 | * |
||
1058 | * @return boolean |
||
1059 | */ |
||
1060 | 7 | public function loadLanguage($name, $domain = '', $language = null) |
|
1083 | |||
1084 | /** |
||
1085 | * loadLocale |
||
1086 | * |
||
1087 | * @param string $domain Module dirname; global language file will be loaded if set to 'global' or not specified |
||
1088 | * @param string $locale Locale to be loaded, current language content will be loaded if not specified |
||
1089 | * |
||
1090 | * @return boolean |
||
1091 | */ |
||
1092 | 4 | public static function loadLocale($domain = null, $locale = null) |
|
1096 | |||
1097 | /** |
||
1098 | * Translate a key value |
||
1099 | * |
||
1100 | * @param string $key constant name |
||
1101 | * @param string $dirname dirname of module (domain) |
||
1102 | * |
||
1103 | * @return string |
||
1104 | */ |
||
1105 | 1 | public function translate($key, $dirname = 'xoops') |
|
1109 | |||
1110 | /** |
||
1111 | * Get active modules from cache file |
||
1112 | * |
||
1113 | * @return array |
||
1114 | */ |
||
1115 | 10 | public function getActiveModules() |
|
1130 | |||
1131 | /** |
||
1132 | * Write active modules to cache file |
||
1133 | * |
||
1134 | * @return array |
||
1135 | */ |
||
1136 | 1 | public function setActiveModules() |
|
1147 | |||
1148 | /** |
||
1149 | * Checks is module is installed and active |
||
1150 | * |
||
1151 | * @param string $dirname module directory |
||
1152 | * |
||
1153 | * @return bool |
||
1154 | */ |
||
1155 | 8 | public function isActiveModule($dirname) |
|
1162 | |||
1163 | /** |
||
1164 | * get module object from module name (dirname) |
||
1165 | * |
||
1166 | * @param string $dirname dirname of the module |
||
1167 | * |
||
1168 | * @return bool|XoopsModule |
||
1169 | */ |
||
1170 | 4 | View Code Duplication | public function getModuleByDirname($dirname) |
1179 | |||
1180 | /** |
||
1181 | * Get Module By Id |
||
1182 | * |
||
1183 | * @param int $id Id of the module |
||
1184 | * |
||
1185 | * @return bool|XoopsModule |
||
1186 | */ |
||
1187 | 1 | View Code Duplication | public function getModuleById($id) |
1196 | |||
1197 | /** |
||
1198 | * Render Simple Header |
||
1199 | * |
||
1200 | * @param bool $closehead true to close the HTML head element |
||
1201 | * |
||
1202 | * @return void |
||
1203 | */ |
||
1204 | 1 | public function simpleHeader($closehead = true) |
|
1252 | |||
1253 | /** |
||
1254 | * Render simpleFooter |
||
1255 | * |
||
1256 | * @return void |
||
1257 | */ |
||
1258 | 2 | public function simpleFooter() |
|
1264 | /** |
||
1265 | * render an alert message to a string |
||
1266 | * |
||
1267 | * @param string $type alert type, one of 'info', 'error', 'success' or 'warning' |
||
1268 | * @param mixed $msg string or array of strings |
||
1269 | * @param string $title title for alert |
||
1270 | * |
||
1271 | * @return string |
||
1272 | */ |
||
1273 | 1 | public function alert($type, $msg, $title = '/') |
|
1327 | |||
1328 | /** |
||
1329 | * Render a confirmation form to a string |
||
1330 | * |
||
1331 | * @param array $hiddens associative array of values used to complete confirmed action |
||
1332 | * @param string $action form action (URL) |
||
1333 | * @param string $msg message to display |
||
1334 | * @param string $submit submit button message |
||
1335 | * @param boolean $addtoken true to add CSRF token |
||
1336 | * |
||
1337 | * @return string rendered confirm message |
||
1338 | */ |
||
1339 | 1 | public function confirm($hiddens, $action, $msg, $submit = '', $addtoken = true) |
|
1365 | |||
1366 | /** |
||
1367 | * Get User Timestamp (kind of pointless, since timestamps are UTC?) |
||
1368 | * |
||
1369 | * @param \DateTime|int $time DateTime object or unix timestamp |
||
1370 | * |
||
1371 | * @return int unix timestamp |
||
1372 | */ |
||
1373 | 1 | public function getUserTimestamp($time) |
|
1378 | |||
1379 | /** |
||
1380 | * Function to calculate server timestamp from user entered time (timestamp) |
||
1381 | * |
||
1382 | * @param int $timestamp time stamp |
||
1383 | * @param null $userTZ timezone |
||
1384 | * |
||
1385 | * @return int |
||
1386 | */ |
||
1387 | 1 | public function userTimeToServerTime($timestamp, $userTZ = null) |
|
1395 | |||
1396 | /** |
||
1397 | * get the groups associated with the current user |
||
1398 | * |
||
1399 | * @return int[] |
||
1400 | */ |
||
1401 | 3 | public function getUserGroups() |
|
1407 | |||
1408 | /** |
||
1409 | * generate a temporary password |
||
1410 | * |
||
1411 | * @return string |
||
1412 | * |
||
1413 | * @todo make better passwords |
||
1414 | */ |
||
1415 | 1 | public function makePass() |
|
1435 | |||
1436 | /** |
||
1437 | * Check Email |
||
1438 | * |
||
1439 | * @param string $email check email |
||
1440 | * @param bool $antispam true if returned email should be have anti-SPAM measures applied |
||
1441 | * |
||
1442 | * @return false|string email address if valid, otherwise false |
||
1443 | */ |
||
1444 | 2 | public function checkEmail($email, $antispam = false) |
|
1455 | |||
1456 | /** |
||
1457 | * formatURL - add default http:// if no valid protocol specified |
||
1458 | * |
||
1459 | * @param string $url full or partial url |
||
1460 | * |
||
1461 | * @return string |
||
1462 | */ |
||
1463 | 1 | public function formatURL($url) |
|
1473 | |||
1474 | /** |
||
1475 | * Function to get banner html tags for use in templates |
||
1476 | * |
||
1477 | * @return string |
||
1478 | */ |
||
1479 | 3 | public function getBanner() |
|
1485 | |||
1486 | /** |
||
1487 | * Function to redirect a user to certain pages |
||
1488 | * |
||
1489 | * @param string $url URL to redirect to |
||
1490 | * @param int $time time to wait (to allow reading message display) |
||
1491 | * @param string $message message to display |
||
1492 | * @param bool $addredirect add xoops_redirect parameter with current URL to the redirect |
||
1493 | * URL - used for return from login redirect |
||
1494 | * @param bool $allowExternalLink allow redirect to external URL |
||
1495 | * |
||
1496 | * @return void |
||
1497 | */ |
||
1498 | public function redirect($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false) |
||
1562 | |||
1563 | /** |
||
1564 | * Do an immediate redirect to the specified url. Use this instead of using PHP's header() |
||
1565 | * directly so that a core.redirect.start event is triggered. An example is debugbar, that |
||
1566 | * stacks data so the details for both original and redirected scripts data are available. |
||
1567 | * |
||
1568 | * @param string $url URL to redirect to |
||
1569 | * |
||
1570 | * @return void |
||
1571 | */ |
||
1572 | public static function simpleRedirect($url) |
||
1579 | |||
1580 | /** |
||
1581 | * Get Environment Value |
||
1582 | * |
||
1583 | * @param string $key key (name) in the environment |
||
1584 | * |
||
1585 | * @return string |
||
1586 | */ |
||
1587 | 8 | public function getEnv($key) |
|
1591 | |||
1592 | /** |
||
1593 | * Function to get css file for a certain themeset |
||
1594 | * |
||
1595 | * @param string $theme theme name |
||
1596 | * |
||
1597 | * @return string |
||
1598 | */ |
||
1599 | 6 | public function getCss($theme = '') |
|
1630 | |||
1631 | /** |
||
1632 | * Get Mailer |
||
1633 | * |
||
1634 | * @return XoopsMailer|XoopsMailerLocale |
||
1635 | */ |
||
1636 | 1 | public function getMailer() |
|
1650 | |||
1651 | /** |
||
1652 | * Get Option |
||
1653 | * |
||
1654 | * @param string $key key (name) of option |
||
1655 | * |
||
1656 | * @return string |
||
1657 | */ |
||
1658 | 4 | public function getOption($key) |
|
1666 | |||
1667 | /** |
||
1668 | * Set Option |
||
1669 | * |
||
1670 | * @param string $key key (name) of option |
||
1671 | * @param null $value value for option |
||
1672 | * |
||
1673 | * @return void |
||
1674 | */ |
||
1675 | 1 | public function setOption($key, $value = null) |
|
1681 | |||
1682 | /** |
||
1683 | * Get Config value |
||
1684 | * |
||
1685 | * @param string $key key (name) of configuration |
||
1686 | * |
||
1687 | * @return mixed |
||
1688 | */ |
||
1689 | 60 | public function getConfig($key) |
|
1693 | |||
1694 | /** |
||
1695 | * Get all Config Values |
||
1696 | * |
||
1697 | * @return array |
||
1698 | */ |
||
1699 | 13 | public function getConfigs() |
|
1703 | |||
1704 | /** |
||
1705 | * Add Config Values |
||
1706 | * |
||
1707 | * @param array $configs array of configs |
||
1708 | * @param string $dirname module name |
||
1709 | * |
||
1710 | * @return void |
||
1711 | */ |
||
1712 | 1 | View Code Duplication | public function addConfigs($configs, $dirname = 'system') |
1722 | |||
1723 | /** |
||
1724 | * Set Config Value |
||
1725 | * |
||
1726 | * @param string $key key (name) of the configuration item |
||
1727 | * @param mixed $value configuration value |
||
1728 | * @param string $dirname dirname of module |
||
1729 | * |
||
1730 | * @return void |
||
1731 | */ |
||
1732 | 9 | View Code Duplication | public function setConfig($key, $value = null, $dirname = 'system') |
1742 | |||
1743 | /** |
||
1744 | * Unset Config Value |
||
1745 | * |
||
1746 | * @param string $key key (name) of the configuration item |
||
1747 | * @param string $dirname dirname of module |
||
1748 | * |
||
1749 | * @return void |
||
1750 | */ |
||
1751 | 3 | public function unsetConfig($key, $dirname = 'system') |
|
1762 | |||
1763 | /** |
||
1764 | * getModuleConfig |
||
1765 | * |
||
1766 | * @param string $key config name |
||
1767 | * @param string $dirname module directory |
||
1768 | * |
||
1769 | * @return mixed the value for the named config |
||
1770 | */ |
||
1771 | 63 | public function getModuleConfig($key, $dirname = '') |
|
1789 | |||
1790 | /** |
||
1791 | * Get Module Configs |
||
1792 | * |
||
1793 | * @param string $dirname dirname of module |
||
1794 | * |
||
1795 | * @return array |
||
1796 | */ |
||
1797 | 20 | public function getModuleConfigs($dirname = '') |
|
1828 | |||
1829 | /** |
||
1830 | * Append Config Value |
||
1831 | * |
||
1832 | * @param string $key key (name) of the configuration item |
||
1833 | * @param array $values array of configuration value |
||
1834 | * @param bool $appendWithKey true to add each $value element with associative value |
||
1835 | * false to add $values as a single index element |
||
1836 | * @param string $dirname dirname of module |
||
1837 | * |
||
1838 | * @return void |
||
1839 | */ |
||
1840 | 3 | public function appendConfig($key, array $values, $appendWithKey = false, $dirname = 'system') |
|
1857 | |||
1858 | /** |
||
1859 | * Disables page cache by overriding module cache settings |
||
1860 | * |
||
1861 | * @return void |
||
1862 | */ |
||
1863 | 1 | public function disableModuleCache() |
|
1869 | |||
1870 | /** |
||
1871 | * getBaseDomain |
||
1872 | * |
||
1873 | * Get domain name from a URL. This will check that the domain is valid for registering, |
||
1874 | * preventing return of constructs like 'co.uk' as the domain. See https://publicsuffix.org/ |
||
1875 | * |
||
1876 | * @param string $url URL |
||
1877 | * @param boolean $includeSubdomain true to include include subdomains, |
||
1878 | * default is false registerable domain only |
||
1879 | * @param boolean $returnObject true to return Pdp\Uri\Url\Host object |
||
1880 | * false returns domain as string |
||
1881 | * |
||
1882 | * @return Pdp\Uri\Url\Host|string|null domain, or null if domain is invalid |
||
1883 | */ |
||
1884 | 1 | public function getBaseDomain($url, $includeSubdomain = false, $returnObject = false) |
|
1922 | |||
1923 | /** |
||
1924 | * function to update compiled template file in cache folder |
||
1925 | * |
||
1926 | * @param string $tpl_id template id |
||
1927 | * |
||
1928 | * @return boolean |
||
1929 | */ |
||
1930 | 1 | public function templateTouch($tpl_id) |
|
1943 | |||
1944 | /** |
||
1945 | * Clear the module cache |
||
1946 | * |
||
1947 | * @param int $mid Module ID |
||
1948 | * |
||
1949 | * @return void |
||
1950 | */ |
||
1951 | public function templateClearModuleCache($mid) |
||
1957 | |||
1958 | /** |
||
1959 | * Support for deprecated messages events |
||
1960 | * |
||
1961 | * @param string $message message |
||
1962 | * |
||
1963 | * @return void |
||
1964 | */ |
||
1965 | 15 | public function deprecated($message) |
|
1970 | |||
1971 | /** |
||
1972 | * Support for disabling error reporting |
||
1973 | * |
||
1974 | * @return void |
||
1975 | */ |
||
1976 | 3 | public function disableErrorReporting() |
|
1981 | } |
||
1982 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: