MaglLegacy::setLegacyScriptFilename()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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