Completed
Push — master ( 778e1c...a27d0d )
by Henri
02:59
created

Request::getVocabid()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 0
1
<?php
2
3
/**
4
 * Provides access to the http request information
5
 */
6
class Request
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
9
    private $lang;
10
    private $clang;
11
    private $page;
12
    private $vocab;
13
    private $vocabids;
14
    private $uri;
15
    private $letter;
16
    private $model;
17
18
    /**
19
     * Initializes the Request Object
20
     */
21
    public function __construct($model)
22
    {
23
        $this->model = $model;
24
    }
25
26
    public function getQueryParam($paramName)
27
    {
28
        return filter_input(INPUT_GET, $paramName, FILTER_SANITIZE_STRING);
29
    }
30
31
    public function getQueryParamPOST($paramName)
32
    {
33
        return filter_input(INPUT_POST, $paramName, FILTER_SANITIZE_STRING);
34
    }
35
36
    public function getQueryParamBoolean($paramName, $default)
37
    {
38
        $val = $this->getQueryParam($paramName);
39
        if ($val !== NULL) {
40
            $val = filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
41
        }
42
        return ($val !== null) ? $val : $default;
43
    }
44
45
    public function getServerConstant($paramName)
46
    {
47
        return filter_input(INPUT_SERVER, $paramName, FILTER_SANITIZE_STRING);
48
    }
49
50
    public function getLang()
51
    {
52
        return $this->lang;
53
    }
54
55
    /**
56
     * Sets the language variable
57
     * @param string $lang
58
     */
59
    public function setLang($lang)
60
    {
61
        if ($lang !== '') {
62
            $this->lang = $lang;
63
        }
64
65
    }
66
67
    public function getContentLang()
68
    {
69
        return $this->clang;
70
    }
71
72
    /**
73
     * Sets the language variable
74
     * @param string $clang
75
     */
76
    public function setContentLang($clang)
77
    {
78
        $this->clang = $this->verifyContentLang($clang);
79
    }
80
81
    private function verifyContentLang($lang)
82
    {
83
        if ($this->vocab) {
84
            return $this->vocab->verifyVocabularyLanguage($lang);
85
        }
86
87
        return $lang;
88
    }
89
90
    public function getPage()
91
    {
92
        return $this->page;
93
    }
94
95
    /**
96
     * Sets the page id variable eg. 'groups'
97
     * @param string $page
98
     */
99
    public function setPage($page)
100
    {
101
        if ($page !== '') {
102
            $this->page = $page;
103
        }
104
105
    }
106
107
    public function getRequestUri()
108
    {
109
        return $this->getServerConstant('HTTP_HOST') . $this->getServerConstant('REQUEST_URI');
110
    }
111
    
112
    /**
113
     * Returns the relative page url eg. '/yso/fi/search?clang=en&q=cat'
114
     * @return string the relative url of the page
115
     */
116
    public function getLangUrl()
117
    {
118
        return substr(str_replace(str_replace('/index.php', '', $this->getServerConstant('SCRIPT_NAME')), '', $this->getServerConstant('REQUEST_URI')), 1);
119
    }
120
121
    public function getLetter()
122
    {
123
        return (isset($this->letter)) ? $this->letter : 'A';
124
    }
125
126
    /**
127
     * Sets the page id variable eg. 'B'
128
     * @param string $letter
129
     */
130
    public function setLetter($letter)
131
    {
132
        if ($letter !== '') {
133
            $this->letter = $letter;
134
        }
135
136
    }
137
138
    public function getURI()
139
    {
140
        return $this->uri;
141
    }
142
143
    /**
144
     * Sets the uri variable
145
     * @param string $uri
146
     */
147
    public function setURI($uri)
148
    {
149
        if ($uri !== '') {
150
            $this->uri = rtrim($uri);
151
        }
152
153
    }
154
155
    /**
156
     * Used to set the vocab id variable when multiple vocabularies have been chosen eg. 'lcsh+yso'
157
     * @param string $ids
158
     */
159
    public function setVocabids($ids)
160
    {
161
        $this->vocabids = $ids;
162
    }
163
164
    public function getVocabid()
165
    {
166
        if ($this->vocabids) {
167
            return $this->vocabids;
168
        }
169
170
        return isset($this->vocab) ? $this->vocab->getId() : '';
171
    }
172
173
    /**
174
     * Creates a Vocabulary object
175
     * @param string $vocabid
176
     */
177
    public function setVocab($vocabid)
178
    {
179
        if (strpos($vocabid, ' ') !== false) // if there are multiple vocabularies just storing the string
180
        {
181
            $this->setVocabids($vocabid);
182
        } else {
183
            $this->vocab = $this->model->getVocabulary($vocabid);
184
        }
185
186
    }
187
188
    public function getVocab()
189
    {
190
        return $this->vocab;
191
    }
192
193
    public function getVocabList() {
194
        return $this->model->getVocabularyList();
195
    }
196
197
    public function getPlugins() {
198
        if ($this->vocab) {
199
            return $this->vocab->getConfig()->getPlugins();
200
        }
201
        return new PluginRegister($this->model->getConfig()->getGlobalPlugins());
202
    }
203
}
204