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 XOOPS Project (http://xoops.org)
18: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
19: * @link http://xoops.org
20: */
21: class XoopsFormRenderer
22: {
23: /**
24: * @var XoopsFormRenderer The reference to *Singleton* instance of this class
25: */
26: private static $instance;
27:
28: /**
29: * @var XoopsFormRendererInterface The reference to *Singleton* instance of this class
30: */
31: protected $renderer;
32:
33: /**
34: * Returns the *Singleton* instance of this class.
35: *
36: * @return XoopsFormRenderer the singleton instance.
37: */
38: public static function getInstance()
39: {
40: if (null === static::$instance) {
41: static::$instance = new static();
42: }
43:
44: return static::$instance;
45: }
46:
47: /**
48: * Protected constructor to prevent creating a new instance of the
49: * *Singleton* via the `new` operator from outside of this class.
50: */
51: protected function __construct()
52: {
53: }
54:
55: /**
56: * Private clone method to prevent cloning of the instance of the
57: * *Singleton* instance.
58: *
59: * @return void
60: */
61: private function __clone()
62: {
63: }
64:
65: /**
66: * Private unserialize method to prevent unserializing of the *Singleton*
67: * instance.
68: *
69: * @return void
70: */
71: private function __wakeup()
72: {
73: }
74:
75: /**
76: * set the renderer
77: *
78: * @param XoopsFormRendererInterface $renderer instance of renderer
79: *
80: * @return void
81: */
82: public function set(XoopsFormRendererInterface $renderer)
83: {
84: $this->renderer = $renderer;
85: }
86:
87: /**
88: * get the renderer
89: *
90: * @return XoopsFormRendererInterface
91: */
92: public function get()
93: {
94: // return a default if not set
95: if (null === $this->renderer) {
96: xoops_load('xoopsformrendererlegacy');
97: $this->renderer = new XoopsFormRendererLegacy();
98: }
99:
100: return $this->renderer;
101: }
102: }
103: