1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* You may not change or alter any portion of this comment or credits |
4
|
|
|
* of supporting developers from this source code or any supporting source code |
5
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
* This program is distributed in the hope that it will be useful, |
7
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
8
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Factory to build handlers |
13
|
|
|
* |
14
|
|
|
* @category XoopsForm |
15
|
|
|
* @package XoopsFormRenderer |
16
|
|
|
* @author Richard Griffith <[email protected]> |
17
|
|
|
* @copyright 2000-2025 XOOPS Project (https://xoops.org) |
18
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
19
|
|
|
* @link https://xoops.org |
20
|
|
|
*/ |
21
|
|
|
final class XoopsFormRenderer |
22
|
|
|
{ |
23
|
|
|
public const NOT_PERMITTED = 'Not supported for Singleton'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var XoopsFormRenderer The reference to *Singleton* instance of this class |
27
|
|
|
*/ |
28
|
|
|
private static $instance; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var XoopsFormRendererInterface The reference to *Singleton* instance of this class |
32
|
|
|
*/ |
33
|
|
|
protected $renderer; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Returns the *Singleton* instance of this class. |
37
|
|
|
* |
38
|
|
|
* @return XoopsFormRenderer the singleton instance. |
39
|
|
|
*/ |
40
|
|
|
public static function getInstance() |
41
|
|
|
{ |
42
|
|
|
if (null === static::$instance) { |
|
|
|
|
43
|
|
|
static::$instance = new static(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return static::$instance; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Protected constructor to prevent creating a new instance of the |
51
|
|
|
* *Singleton* via the `new` operator from outside of this class. |
52
|
|
|
*/ |
53
|
|
|
protected function __construct() {} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Private clone method to prevent cloning of the instance of the |
57
|
|
|
* *Singleton* instance. |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
* |
61
|
|
|
* @throws \LogicException |
62
|
|
|
*/ |
63
|
|
|
public function __clone() |
64
|
|
|
{ |
65
|
|
|
throw new \LogicException(static::NOT_PERMITTED); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Private unserialize method to prevent unserializing of the *Singleton* |
70
|
|
|
* instance. |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
* |
74
|
|
|
* @throws \LogicException |
75
|
|
|
*/ |
76
|
|
|
public function __wakeup() |
77
|
|
|
{ |
78
|
|
|
throw new \LogicException(static::NOT_PERMITTED); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* set the renderer |
83
|
|
|
* |
84
|
|
|
* @param XoopsFormRendererInterface $renderer instance of renderer |
85
|
|
|
* |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
|
|
public function set(XoopsFormRendererInterface $renderer) |
89
|
|
|
{ |
90
|
|
|
$this->renderer = $renderer; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* get the renderer |
95
|
|
|
* |
96
|
|
|
* @return XoopsFormRendererInterface |
97
|
|
|
*/ |
98
|
|
|
public function get() |
99
|
|
|
{ |
100
|
|
|
// return a default if not set |
101
|
|
|
if (null === $this->renderer) { |
102
|
|
|
xoops_load('xoopsformrendererlegacy'); |
103
|
|
|
$this->renderer = new XoopsFormRendererLegacy(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this->renderer; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|