XoopsFormRenderer::__clone()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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) {
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $instance to at least protected.
Loading history...
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