Completed
Push — master ( 2ab45b...aa8da2 )
by Korotkov
03:07
created

ContainerGlobalsTrait::getDelete()   A

Complexity

Conditions 2
Paths 2

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 2
eloc 2
nc 2
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\Container;
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 isset($this->files[$formName]['name'][$value])
179
            ? ($this->files[$formName]['name'][$value] !== '')
180
            : false;
181
    }
182
183
    /**
184
     * @param string $key
185
     * @param string $value
186
     *
187
     * @return bool
188
     */
189
    public function isFileType(string $key, string $value) : bool
190
    {
191
        return ($this->files['type'][$key] == $value) ? true : false;
192
    }
193
194
    /**
195
     * @param string|null $key
196
     *
197
     * @return array|mixed
198
     */
199
    public function getPut(string $key = null)
200
    {
201
        return empty($key) ? $this->put : $this->put[$key];
202
    }
203
204
    /**
205
     * @param array $put
206
     */
207
    public function setPut(array $put): void
208
    {
209
        $this->put = $put;
210
    }
211
212
    /**
213
     * @param string $key
214
     *
215
     * @return bool
216
     */
217
    public function hasPut(string $key): bool
218
    {
219
        return isset($this->put[$key]);
220
    }
221
222
    /**
223
     * @param string|null $key
224
     *
225
     * @return array|mixed
226
     */
227
    public function getPatch(string $key = null)
228
    {
229
        return empty($key) ? $this->patch : $this->patch[$key];
230
    }
231
232
    /**
233
     * @param array $patch
234
     */
235
    public function setPatch(array $patch): void
236
    {
237
        $this->patch = $patch;
238
    }
239
240
    /**
241
     * @param string $key
242
     *
243
     * @return bool
244
     */
245
    public function hasPatch(string $key): bool
246
    {
247
        return isset($this->patch[$key]);
248
    }
249
250
    /**
251
     * @param string|null $key
252
     *
253
     * @return array|mixed
254
     */
255
    public function getDelete(string $key = null)
256
    {
257
        return empty($key) ? $this->delete : $this->delete[$key];
258
    }
259
260
    /**
261
     * @param array $delete
262
     */
263
    public function setDelete(array $delete): void
264
    {
265
        $this->delete = $delete;
266
    }
267
268
    /**
269
     * @param string $key
270
     *
271
     * @return bool
272
     */
273
    public function hasDelete(string $key): bool
274
    {
275
        return isset($this->delete[$key]);
276
    }
277
}
278