Completed
Push — master ( 50e1bf...02c1f4 )
by Korotkov
01:55
created

ContainerGlobalsTrait::hasDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Date: 06.04.17
7
 * Time: 15:00
8
 *
9
 * @author    : Korotkov Danila <[email protected]>
10
 * @copyright Copyright (c) 2016, Korotkov Danila
11
 * @license   http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
12
 */
13
14
namespace Rudra;
15
16
/**
17
 * Class ContainerFilesTrait
18
 *
19
 * @package Rudra
20
 */
21
trait ContainerGlobalsTrait
22
{
23
24
    /**
25
     * @var array
26
     */
27
    protected $get;
28
29
    /**
30
     * @var array
31
     */
32
    protected $post;
33
34
    /**
35
     * @var array
36
     */
37
    protected $put;
38
39
    /**
40
     * @var array
41
     */
42
    protected $patch;
43
44
    /**
45
     * @var array
46
     */
47
    protected $delete;
48
49
    /**
50
     * @var array
51
     */
52
    protected $server;
53
54
    /**
55
     * @var array
56
     */
57
    protected $files;
58
59
    /**
60
     * Container constructor.
61
     */
62
    protected function __construct()
63
    {
64
        $this->get    = $_GET;
65
        $this->post   = $_POST;
66
        $this->server = $_SERVER;
67
        $this->files  = $_FILES;
68
    }
69
70
    /**
71
     * @param string|null $key
72
     *
73
     * @return array|mixed
74
     */
75
    public function getGet(string $key = null)
76
    {
77
        return empty($key) ? $this->get : $this->get[$key];
78
    }
79
80
    /**
81
     * @param array $get
82
     */
83
    public function setGet(array $get): void
84
    {
85
        $this->get = $get;
86
    }
87
88
89
    /**
90
     * @param string $key
91
     *
92
     * @return bool
93
     */
94
    public function hasGet(string $key): bool
95
    {
96
        return isset($this->get[$key]);
97
    }
98
99
    /**
100
     * @param string|null $key
101
     *
102
     * @return array|mixed
103
     */
104
    public function getPost(string $key = null)
105
    {
106
        return empty($key) ? $this->post : $this->post[$key];
107
    }
108
109
    /**
110
     * @param array $post
111
     */
112
    public function setPost(array $post): void
113
    {
114
        $this->post = $post;
115
    }
116
117
    /**
118
     * @param string $key
119
     *
120
     * @return bool
121
     */
122
    public function hasPost(string $key): bool
123
    {
124
        return isset($this->post[$key]);
125
    }
126
127
    /**
128
     * @param string $key
129
     *
130
     * @return array|mixed|null
131
     */
132
    public function getServer(string $key = null)
133
    {
134
        if (isset($key)) {
135
            return $this->server[$key] ?? null;
136
        }
137
138
        return $this->server;
139
    }
140
141
    /**
142
     * @param string $key
143
     * @param string $value
144
     */
145
    public function setServer(string $key, string $value)
146
    {
147
        $this->server[$key] = $value;
148
    }
149
150
    /**
151
     * @param array $files
152
     */
153
    public function setFiles(array $files)
154
    {
155
        $this->files = $files;
156
    }
157
158
    /**
159
     * @param string $key
160
     * @param string $fieldName
161
     * @param string $formName
162
     *
163
     * @return string
164
     */
165
    public function getUpload(string $key, string $fieldName, string $formName = 'upload') : string
166
    {
167
        return $this->files[$formName][$fieldName][$key];
168
    }
169
170
    /**
171
     * @param string $value
172
     * @param string $formName
173
     *
174
     * @return bool
175
     */
176
    public function isUploaded(string $value, string $formName = 'upload') : bool
177
    {
178
        return ($this->files[$formName]['name'][$value] !== '');
179
    }
180
181
    /**
182
     * @param string $key
183
     * @param string $value
184
     *
185
     * @return bool
186
     */
187
    public function isFileType(string $key, string $value) : bool
188
    {
189
        return ($this->files['type'][$key] == $value) ? true : false;
190
    }
191
192
    /**
193
     * @param string|null $key
194
     *
195
     * @return array|mixed
196
     */
197
    public function getPut(string $key = null)
198
    {
199
        return empty($key) ? $this->put : $this->put[$key];
200
    }
201
202
    /**
203
     * @param array $put
204
     */
205
    public function setPut(array $put): void
206
    {
207
        $this->put = $put;
208
    }
209
210
    /**
211
     * @param string $key
212
     *
213
     * @return bool
214
     */
215
    public function hasPut(string $key): bool
216
    {
217
        return isset($this->put[$key]);
218
    }
219
220
    /**
221
     * @param string|null $key
222
     *
223
     * @return array|mixed
224
     */
225
    public function getPatch(string $key = null)
226
    {
227
        return empty($key) ? $this->patch : $this->patch[$key];
228
    }
229
230
    /**
231
     * @param array $patch
232
     */
233
    public function setPatch(array $patch): void
234
    {
235
        $this->patch = $patch;
236
    }
237
238
    /**
239
     * @param string $key
240
     *
241
     * @return bool
242
     */
243
    public function hasPatch(string $key): bool
244
    {
245
        return isset($this->patch[$key]);
246
    }
247
248
    /**
249
     * @param string|null $key
250
     *
251
     * @return array|mixed
252
     */
253
    public function getDelete(string $key = null)
254
    {
255
        return empty($key) ? $this->delete : $this->delete[$key];
256
    }
257
258
    /**
259
     * @param array $delete
260
     */
261
    public function setDelete(array $delete): void
262
    {
263
        $this->delete = $delete;
264
    }
265
266
    /**
267
     * @param string $key
268
     *
269
     * @return bool
270
     */
271
    public function hasDelete(string $key): bool
272
    {
273
        return isset($this->delete[$key]);
274
    }
275
}
276