Passed
Pull Request — master (#10)
by Korotkov
01:41
created

ContainerGlobalsTrait::hasPatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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