Completed
Branch master (ec991a)
by Osma
05:04 queued 02:03
created

Request::getQueryParamPOST()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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