Completed
Branch master (b716fd)
by Matthias
01:23
created

MaglLegacy::setVarOnce()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
/**
4
 * @author Matthias Glaub <[email protected]>
5
 * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
6
 */
7
8
namespace MaglLegacyApplication\Application;
9
10
class MaglLegacy
11
{
12
13
    const EVENT_SHORT_CIRCUIT_RESPONSE = 'magl-short-circuit-response';
14
15
    /**
16
     *
17
     * @var MaglLegacy
18
     */
19
    private static $instance = null;
20
21
    /**
22
     *
23
     * @var \Zend\Mvc\ApplicationInterface
24
     */
25
    private $application;
26
27
    /**
28
     *
29
     * @var string full path of the requested file (may be used within your legacy application)
30
     */
31
    private $legacyScriptFilename = null;
32
33
    /**
34
     *
35
     * @var string url path of the requested file (may be used within your legacy application)
36
     */
37
    private $legacyScriptName = null;
38
39
    /**
40
     *
41
     * @return MaglLegacy
42
     */
43 10
    public static function getInstance()
44
    {
45 10
        if (null === self::$instance) {
46
            self::$instance = new static();
47
        }
48
49 10
        return self::$instance;
50
    }
51
52
    /**
53
     * @codeCoverageIgnore
54
     */
55
    private function __construct()
56
    {
57
        return null;
58
    }
59
60
    /**
61
     * @codeCoverageIgnore
62
     */
63
    private function __clone()
64
    {
65
        return null;
66
    }
67
68 6
    public function setApplication(\Zend\Mvc\ApplicationInterface $application)
69
    {
70 6
        $this->application = $application;
71 6
    }
72
73
    /**
74
     *
75
     * @return \Zend\Mvc\ApplicationInterface
76
     */
77 1
    public function getApplication()
78
    {
79 1
        return $this->application;
80
    }
81
82
    /**
83
     *
84
     * @return \Zend\ServiceManager\ServiceLocatorInterface
85
     */
86
    public static function getServiceManager()
87
    {
88
        return static::getInstance()->getApplication()->getServiceManager();
89
    }
90
91
    /**
92
     *
93
     * @return \Zend\EventManager\EventManagerInterface
94
     */
95
    public static function getEventManager()
96
    {
97
        return static::getInstance()->getApplication()->getEventManager();
98
    }
99
100
    /**
101
     *
102
     * @return string the full path of the requested legacy filename
103
     */
104 1
    public function getLegacyScriptFilename()
105
    {
106 1
        return $this->legacyScriptFilename;
107
    }
108
109
    /**
110
     *
111
     * @param  string $legacyScriptFilename
112
     * @return boolean true, if the script filenamename was set, false otherwise, e.g. it has already been set
113
     */
114 5
    public function setLegacyScriptFilename($legacyScriptFilename)
115
    {
116 5
        return $this->setVarOnce('legacyScriptFilename', $legacyScriptFilename);
117
    }
118
119
    /**
120
     *
121
     * @return string the URI path of the requested legacy filename
122
     */
123 1
    public function getLegacyScriptName()
124
    {
125 1
        return $this->legacyScriptName;
126
    }
127
128
    /**
129
     *
130
     * @param  string $legacyScriptName
131
     * @return boolean true, if the script name was set, false otherwise, e.g. it has already been set
132
     */
133 5
    public function setLegacyScriptName($legacyScriptName)
134
    {
135 5
        return $this->setVarOnce('legacyScriptName', $legacyScriptName);
136
    }
137
138
    /**
139
     * @param string $varName the variable to be set
140
     * @param string $varValue the value
141
     */
142 6
    private function setVarOnce($varName, $varValue)
143
    {
144 6
        if (!isset($this->$varName)) {
145 2
            $this->$varName = $varValue;
146
147 2
            return true;
148
        }
149
150 6
        return false;
151
    }
152
}
153