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 <richard@geekwright.com> |
17: | * @copyright 2017-2020 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: | 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: | |
57: | /** |
58: | * Private clone method to prevent cloning of the instance of the |
59: | * *Singleton* instance. |
60: | * |
61: | * @return void |
62: | * |
63: | * @throws \LogicException |
64: | */ |
65: | public function __clone() |
66: | { |
67: | throw new \LogicException(static::NOT_PERMITTED); |
68: | } |
69: | |
70: | /** |
71: | * Private unserialize method to prevent unserializing of the *Singleton* |
72: | * instance. |
73: | * |
74: | * @return void |
75: | * |
76: | * @throws \LogicException |
77: | */ |
78: | public function __wakeup() |
79: | { |
80: | throw new \LogicException(static::NOT_PERMITTED); |
81: | } |
82: | |
83: | /** |
84: | * set the renderer |
85: | * |
86: | * @param XoopsFormRendererInterface $renderer instance of renderer |
87: | * |
88: | * @return void |
89: | */ |
90: | public function set(XoopsFormRendererInterface $renderer) |
91: | { |
92: | $this->renderer = $renderer; |
93: | } |
94: | |
95: | /** |
96: | * get the renderer |
97: | * |
98: | * @return XoopsFormRendererInterface |
99: | */ |
100: | public function get() |
101: | { |
102: | // return a default if not set |
103: | if (null === $this->renderer) { |
104: | xoops_load('xoopsformrendererlegacy'); |
105: | $this->renderer = new XoopsFormRendererLegacy(); |
106: | } |
107: | |
108: | return $this->renderer; |
109: | } |
110: | } |
111: |