1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Xhelp; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* You may not change or alter any portion of this comment or credits |
7
|
|
|
* of supporting developers from this source code or any supporting source code |
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
17
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
18
|
|
|
* @author Brian Wahoff <[email protected]> |
19
|
|
|
* @author Eric Juden <[email protected]> |
20
|
|
|
* @author XOOPS Development Team |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
if (!\defined('XHELP_CLASS_PATH')) { |
24
|
|
|
exit(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* class ReportRendererFactory |
29
|
|
|
*/ |
30
|
|
|
class ReportRendererFactory |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* ReportRendererFactory constructor. |
34
|
|
|
*/ |
35
|
|
|
public function __construct() |
36
|
|
|
{ |
37
|
|
|
// Constructor |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $type |
42
|
|
|
* @param string $report |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public static function getRenderer(string $type, string $report): bool |
46
|
|
|
{ |
47
|
|
|
$ret = false; |
48
|
|
|
if ('' === $type) { |
49
|
|
|
return $ret; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// Check rendererValid function |
53
|
|
|
$isValid = self::_rendererValid($type); |
54
|
|
|
|
55
|
|
|
if ($isValid) { |
56
|
|
|
// Step 2 - include script with faq adapter class |
57
|
|
|
// require_once \XHELP_RPT_RENDERER_PATH . '/' . $type . 'ReportRenderer.php'; |
58
|
|
|
|
59
|
|
|
// Step 3 - create instance of adapter class |
60
|
|
|
// $classname = 'xhelp' . $type . 'ReportRenderer'; |
61
|
|
|
|
62
|
|
|
$classname = __NAMESPACE__ . '\ReportRenderer\\' . \ucfirst($type . 'ReportRenderer'); |
63
|
|
|
if (!\class_exists($classname)) { |
64
|
|
|
throw new \RuntimeException("Class '$classname' not found"); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// Step 4 - return adapter class |
68
|
|
|
$ret = new $classname($report); |
69
|
|
|
|
70
|
|
|
return $ret; |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $ret; |
74
|
|
|
//XHELP_RPT_RENDERER_PATH |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $type |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
|
|
private static function _rendererValid(string $type): bool |
82
|
|
|
{ |
83
|
|
|
// Make sure this is a valid file |
84
|
|
|
if (\is_file(\XHELP_RPT_RENDERER_PATH . '/' . $type . 'ReportRenderer.php')) { |
85
|
|
|
return true; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|